wok-tiny rev 73

Add jssame
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Jan 21 12:51:08 2012 +0100 (2012-01-21)
parents 326cb72ed4ae
children 044813ac0732
files jssame/receipt jssame/stuff/index.html
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/jssame/receipt	Sat Jan 21 12:51:08 2012 +0100
     1.3 @@ -0,0 +1,17 @@
     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 +	mkdir $fs/var/www/same
    1.17 +	cp -a $stuff/index.html $fs/var/www/same
    1.18 +	chown -R 80.80 $fs/var/www/same
    1.19 +}
    1.20 +
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/jssame/stuff/index.html	Sat Jan 21 12:51:08 2012 +0100
     2.3 @@ -0,0 +1,147 @@
     2.4 +<html>
     2.5 +<head>
     2.6 +<title>Same Game</title>
     2.7 +<style type="text/css">
     2.8 +body, input {
     2.9 +	background: black;
    2.10 +	color: white;
    2.11 +	border: none;
    2.12 +	font-size: 14px;
    2.13 +}
    2.14 +a {
    2.15 +	color: black;
    2.16 +	text-decoration: none;
    2.17 +}
    2.18 +</style>
    2.19 +<script language="javascript">
    2.20 +<!-- // Original:  Jason Fondren (usher@betterbox.net) http://www.oogha.com/
    2.21 +
    2.22 +var none=" ", off="&#9679;", on="&bull;", color=["black","red","yellow","blue"];
    2.23 +
    2.24 +total = 0
    2.25 +sz = (innerHeight - 20)/10
    2.26 +
    2.27 +main = new Array()
    2.28 +init = new Array()
    2.29 +for (i = 0; i < 150; i++)
    2.30 +	main[i] = init[i] = 1 + Math.floor((Math.random() * 3))
    2.31 +
    2.32 +function sameBelow(nb) {
    2.33 +	return main[nb-1] == main[nb] && (nb % 10) != 0
    2.34 +}
    2.35 +
    2.36 +function sameAbove(nb) {
    2.37 +	return main[nb+1] == main[nb] && (nb % 10) != 9
    2.38 +}
    2.39 +
    2.40 +function AddAdj(nb) {
    2.41 +	for (n=0; n<adj.length; n++)
    2.42 +		if (adj[n] == nb) return
    2.43 +	adj[++i] = nb
    2.44 +}
    2.45 +
    2.46 +function notBalls(nb) {
    2.47 +	if (main[nb] == 0) return true
    2.48 +	adj = new Array()
    2.49 +	adj[0] = nb
    2.50 +	for (i = c = 0; c < adj.length; c++) {
    2.51 +		nb = adj[c]
    2.52 +		if (sameAbove(nb)) AddAdj(nb+1)
    2.53 +		if (main[nb+10] == main[nb]) AddAdj(nb+10)
    2.54 +		if (sameBelow(nb)) AddAdj(nb-1)
    2.55 +		if (main[nb-10] == main[nb]) AddAdj(nb-10)
    2.56 +	}
    2.57 +	if (c < 2) return true
    2.58 +	c -= 2
    2.59 +	score = c * c
    2.60 +	return false
    2.61 +}
    2.62 +
    2.63 +function Ball(nb,state) {
    2.64 +	if (notBalls(nb)) return
    2.65 +	if (state == off) score = 0
    2.66 +	document.scores.click.value = score
    2.67 +	for (n = 0; n < adj.length; n++)
    2.68 +		document.getElementById("b" + adj[n]).innerHTML = state
    2.69 +}
    2.70 +
    2.71 +function clickBall(nb) {
    2.72 +	if (notBalls(nb)) return
    2.73 +	for (n=0; n<adj.length; n++) main[adj[n]] = 0
    2.74 +	for (change = i = 0; i < 15; i++, change += 10) {
    2.75 +		blankCount = 0
    2.76 +		column = new Array()
    2.77 +		newColumn = new Array()
    2.78 +		for (c = 0; c < 10; c++) {
    2.79 +			column[c] = main[c + change]
    2.80 +			if (column[c] == 0) 
    2.81 +				newColumn[10 - ++blankCount] = 0
    2.82 +			else	newColumn[c - blankCount] = column[c]
    2.83 +		}
    2.84 +		for (c = 0; c < 10; c++) main[c + change] = newColumn[c]
    2.85 +		if (blankCount == 10) {
    2.86 +			for (c = change; c < 140; c++) main[c] = main[c + 10]
    2.87 +			for (c = 140; c < 150; c++) main[c] = 0
    2.88 +			change -= 10
    2.89 +		}
    2.90 +	}
    2.91 +	startUp()
    2.92 +	document.scores.show.value = total += score
    2.93 +	Ball(nb,on)
    2.94 +	if (main[0] == 0) return // board is cleared
    2.95 +	for (q = 0; q < 150; q++) {
    2.96 +		if (main[q] == 0) continue
    2.97 +		if (sameAbove(q)) return
    2.98 +		if (main[q + 10] == main[q]) return
    2.99 +		if (sameBelow(q)) return
   2.100 +		if (main[q - 10] == main[q]) return
   2.101 +	}
   2.102 +	alert("Game Over!")
   2.103 +}
   2.104 +
   2.105 +function startUp() {
   2.106 +	document.scores.show.value = 0
   2.107 +	for (i = 0; i < main.length; i++) {
   2.108 +		var o=document.getElementById("b" + i)
   2.109 +		o.innerHTML = off
   2.110 +		o.style.color = color[main[i]]
   2.111 +	}
   2.112 +}
   2.113 +
   2.114 +function replay() {
   2.115 +	for (i = total = 0; i < init.length; i++)
   2.116 +		main[i] = init[i]
   2.117 +	startUp()
   2.118 +}
   2.119 +
   2.120 +// -->
   2.121 +</script>
   2.122 +</head>
   2.123 +
   2.124 +<body onLoad="startUp()">
   2.125 +<div align="center">
   2.126 +<table border=0 cellpadding=0 cellspacing=0>
   2.127 +<script language="javascript">
   2.128 +<!--
   2.129 +for (i = 9; i >= 0; i--) {
   2.130 +	document.writeln('<tr>')
   2.131 +	for (n = i; n < 150; n += 10)
   2.132 +		document.writeln('<td width=' + sz + ' height=' + sz + 
   2.133 +		  ' align=center style="font-size:' + sz + 'px;">' +
   2.134 +		  '<a id=b' + n + ' href=javascript:clickBall(' + n + 
   2.135 +		  ') onmouseover=Ball(' + n + ',"' + on + 
   2.136 +		  '") onmouseout=Ball(' + n + ',"' + off + '")>' + 
   2.137 +		  none + '</a></td>')
   2.138 +	document.writeln('</tr>')
   2.139 +}
   2.140 +//-->
   2.141 +</script>
   2.142 +
   2.143 +</table>
   2.144 +<form name=scores method=post>
   2.145 +Total Score:<span title="replay the same board"><input type=text name=show size=6 value=0 onFocus="blur()" onClick="replay()"></span>
   2.146 +Click Score:<input type=text name=click size=6 value=0 onFocus="blur()">
   2.147 +<span title="play a new board"><input type=submit value=New></span>
   2.148 +</form>
   2.149 +</center>
   2.150 +</body></html>