wok-next rev 11605
Add jssame
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Fri Jan 20 16:09:12 2012 +0100 (2012-01-20) |
parents | b18a9cc2a0ba |
children | 6da83b7b4dea |
files | jssame/receipt jssame/stuff/usr/share/applications/same.desktop jssame/stuff/var/www/same/1off.gif jssame/stuff/var/www/same/1on.gif jssame/stuff/var/www/same/2off.gif jssame/stuff/var/www/same/2on.gif jssame/stuff/var/www/same/3off.gif jssame/stuff/var/www/same/3on.gif jssame/stuff/var/www/same/black.gif jssame/stuff/var/www/same/index.html |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/jssame/receipt Fri Jan 20 16:09:12 2012 +0100 1.3 @@ -0,0 +1,16 @@ 1.4 +# SliTaz package receipt. 1.5 + 1.6 +PACKAGE="jssame" 1.7 +VERSION="1.0" 1.8 +CATEGORY="games" 1.9 +SHORT_DESC="Same game in javascript" 1.10 +MAINTAINER="pascal.bellard@slitaz.org" 1.11 +WEB_SITE="http://www.slitaz.org/" 1.12 + 1.13 +# Rules to gen a SliTaz package suitable for Tazpkg. 1.14 +genpkg_rules() 1.15 +{ 1.16 + cp -a $stuff $fs 1.17 + chown -R 80.80 $fs/var/www/jssame 1.18 +} 1.19 +
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/jssame/stuff/usr/share/applications/same.desktop Fri Jan 20 16:09:12 2012 +0100 2.3 @@ -0,0 +1,8 @@ 2.4 +[Desktop Entry] 2.5 +Type=Application 2.6 +Name=Same 2.7 +Exec=browser file:///var/www/same/index.html 2.8 +Icon=/var/www/same/2on.gif 2.9 +Terminal=false 2.10 +Categories=Game; 2.11 +Comment=Chess game
3.1 Binary file jssame/stuff/var/www/same/1off.gif has changed
4.1 Binary file jssame/stuff/var/www/same/1on.gif has changed
5.1 Binary file jssame/stuff/var/www/same/2off.gif has changed
6.1 Binary file jssame/stuff/var/www/same/2on.gif has changed
7.1 Binary file jssame/stuff/var/www/same/3off.gif has changed
8.1 Binary file jssame/stuff/var/www/same/3on.gif has changed
9.1 Binary file jssame/stuff/var/www/same/black.gif has changed
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 10.2 +++ b/jssame/stuff/var/www/same/index.html Fri Jan 20 16:09:12 2012 +0100 10.3 @@ -0,0 +1,150 @@ 10.4 +<html> 10.5 +<head> 10.6 +<title>Same Game</title> 10.7 +<style type="text/css"> 10.8 +body, input { 10.9 + background: black; 10.10 + color: white; 10.11 + border: none; 10.12 + font-size: 14px; 10.13 +} 10.14 +a { color: black; } 10.15 +</style> 10.16 +<script language="javascript"> 10.17 +<!-- // Original: Jason Fondren (usher@betterbox.net) http://www.oogha.com/ 10.18 +// 0=blank 1=red 2=yellow 3=blue 10.19 + 10.20 +off0 = new Image(); off0.src = "black.gif"; 10.21 +off1 = new Image(); off1.src = "1off.gif"; 10.22 +off2 = new Image(); off2.src = "2off.gif"; 10.23 +off3 = new Image(); off3.src = "3off.gif"; 10.24 +on0 = new Image(); on0.src = "black.gif"; 10.25 +on1 = new Image(); on1.src = "1on.gif"; 10.26 +on2 = new Image(); on2.src = "2on.gif"; 10.27 +on3 = new Image(); on3.src = "3on.gif"; 10.28 + 10.29 +total = 0 10.30 +imgsize = (innerHeight - 20)/10 10.31 +if (imgsize > 32) imgsize = 32 10.32 + 10.33 +main = new Array() 10.34 +init = new Array() 10.35 +for (i = 0; i < 150; i++) 10.36 + main[i] = init[i] = 1 + Math.floor((Math.random() * 3)) 10.37 + 10.38 +function isSameBelow(numba) { 10.39 + return main[numba-1] == main[numba] && (numba % 10) != 0 10.40 +} 10.41 + 10.42 +function isSameAbove(numba) { 10.43 + return main[numba+1] == main[numba] && (numba % 10) != 9 10.44 +} 10.45 + 10.46 +function AddAdjacent(numba) { 10.47 + for (n=0; n<adj.length; n++) 10.48 + if (adj[n] == numba) return 10.49 + adj[++i] = numba 10.50 +} 10.51 + 10.52 +function isNotBallSet(numba) { 10.53 + if (main[numba] == 0) return true 10.54 + adj = new Array() 10.55 + adj[0] = numba 10.56 + for (i = c = 0; c < adj.length; c++) { 10.57 + numba = adj[c] 10.58 + if (isSameAbove(numba)) AddAdjacent(numba+1) 10.59 + if (main[numba+10] == main[numba]) AddAdjacent(numba+10) 10.60 + if (isSameBelow(numba)) AddAdjacent(numba-1) 10.61 + if (main[numba-10] == main[numba]) AddAdjacent(numba-10) 10.62 + } 10.63 + if (c < 2) return true 10.64 + c -= 2 10.65 + score = c * c 10.66 + return false 10.67 +} 10.68 + 10.69 +function Ball(numba,state) { 10.70 + if (isNotBallSet(numba)) return 10.71 + if (state == "off") score = 0 10.72 + document.scores.click.value = score 10.73 + for (n = 0; n < adj.length; n++) 10.74 + document["img" + adj[n]].src = eval(state + main[numba] + ".src") 10.75 +} 10.76 + 10.77 +function clickBall(numba) { 10.78 + if (isNotBallSet(numba)) return 10.79 + for (n=0; n<adj.length; n++) main[adj[n]] = 0 10.80 + for (change = i = 0; i < 15; i++, change += 10) { 10.81 + blankCount = 0 10.82 + column = new Array() 10.83 + newColumn = new Array() 10.84 + for (c = 0; c < 10; c++) { 10.85 + column[c] = main[c + change] 10.86 + if (column[c] == 0) 10.87 + newColumn[10 - ++blankCount] = 0 10.88 + else newColumn[c - blankCount] = column[c] 10.89 + } 10.90 + for (c = 0; c < 10; c++) main[c + change] = newColumn[c] 10.91 + if (blankCount == 10) { 10.92 + for (c = change; c < 140; c++) main[c] = main[c + 10] 10.93 + for (c = 140; c < 150; c++) main[c] = 0 10.94 + change -= 10 10.95 + } 10.96 + } 10.97 + startUp() 10.98 + document.scores.show.value = total += score 10.99 + Ball(numba,"on") 10.100 + if (main[0] == 0) return // board is cleared 10.101 + for (q = 0; q < 150; q++) { 10.102 + if (main[q] == 0) continue 10.103 + if (isSameAbove(q)) return 10.104 + if (main[q + 10] == main[q]) return 10.105 + if (isSameBelow(q)) return 10.106 + if (main[q - 10] == main[q]) return 10.107 + } 10.108 + alert("Game Over!") 10.109 +} 10.110 + 10.111 +function startUp() { 10.112 +// if (navigator.userAgent.substring(0,6) == "TazWeb") 10.113 +// window.resizeTo(32*15, 32*10+20) 10.114 + document.scores.show.value = 0 10.115 + for (i = 0; i < main.length; i++) 10.116 + document["img" + i].src = eval("off" + main[i] + ".src") 10.117 +} 10.118 + 10.119 +function replay() { 10.120 + for (i = total = 0; i < init.length; i++) 10.121 + main[i] = init[i] 10.122 + startUp() 10.123 +} 10.124 +// --> 10.125 +</script> 10.126 +</head> 10.127 + 10.128 +<body onLoad="startUp()"> 10.129 + 10.130 +<div align="center"> 10.131 +<table border=0 cellpadding=0 cellspacing=0 bgcolor=black> 10.132 +<script language="javascript"> 10.133 +<!-- // Original: Jason Fondren (usher@betterbox.net) http://www.oogha.com/ 10.134 +for (i = 9; i >= 0; i--) { 10.135 + document.writeln('<tr>') 10.136 + for (n = i; n < 150; n += 10) 10.137 + document.writeln('<td><a href=javascript:clickBall(' + n + 10.138 + ') onmouseover=Ball(' + n + ',"on") onmouseout=Ball(' + n + 10.139 + ',"off")><img src=black.gif height=' + imgsize + ' width=' + 10.140 + imgsize + ' name=img' + n + ' border=0></a></td>') 10.141 + document.writeln('</tr>') 10.142 +} 10.143 +//--> 10.144 +</script> 10.145 + 10.146 +</table> 10.147 +<form name=scores method=post> 10.148 +Total Score:<span title="replay the same board"><input type=text name=show size=6 value=0 onFocus="blur()" onClick="replay()"></span> 10.149 +Click Score:<input type=text name=click size=6 value=0 onFocus="blur()"> 10.150 +<span title="play a new board"><input type=submit value=New></span> 10.151 +</form> 10.152 +</center> 10.153 +</body></html>