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

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