topical media & game development
game-javascript-casual-shift-it-game.htm / htm
<!-- ONE STEP TO INSTALL SHIFT IT:
1. Paste the coding into the BODY of your HTML document -->
<!-- STEP ONE: Copy this coding into the BODY of your HTML document -->
<BODY>
<center>
<form name=pad>
<table border=2 cellpadding=2 cellspacing=2>
<tr>
<td colspan=4 align=center>Shift It 4x4 Game</td>
</tr>
<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Dion -->
<!-- Web Site: http://www.iinet.net.au/~biab/ -->
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
bx=3; by=3;
for (y=0;y<4;y++) {
document.write('<tr>');
for (x=0;x<4;x++) {
document.write('<td><tt><input type=button value=" " ');
document.write('onclick="move('+x+','+y+');"></tt></td>');
}
document.write('</tr>');
}
function move(x,y) {
ax=Math.abs(bx-x);
ay=Math.abs(by-y);
if (((ax*ay)==0)&&((ax+ay)==1)) {
f=document.pad;
f.elements[4*by+bx].value=f.elements[4*y+x].value;
f.elements[4*y+x].value=" ";
bx=x; by=y; f.msg.value++;
}
}
function rndize() {
alpha="ABCDEFGHIJKLMNO ";
for (i=0;i<16;i++) {
x=0;
y=0;
while (document.pad.elements[4*y+x].value!=" ") {
x=Math.floor(Math.random()*4);
y=Math.floor(Math.random()*4);
}
document.pad.elements[4*y+x].value=alpha.substring(i,i+1);
}
bx=x;
by=y;
}
rndize();
// End -->
</script>
<tr>
<td colspan=4><input type=text size=20 name=msg></td>
</tr>
</table>
</form>
</center>
<p><center>
<font face="arial, helvetica" size="-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>
<!-- Script Size: 1.46 KB -->
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.