wok diff 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 diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/slitaz-tic-tac-toe/stuff/share/games/slitaz-tic-tac-toe/data.js Sat May 21 21:38:29 2022 +0000 1.3 @@ -0,0 +1,251 @@ 1.4 +var x = "black-stone.png"; 1.5 + 1.6 +var o = "white-stone.png"; 1.7 + 1.8 +var blank = "blank.png"; 1.9 + 1.10 +var pause = 0; 1.11 +var all = 0; 1.12 +var a = 0; 1.13 +var b = 0; 1.14 +var c = 0; 1.15 +var d = 0; 1.16 +var e = 0; 1.17 +var f = 0; 1.18 +var g = 0; 1.19 +var h = 0; 1.20 +var i = 0; 1.21 +var temp=""; 1.22 +var ok = 0; 1.23 +var cf = 0; 1.24 +var choice=9; 1.25 +var aRandomNumber = 0; 1.26 +var comp = 0; 1.27 +var t = 0; 1.28 +var wn = 0; 1.29 +var ls = 0; 1.30 +var ts = 0; 1.31 +function help() { 1.32 +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") 1.33 +} 1.34 +function logicOne() { 1.35 +if ((a==1)&&(b==1)&&(c==1)) all=1; 1.36 +if ((a==1)&&(d==1)&&(g==1)) all=1; 1.37 +if ((a==1)&&(e==1)&&(i==1)) all=1; 1.38 +if ((b==1)&&(e==1)&&(h==1)) all=1; 1.39 +if ((d==1)&&(e==1)&&(f==1)) all=1; 1.40 +if ((g==1)&&(h==1)&&(i==1)) all=1; 1.41 +if ((c==1)&&(f==1)&&(i==1)) all=1; 1.42 +if ((g==1)&&(e==1)&&(c==1)) all=1; 1.43 +if ((a==2)&&(b==2)&&(c==2)) all=2; 1.44 +if ((a==2)&&(d==2)&&(g==2)) all=2; 1.45 +if ((a==2)&&(e==2)&&(i==2)) all=2; 1.46 +if ((b==2)&&(e==2)&&(h==2)) all=2; 1.47 +if ((d==2)&&(e==2)&&(f==2)) all=2; 1.48 +if ((g==2)&&(h==2)&&(i==2)) all=2; 1.49 +if ((c==2)&&(f==2)&&(i==2)) all=2; 1.50 +if ((g==2)&&(e==2)&&(c==2)) all=2; 1.51 +if ((a != 0)&&(b != 0)&&(c != 0)&&(d != 0)&&(e != 0)&&(f != 0)&&(g != 0)&&(h != 0)&&(i != 0)&&(all == 0)) all = 3; 1.52 +} 1.53 +function logicTwo() { 1.54 +if ((a==2)&&(b==2)&&(c== 0)&&(temp=="")) temp="C"; 1.55 +if ((a==2)&&(b== 0)&&(c==2)&&(temp=="")) temp="B"; 1.56 +if ((a== 0)&&(b==2)&&(c==2)&&(temp=="")) temp="A"; 1.57 +if ((a==2)&&(d==2)&&(g== 0)&&(temp=="")) temp="G"; 1.58 +if ((a==2)&&(d== 0)&&(g==2)&&(temp=="")) temp="D"; 1.59 +if ((a== 0)&&(d==2)&&(g==2)&&(temp=="")) temp="A"; 1.60 +if ((a==2)&&(e==2)&&(i== 0)&&(temp=="")) temp="I"; 1.61 +if ((a==2)&&(e== 0)&&(i==2)&&(temp=="")) temp="E"; 1.62 +if ((a== 0)&&(e==2)&&(i==2)&&(temp=="")) temp="A"; 1.63 +if ((b==2)&&(e==2)&&(h== 0)&&(temp=="")) temp="H"; 1.64 +if ((b==2)&&(e== 0)&&(h==2)&&(temp=="")) temp="E"; 1.65 +if ((b== 0)&&(e==2)&&(h==2)&&(temp=="")) temp="B"; 1.66 +if ((d==2)&&(e==2)&&(f== 0)&&(temp=="")) temp="F"; 1.67 +if ((d==2)&&(e== 0)&&(f==2)&&(temp=="")) temp="E"; 1.68 +if ((d== 0)&&(e==2)&&(f==2)&&(temp=="")) temp="D"; 1.69 +if ((g==2)&&(h==2)&&(i== 0)&&(temp=="")) temp="I"; 1.70 +if ((g==2)&&(h== 0)&&(i==2)&&(temp=="")) temp="H"; 1.71 +if ((g== 0)&&(h==2)&&(i==2)&&(temp=="")) temp="G"; 1.72 +if ((c==2)&&(f==2)&&(i== 0)&&(temp=="")) temp="I"; 1.73 +if ((c==2)&&(f== 0)&&(i==2)&&(temp=="")) temp="F"; 1.74 +if ((c== 0)&&(f==2)&&(i==2)&&(temp=="")) temp="C"; 1.75 +if ((g==2)&&(e==2)&&(c== 0)&&(temp=="")) temp="C"; 1.76 +if ((g==2)&&(e== 0)&&(c==2)&&(temp=="")) temp="E"; 1.77 +if ((g== 0)&&(e==2)&&(c==2)&&(temp=="")) temp="G"; 1.78 +} 1.79 +function logicThree() { 1.80 +if ((a==1)&&(b==1)&&(c==0)&&(temp=="")) temp="C"; 1.81 +if ((a==1)&&(b==0)&&(c==1)&&(temp=="")) temp="B"; 1.82 +if ((a==0)&&(b==1)&&(c==1)&&(temp=="")) temp="A"; 1.83 +if ((a==1)&&(d==1)&&(g==0)&&(temp=="")) temp="G"; 1.84 +if ((a==1)&&(d==0)&&(g==1)&&(temp=="")) temp="D"; 1.85 +if ((a==0)&&(d==1)&&(g==1)&&(temp=="")) temp="A"; 1.86 +if ((a==1)&&(e==1)&&(i==0)&&(temp=="")) temp="I"; 1.87 +if ((a==1)&&(e==0)&&(i==1)&&(temp=="")) temp="E"; 1.88 +if ((a==0)&&(e==1)&&(i==1)&&(temp=="")) temp="A"; 1.89 +if ((b==1)&&(e==1)&&(h==0)&&(temp=="")) temp="H"; 1.90 +if ((b==1)&&(e==0)&&(h==1)&&(temp=="")) temp="E"; 1.91 +if ((b==0)&&(e==1)&&(h==1)&&(temp=="")) temp="B"; 1.92 +if ((d==1)&&(e==1)&&(f==0)&&(temp=="")) temp="F"; 1.93 +if ((d==1)&&(e==0)&&(f==1)&&(temp=="")) temp="E"; 1.94 +if ((d==0)&&(e==1)&&(f==1)&&(temp=="")) temp="D"; 1.95 +if ((g==1)&&(h==1)&&(i==0)&&(temp=="")) temp="I"; 1.96 +if ((g==1)&&(h==0)&&(i==1)&&(temp=="")) temp="H"; 1.97 +if ((g==0)&&(h==1)&&(i==1)&&(temp=="")) temp="G"; 1.98 +if ((c==1)&&(f==1)&&(i==0)&&(temp=="")) temp="I"; 1.99 +if ((c==1)&&(f==0)&&(i==1)&&(temp=="")) temp="F"; 1.100 +if ((c==0)&&(f==1)&&(i==1)&&(temp=="")) temp="C"; 1.101 +if ((g==1)&&(e==1)&&(c==0)&&(temp=="")) temp="C"; 1.102 +if ((g==1)&&(e==0)&&(c==1)&&(temp=="")) temp="E"; 1.103 +if ((g==0)&&(e==1)&&(c==1)&&(temp=="")) temp="G"; 1.104 +} 1.105 +function clearOut() { 1.106 +document.game.you.value="0"; 1.107 +document.game.slitaz.value="0"; 1.108 +document.game.ties.value="0"; 1.109 +} 1.110 +function checkSpace() { 1.111 +if ((temp=="A")&&(a==0)) { 1.112 +ok=1; 1.113 +if (cf==0) a=1; 1.114 +if (cf==1) a=2; 1.115 +} 1.116 +if ((temp=="B")&&(b==0)) { 1.117 +ok=1; 1.118 +if (cf==0) b=1; 1.119 +if (cf==1) b=2; 1.120 +} 1.121 +if ((temp=="C")&&(c==0)) { 1.122 +ok=1; 1.123 +if (cf==0) c=1; 1.124 +if (cf==1) c=2; 1.125 +} 1.126 +if ((temp=="D")&&(d==0)) { 1.127 +ok=1; 1.128 +if (cf==0) d=1; 1.129 +if (cf==1) d=2; 1.130 +} 1.131 +if ((temp=="E")&&(e==0)) { 1.132 +ok=1; 1.133 +if (cf==0) e=1; 1.134 +if (cf==1) e=2; 1.135 +} 1.136 +if ((temp=="F")&&(f==0)) { 1.137 +ok=1 1.138 +if (cf==0) f=1; 1.139 +if (cf==1) f=2; 1.140 +} 1.141 +if ((temp=="G")&&(g==0)) { 1.142 +ok=1 1.143 +if (cf==0) g=1; 1.144 +if (cf==1) g=2; 1.145 +} 1.146 +if ((temp=="H")&&(h==0)) { 1.147 +ok=1; 1.148 +if (cf==0) h=1; 1.149 +if (cf==1) h=2; 1.150 +} 1.151 +if ((temp=="I")&&(i==0)) { 1.152 +ok=1; 1.153 +if (cf==0) i=1; 1.154 +if (cf==1) i=2; 1.155 +} 1.156 +} 1.157 +function yourChoice(chName) { 1.158 +pause = 0; 1.159 +if (all!=0) ended(); 1.160 +if (all==0) { 1.161 +cf = 0; 1.162 +ok = 0; 1.163 +temp=chName; 1.164 +checkSpace(); 1.165 +if (ok==1) { 1.166 +document.images[chName].src = x; 1.167 +} 1.168 +if (ok==0)taken(); 1.169 +process(); 1.170 +if ((all==0)&&(pause==0)) myChoice(); 1.171 + } 1.172 +} 1.173 +function taken() { 1.174 +alert("Please, select an empty. \n\n") 1.175 +pause=1; 1.176 +} 1.177 +function myChoice() { 1.178 +temp=""; 1.179 +ok = 0; 1.180 +cf=1; 1.181 +logicTwo(); 1.182 +logicThree(); 1.183 +checkSpace(); 1.184 +while(ok==0) { 1.185 +aRandomNumber=Math.random() 1.186 +comp=Math.round((choice-1)*aRandomNumber)+1; 1.187 +if (comp==1) temp="A"; 1.188 +if (comp==2) temp="B"; 1.189 +if (comp==3) temp="C"; 1.190 +if (comp==4) temp="D"; 1.191 +if (comp==5) temp="E"; 1.192 +if (comp==6) temp="F"; 1.193 +if (comp==7) temp="G"; 1.194 +if (comp==8) temp="H"; 1.195 +if (comp==9) temp="I"; 1.196 +checkSpace(); 1.197 +} 1.198 +document.images[temp].src= o; 1.199 +process(); 1.200 +} 1.201 +function restart() { 1.202 + if (confirm('Delete all score and restart game?')) { 1.203 + window.location="slitaz-tic-tac-toe.html" 1.204 +} 1.205 +} 1.206 +function ended() { 1.207 +alert("Ops! This round is over. \n\n To play again click 'New Round' button. \n\n To restart all game click 'Restart' button.") 1.208 +} 1.209 +function process() { 1.210 +logicOne(); 1.211 +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++;} 1.212 +if (all==2){ alert("Awww, that's too bad! \n\n Try to win me! \n\n"); ls++;} 1.213 +if (all==3){ alert("Tie! Let's play again?"); ts++;} 1.214 +if (all!=0) { 1.215 +document.game.you.value = wn; 1.216 +document.game.slitaz.value = ls; 1.217 +document.game.ties.value = ts; 1.218 + } 1.219 +} 1.220 +function playAgain() { 1.221 +if (all==0) { 1.222 +if(confirm("Start new round?")) reset(); 1.223 +} 1.224 +if (all>0) reset(); 1.225 +} 1.226 +function reset() { 1.227 +all = 0; 1.228 +a = 0; 1.229 +b = 0; 1.230 +c = 0; 1.231 +d = 0; 1.232 +e = 0; 1.233 +f = 0; 1.234 +g = 0; 1.235 +h = 0; 1.236 +i = 0; 1.237 +temp=""; 1.238 +ok = 0; 1.239 +cf = 0; 1.240 +choice=9; 1.241 +aRandomNumber = 0; 1.242 +comp = 0; 1.243 +document.images.A.src= blank; 1.244 +document.images.B.src= blank; 1.245 +document.images.C.src= blank; 1.246 +document.images.D.src= blank; 1.247 +document.images.E.src= blank; 1.248 +document.images.F.src= blank; 1.249 +document.images.G.src= blank; 1.250 +document.images.H.src= blank; 1.251 +document.images.I.src= blank; 1.252 +if (t==0) { t=2; myChoice(); } 1.253 +t--; 1.254 +}