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