wok-tiny view jssame/stuff/index.html @ rev 73

Add jssame
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Jan 21 12:51:08 2012 +0100 (2012-01-21)
parents
children 044813ac0732
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 {
12 color: black;
13 text-decoration: none;
14 }
15 </style>
16 <script language="javascript">
17 <!-- // Original: Jason Fondren (usher@betterbox.net) http://www.oogha.com/
19 var none=" ", off="&#9679;", on="&bull;", color=["black","red","yellow","blue"];
21 total = 0
22 sz = (innerHeight - 20)/10
24 main = new Array()
25 init = new Array()
26 for (i = 0; i < 150; i++)
27 main[i] = init[i] = 1 + Math.floor((Math.random() * 3))
29 function sameBelow(nb) {
30 return main[nb-1] == main[nb] && (nb % 10) != 0
31 }
33 function sameAbove(nb) {
34 return main[nb+1] == main[nb] && (nb % 10) != 9
35 }
37 function AddAdj(nb) {
38 for (n=0; n<adj.length; n++)
39 if (adj[n] == nb) return
40 adj[++i] = nb
41 }
43 function notBalls(nb) {
44 if (main[nb] == 0) return true
45 adj = new Array()
46 adj[0] = nb
47 for (i = c = 0; c < adj.length; c++) {
48 nb = adj[c]
49 if (sameAbove(nb)) AddAdj(nb+1)
50 if (main[nb+10] == main[nb]) AddAdj(nb+10)
51 if (sameBelow(nb)) AddAdj(nb-1)
52 if (main[nb-10] == main[nb]) AddAdj(nb-10)
53 }
54 if (c < 2) return true
55 c -= 2
56 score = c * c
57 return false
58 }
60 function Ball(nb,state) {
61 if (notBalls(nb)) return
62 if (state == off) score = 0
63 document.scores.click.value = score
64 for (n = 0; n < adj.length; n++)
65 document.getElementById("b" + adj[n]).innerHTML = state
66 }
68 function clickBall(nb) {
69 if (notBalls(nb)) return
70 for (n=0; n<adj.length; n++) main[adj[n]] = 0
71 for (change = i = 0; i < 15; i++, change += 10) {
72 blankCount = 0
73 column = new Array()
74 newColumn = new Array()
75 for (c = 0; c < 10; c++) {
76 column[c] = main[c + change]
77 if (column[c] == 0)
78 newColumn[10 - ++blankCount] = 0
79 else newColumn[c - blankCount] = column[c]
80 }
81 for (c = 0; c < 10; c++) main[c + change] = newColumn[c]
82 if (blankCount == 10) {
83 for (c = change; c < 140; c++) main[c] = main[c + 10]
84 for (c = 140; c < 150; c++) main[c] = 0
85 change -= 10
86 }
87 }
88 startUp()
89 document.scores.show.value = total += score
90 Ball(nb,on)
91 if (main[0] == 0) return // board is cleared
92 for (q = 0; q < 150; q++) {
93 if (main[q] == 0) continue
94 if (sameAbove(q)) return
95 if (main[q + 10] == main[q]) return
96 if (sameBelow(q)) return
97 if (main[q - 10] == main[q]) return
98 }
99 alert("Game Over!")
100 }
102 function startUp() {
103 document.scores.show.value = 0
104 for (i = 0; i < main.length; i++) {
105 var o=document.getElementById("b" + i)
106 o.innerHTML = off
107 o.style.color = color[main[i]]
108 }
109 }
111 function replay() {
112 for (i = total = 0; i < init.length; i++)
113 main[i] = init[i]
114 startUp()
115 }
117 // -->
118 </script>
119 </head>
121 <body onLoad="startUp()">
122 <div align="center">
123 <table border=0 cellpadding=0 cellspacing=0>
124 <script language="javascript">
125 <!--
126 for (i = 9; i >= 0; i--) {
127 document.writeln('<tr>')
128 for (n = i; n < 150; n += 10)
129 document.writeln('<td width=' + sz + ' height=' + sz +
130 ' align=center style="font-size:' + sz + 'px;">' +
131 '<a id=b' + n + ' href=javascript:clickBall(' + n +
132 ') onmouseover=Ball(' + n + ',"' + on +
133 '") onmouseout=Ball(' + n + ',"' + off + '")>' +
134 none + '</a></td>')
135 document.writeln('</tr>')
136 }
137 //-->
138 </script>
140 </table>
141 <form name=scores method=post>
142 Total Score:<span title="replay the same board"><input type=text name=show size=6 value=0 onFocus="blur()" onClick="replay()"></span>
143 Click Score:<input type=text name=click size=6 value=0 onFocus="blur()">
144 <span title="play a new board"><input type=submit value=New></span>
145 </form>
146 </center>
147 </body></html>