wok-6.x view jssame/stuff/var/www/same/index.html @ rev 11605

Add jssame
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Jan 20 16:09:12 2012 +0100 (2012-01-20)
parents
children 38deae80557b
line source
1 <html>
2 <head>
3 <title>Same Game</title>
4 <style type="text/css">
5 body, input {
6 background: black;
7 color: white;
8 border: none;
9 font-size: 14px;
10 }
11 a { color: black; }
12 </style>
13 <script language="javascript">
14 <!-- // Original: Jason Fondren (usher@betterbox.net) http://www.oogha.com/
15 // 0=blank 1=red 2=yellow 3=blue
17 off0 = new Image(); off0.src = "black.gif";
18 off1 = new Image(); off1.src = "1off.gif";
19 off2 = new Image(); off2.src = "2off.gif";
20 off3 = new Image(); off3.src = "3off.gif";
21 on0 = new Image(); on0.src = "black.gif";
22 on1 = new Image(); on1.src = "1on.gif";
23 on2 = new Image(); on2.src = "2on.gif";
24 on3 = new Image(); on3.src = "3on.gif";
26 total = 0
27 imgsize = (innerHeight - 20)/10
28 if (imgsize > 32) imgsize = 32
30 main = new Array()
31 init = new Array()
32 for (i = 0; i < 150; i++)
33 main[i] = init[i] = 1 + Math.floor((Math.random() * 3))
35 function isSameBelow(numba) {
36 return main[numba-1] == main[numba] && (numba % 10) != 0
37 }
39 function isSameAbove(numba) {
40 return main[numba+1] == main[numba] && (numba % 10) != 9
41 }
43 function AddAdjacent(numba) {
44 for (n=0; n<adj.length; n++)
45 if (adj[n] == numba) return
46 adj[++i] = numba
47 }
49 function isNotBallSet(numba) {
50 if (main[numba] == 0) return true
51 adj = new Array()
52 adj[0] = numba
53 for (i = c = 0; c < adj.length; c++) {
54 numba = adj[c]
55 if (isSameAbove(numba)) AddAdjacent(numba+1)
56 if (main[numba+10] == main[numba]) AddAdjacent(numba+10)
57 if (isSameBelow(numba)) AddAdjacent(numba-1)
58 if (main[numba-10] == main[numba]) AddAdjacent(numba-10)
59 }
60 if (c < 2) return true
61 c -= 2
62 score = c * c
63 return false
64 }
66 function Ball(numba,state) {
67 if (isNotBallSet(numba)) return
68 if (state == "off") score = 0
69 document.scores.click.value = score
70 for (n = 0; n < adj.length; n++)
71 document["img" + adj[n]].src = eval(state + main[numba] + ".src")
72 }
74 function clickBall(numba) {
75 if (isNotBallSet(numba)) return
76 for (n=0; n<adj.length; n++) main[adj[n]] = 0
77 for (change = i = 0; i < 15; i++, change += 10) {
78 blankCount = 0
79 column = new Array()
80 newColumn = new Array()
81 for (c = 0; c < 10; c++) {
82 column[c] = main[c + change]
83 if (column[c] == 0)
84 newColumn[10 - ++blankCount] = 0
85 else newColumn[c - blankCount] = column[c]
86 }
87 for (c = 0; c < 10; c++) main[c + change] = newColumn[c]
88 if (blankCount == 10) {
89 for (c = change; c < 140; c++) main[c] = main[c + 10]
90 for (c = 140; c < 150; c++) main[c] = 0
91 change -= 10
92 }
93 }
94 startUp()
95 document.scores.show.value = total += score
96 Ball(numba,"on")
97 if (main[0] == 0) return // board is cleared
98 for (q = 0; q < 150; q++) {
99 if (main[q] == 0) continue
100 if (isSameAbove(q)) return
101 if (main[q + 10] == main[q]) return
102 if (isSameBelow(q)) return
103 if (main[q - 10] == main[q]) return
104 }
105 alert("Game Over!")
106 }
108 function startUp() {
109 // if (navigator.userAgent.substring(0,6) == "TazWeb")
110 // window.resizeTo(32*15, 32*10+20)
111 document.scores.show.value = 0
112 for (i = 0; i < main.length; i++)
113 document["img" + i].src = eval("off" + main[i] + ".src")
114 }
116 function replay() {
117 for (i = total = 0; i < init.length; i++)
118 main[i] = init[i]
119 startUp()
120 }
121 // -->
122 </script>
123 </head>
125 <body onLoad="startUp()">
127 <div align="center">
128 <table border=0 cellpadding=0 cellspacing=0 bgcolor=black>
129 <script language="javascript">
130 <!-- // Original: Jason Fondren (usher@betterbox.net) http://www.oogha.com/
131 for (i = 9; i >= 0; i--) {
132 document.writeln('<tr>')
133 for (n = i; n < 150; n += 10)
134 document.writeln('<td><a href=javascript:clickBall(' + n +
135 ') onmouseover=Ball(' + n + ',"on") onmouseout=Ball(' + n +
136 ',"off")><img src=black.gif height=' + imgsize + ' width=' +
137 imgsize + ' name=img' + n + ' border=0></a></td>')
138 document.writeln('</tr>')
139 }
140 //-->
141 </script>
143 </table>
144 <form name=scores method=post>
145 Total Score:<span title="replay the same board"><input type=text name=show size=6 value=0 onFocus="blur()" onClick="replay()"></span>
146 Click Score:<input type=text name=click size=6 value=0 onFocus="blur()">
147 <span title="play a new board"><input type=submit value=New></span>
148 </form>
149 </center>
150 </body></html>