wok view slitaz-tic-tac-toe/stuff/share/games/slitaz-tic-tac-toe/data.js @ rev 25037

Up glza (0.11.4)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat May 21 21:38:29 2022 +0000 (2022-05-21)
parents
children
line source
1 var x = "black-stone.png";
3 var o = "white-stone.png";
5 var blank = "blank.png";
7 var pause = 0;
8 var all = 0;
9 var a = 0;
10 var b = 0;
11 var c = 0;
12 var d = 0;
13 var e = 0;
14 var f = 0;
15 var g = 0;
16 var h = 0;
17 var i = 0;
18 var temp="";
19 var ok = 0;
20 var cf = 0;
21 var choice=9;
22 var aRandomNumber = 0;
23 var comp = 0;
24 var t = 0;
25 var wn = 0;
26 var ls = 0;
27 var ts = 0;
28 function help() {
29 alert("Game Help \n\n ------------------ \n\n You play with black stone and Slitaz with white stone. \n\n Choose an empty space and click. \n\n The first complete three lines is the winner. \n\n ------------------ \n\n To start a new round, click 'New Round' button. \n\n To start a new game, click 'Restart Game' button. \n\n")
30 }
31 function logicOne() {
32 if ((a==1)&&(b==1)&&(c==1)) all=1;
33 if ((a==1)&&(d==1)&&(g==1)) all=1;
34 if ((a==1)&&(e==1)&&(i==1)) all=1;
35 if ((b==1)&&(e==1)&&(h==1)) all=1;
36 if ((d==1)&&(e==1)&&(f==1)) all=1;
37 if ((g==1)&&(h==1)&&(i==1)) all=1;
38 if ((c==1)&&(f==1)&&(i==1)) all=1;
39 if ((g==1)&&(e==1)&&(c==1)) all=1;
40 if ((a==2)&&(b==2)&&(c==2)) all=2;
41 if ((a==2)&&(d==2)&&(g==2)) all=2;
42 if ((a==2)&&(e==2)&&(i==2)) all=2;
43 if ((b==2)&&(e==2)&&(h==2)) all=2;
44 if ((d==2)&&(e==2)&&(f==2)) all=2;
45 if ((g==2)&&(h==2)&&(i==2)) all=2;
46 if ((c==2)&&(f==2)&&(i==2)) all=2;
47 if ((g==2)&&(e==2)&&(c==2)) all=2;
48 if ((a != 0)&&(b != 0)&&(c != 0)&&(d != 0)&&(e != 0)&&(f != 0)&&(g != 0)&&(h != 0)&&(i != 0)&&(all == 0)) all = 3;
49 }
50 function logicTwo() {
51 if ((a==2)&&(b==2)&&(c== 0)&&(temp=="")) temp="C";
52 if ((a==2)&&(b== 0)&&(c==2)&&(temp=="")) temp="B";
53 if ((a== 0)&&(b==2)&&(c==2)&&(temp=="")) temp="A";
54 if ((a==2)&&(d==2)&&(g== 0)&&(temp=="")) temp="G";
55 if ((a==2)&&(d== 0)&&(g==2)&&(temp=="")) temp="D";
56 if ((a== 0)&&(d==2)&&(g==2)&&(temp=="")) temp="A";
57 if ((a==2)&&(e==2)&&(i== 0)&&(temp=="")) temp="I";
58 if ((a==2)&&(e== 0)&&(i==2)&&(temp=="")) temp="E";
59 if ((a== 0)&&(e==2)&&(i==2)&&(temp=="")) temp="A";
60 if ((b==2)&&(e==2)&&(h== 0)&&(temp=="")) temp="H";
61 if ((b==2)&&(e== 0)&&(h==2)&&(temp=="")) temp="E";
62 if ((b== 0)&&(e==2)&&(h==2)&&(temp=="")) temp="B";
63 if ((d==2)&&(e==2)&&(f== 0)&&(temp=="")) temp="F";
64 if ((d==2)&&(e== 0)&&(f==2)&&(temp=="")) temp="E";
65 if ((d== 0)&&(e==2)&&(f==2)&&(temp=="")) temp="D";
66 if ((g==2)&&(h==2)&&(i== 0)&&(temp=="")) temp="I";
67 if ((g==2)&&(h== 0)&&(i==2)&&(temp=="")) temp="H";
68 if ((g== 0)&&(h==2)&&(i==2)&&(temp=="")) temp="G";
69 if ((c==2)&&(f==2)&&(i== 0)&&(temp=="")) temp="I";
70 if ((c==2)&&(f== 0)&&(i==2)&&(temp=="")) temp="F";
71 if ((c== 0)&&(f==2)&&(i==2)&&(temp=="")) temp="C";
72 if ((g==2)&&(e==2)&&(c== 0)&&(temp=="")) temp="C";
73 if ((g==2)&&(e== 0)&&(c==2)&&(temp=="")) temp="E";
74 if ((g== 0)&&(e==2)&&(c==2)&&(temp=="")) temp="G";
75 }
76 function logicThree() {
77 if ((a==1)&&(b==1)&&(c==0)&&(temp=="")) temp="C";
78 if ((a==1)&&(b==0)&&(c==1)&&(temp=="")) temp="B";
79 if ((a==0)&&(b==1)&&(c==1)&&(temp=="")) temp="A";
80 if ((a==1)&&(d==1)&&(g==0)&&(temp=="")) temp="G";
81 if ((a==1)&&(d==0)&&(g==1)&&(temp=="")) temp="D";
82 if ((a==0)&&(d==1)&&(g==1)&&(temp=="")) temp="A";
83 if ((a==1)&&(e==1)&&(i==0)&&(temp=="")) temp="I";
84 if ((a==1)&&(e==0)&&(i==1)&&(temp=="")) temp="E";
85 if ((a==0)&&(e==1)&&(i==1)&&(temp=="")) temp="A";
86 if ((b==1)&&(e==1)&&(h==0)&&(temp=="")) temp="H";
87 if ((b==1)&&(e==0)&&(h==1)&&(temp=="")) temp="E";
88 if ((b==0)&&(e==1)&&(h==1)&&(temp=="")) temp="B";
89 if ((d==1)&&(e==1)&&(f==0)&&(temp=="")) temp="F";
90 if ((d==1)&&(e==0)&&(f==1)&&(temp=="")) temp="E";
91 if ((d==0)&&(e==1)&&(f==1)&&(temp=="")) temp="D";
92 if ((g==1)&&(h==1)&&(i==0)&&(temp=="")) temp="I";
93 if ((g==1)&&(h==0)&&(i==1)&&(temp=="")) temp="H";
94 if ((g==0)&&(h==1)&&(i==1)&&(temp=="")) temp="G";
95 if ((c==1)&&(f==1)&&(i==0)&&(temp=="")) temp="I";
96 if ((c==1)&&(f==0)&&(i==1)&&(temp=="")) temp="F";
97 if ((c==0)&&(f==1)&&(i==1)&&(temp=="")) temp="C";
98 if ((g==1)&&(e==1)&&(c==0)&&(temp=="")) temp="C";
99 if ((g==1)&&(e==0)&&(c==1)&&(temp=="")) temp="E";
100 if ((g==0)&&(e==1)&&(c==1)&&(temp=="")) temp="G";
101 }
102 function clearOut() {
103 document.game.you.value="0";
104 document.game.slitaz.value="0";
105 document.game.ties.value="0";
106 }
107 function checkSpace() {
108 if ((temp=="A")&&(a==0)) {
109 ok=1;
110 if (cf==0) a=1;
111 if (cf==1) a=2;
112 }
113 if ((temp=="B")&&(b==0)) {
114 ok=1;
115 if (cf==0) b=1;
116 if (cf==1) b=2;
117 }
118 if ((temp=="C")&&(c==0)) {
119 ok=1;
120 if (cf==0) c=1;
121 if (cf==1) c=2;
122 }
123 if ((temp=="D")&&(d==0)) {
124 ok=1;
125 if (cf==0) d=1;
126 if (cf==1) d=2;
127 }
128 if ((temp=="E")&&(e==0)) {
129 ok=1;
130 if (cf==0) e=1;
131 if (cf==1) e=2;
132 }
133 if ((temp=="F")&&(f==0)) {
134 ok=1
135 if (cf==0) f=1;
136 if (cf==1) f=2;
137 }
138 if ((temp=="G")&&(g==0)) {
139 ok=1
140 if (cf==0) g=1;
141 if (cf==1) g=2;
142 }
143 if ((temp=="H")&&(h==0)) {
144 ok=1;
145 if (cf==0) h=1;
146 if (cf==1) h=2;
147 }
148 if ((temp=="I")&&(i==0)) {
149 ok=1;
150 if (cf==0) i=1;
151 if (cf==1) i=2;
152 }
153 }
154 function yourChoice(chName) {
155 pause = 0;
156 if (all!=0) ended();
157 if (all==0) {
158 cf = 0;
159 ok = 0;
160 temp=chName;
161 checkSpace();
162 if (ok==1) {
163 document.images[chName].src = x;
164 }
165 if (ok==0)taken();
166 process();
167 if ((all==0)&&(pause==0)) myChoice();
168 }
169 }
170 function taken() {
171 alert("Please, select an empty. \n\n")
172 pause=1;
173 }
174 function myChoice() {
175 temp="";
176 ok = 0;
177 cf=1;
178 logicTwo();
179 logicThree();
180 checkSpace();
181 while(ok==0) {
182 aRandomNumber=Math.random()
183 comp=Math.round((choice-1)*aRandomNumber)+1;
184 if (comp==1) temp="A";
185 if (comp==2) temp="B";
186 if (comp==3) temp="C";
187 if (comp==4) temp="D";
188 if (comp==5) temp="E";
189 if (comp==6) temp="F";
190 if (comp==7) temp="G";
191 if (comp==8) temp="H";
192 if (comp==9) temp="I";
193 checkSpace();
194 }
195 document.images[temp].src= o;
196 process();
197 }
198 function restart() {
199 if (confirm('Delete all score and restart game?')) {
200 window.location="slitaz-tic-tac-toe.html"
201 }
202 }
203 function ended() {
204 alert("Ops! This round is over. \n\n To play again click 'New Round' button. \n\n To restart all game click 'Restart' button.")
205 }
206 function process() {
207 logicOne();
208 if (all==1){ alert("Woohoooo! \n\n You are amazing " + player + "! \n\n I'm not buying it. \n\n New round? \n\n"); wn++;}
209 if (all==2){ alert("Awww, that's too bad! \n\n Try to win me! \n\n"); ls++;}
210 if (all==3){ alert("Tie! Let's play again?"); ts++;}
211 if (all!=0) {
212 document.game.you.value = wn;
213 document.game.slitaz.value = ls;
214 document.game.ties.value = ts;
215 }
216 }
217 function playAgain() {
218 if (all==0) {
219 if(confirm("Start new round?")) reset();
220 }
221 if (all>0) reset();
222 }
223 function reset() {
224 all = 0;
225 a = 0;
226 b = 0;
227 c = 0;
228 d = 0;
229 e = 0;
230 f = 0;
231 g = 0;
232 h = 0;
233 i = 0;
234 temp="";
235 ok = 0;
236 cf = 0;
237 choice=9;
238 aRandomNumber = 0;
239 comp = 0;
240 document.images.A.src= blank;
241 document.images.B.src= blank;
242 document.images.C.src= blank;
243 document.images.D.src= blank;
244 document.images.E.src= blank;
245 document.images.F.src= blank;
246 document.images.G.src= blank;
247 document.images.H.src= blank;
248 document.images.I.src= blank;
249 if (t==0) { t=2; myChoice(); }
250 t--;
251 }