102 lines
No EOL
3.1 KiB
HTML
102 lines
No EOL
3.1 KiB
HTML
<html>
|
|
<HEAD>
|
|
<title>Zeros</title>
|
|
<meta name="viewport" content="width=240">
|
|
<style>
|
|
body { margin:0px; }
|
|
#screen { width: 240px; height:176px; overflow: hidden; }
|
|
</style>
|
|
<!--input { border-left: 10px; border-right: 10px; border-color: silver; border-style: double }-->
|
|
<!-- http://javascript.internet.com -->
|
|
<!-- Original: http://webplaza.pt.lu/dostert/ -->
|
|
<SCRIPT>
|
|
var Size = new Number(6);
|
|
var Moves = new Array();
|
|
function NewGame(){
|
|
for(i = 0; i < Size * Size; document.forms[0].elements[i++].value = 0);
|
|
for(i = 0; i < 3 + 3 * document.forms[0].Difficulty.selectedIndex; i++)
|
|
NewValue(Math.floor(Math.random() * Size),Math.floor(Math.random() * Size),1);
|
|
Moves.length = document.forms[0].Score.value = 0;
|
|
}
|
|
function TakeBack(flag){
|
|
|
|
while(flag-- && (i = Moves.pop()))
|
|
|
|
NewValue(parseInt(i.split("-")[0]),parseInt(i.split("-")[1]),1);
|
|
|
|
document.forms[0].Score.value = Moves.length;
|
|
|
|
}
|
|
function Clicked(x,y){
|
|
|
|
NewValue(x,y,3);
|
|
|
|
document.forms[0].Score.value = Moves.push(x + "-" + y);
|
|
|
|
for(i = 0; i < Size * Size; i++)
|
|
|
|
if(parseInt(document.forms[0].elements[i].value))
|
|
|
|
return;
|
|
|
|
alert((Moves.length <= 3 + 3 * document.forms[0].Difficulty.selectedIndex ? "Perfect! " : "") + "Done in " + Moves.length + " clicks");
|
|
|
|
NewGame();
|
|
|
|
}
|
|
function NewValue(x,y,c){
|
|
|
|
ChangeValue(x,y,c);
|
|
|
|
ChangeValue(x - 1,y,c);
|
|
|
|
ChangeValue(x + 1,y,c);
|
|
|
|
ChangeValue(x,y - 1,c);
|
|
|
|
ChangeValue(x,y + 1,c);
|
|
|
|
}
|
|
function ChangeValue(x,y,c){
|
|
|
|
if(x >= 0 && x < Size && y >= 0 && y < Size)
|
|
|
|
with(document.forms[0].elements[x + Size * y]) value = (parseInt(value) + c) & 3;
|
|
|
|
}
|
|
</script>
|
|
<script>
|
|
function help(){
|
|
alert("Click on one of the buttons in the playing field to decrement that buttons value by 1, as well as the values of the 4 surrounding ones. The goal is to set all buttons to '0'.");
|
|
}
|
|
</script>
|
|
</HEAD>
|
|
<BODY onLoad="NewGame()">
|
|
<div id="screen">
|
|
<center><font size="2">
|
|
<a href="" onClick="NewGame(); return false;" onMouseOver="window.status='Start a new game'; return true;" onMouseOut="window.status=''; return true;" title="Start a new game">New</a> - <a href="" onClick="TakeBack(-1); return false;" onMouseOver="window.status='Restart the board'; return true;" onMouseOut="window.status=''; return true;" title="Restart the board">Restart</a> - <a href="" onClick="TakeBack(1); return false;" onMouseOver="window.status='Undo last move'; return true;" onMouseOut="window.status=''; return true;" title="Undo last move">Undo</a> - <a href="javascript:help();">Help</a>
|
|
<form action="" method="get" enctype="application/x-www-form-urlencoded">
|
|
<script>
|
|
for(y = 0; y < Size; y++,window.document.write("<br>"))
|
|
|
|
for(x = 0; x < Size; x++)
|
|
|
|
window.document.write('<input type="button" value="" onClick="Clicked(' + x + ',' + y + ')">');
|
|
</script>
|
|
Level: <select name="Difficulty" onChange="NewGame()">
|
|
<option>Huh, what?</option>
|
|
<option>Dumb</option>
|
|
<option>Real easy</option>
|
|
<option>Easy</option>
|
|
<option selected>Normal</option>
|
|
<option>Hard</option>
|
|
<option>Real hard</option>
|
|
<option>Master</option>
|
|
<option>Impossible</option>
|
|
</select>
|
|
Clicks: <input type="text" name="Score" value="0" size="3" disabled>
|
|
</form>
|
|
</font></center>
|
|
</div>
|
|
</BODY>
|
|
</html> |