topical media & game development
game-javascript-casual-knight-game.htm / htm
<!-- ONE STEP TO INSTALL KNIGHT GAME:
1. Copy the coding into the BODY of your HTML document -->
<!-- STEP ONE: Paste this code into the BODY of your HTML document -->
<BODY>
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Original: Ben Joffe -->
<!-- Web Site: http://www.joffe.tk/ -->
<script>
document.write('<table style=cursor:pointer;cursor:hand border=2 cellpadding=0 cellspacing=0>')
var squarenum=0;
var curnum=0;
curcol="#996633";
for(var count1=0; count1<8; count1++){
document.write('<tr>')
if(curcol=="#996633") {curcol="#663300"} else curcol="#996633";
for(var count=0; count<8; count++){
if(curcol=="#996633") {curcol="#663300"} else curcol="#996633";
document.write('<td bgcolor='+curcol+' id='+curnum+' name='+squarenum+' width=50 height=50 onclick=\"moveto(this);\"> </td>');
curnum++;
squarenum++
}
document.write('</tr>')
curnum+=20;
}
document.write('</table>')
document.getElementById(0).innerHTML="<img src=horse.gif>";
document.getElementById(0).bgColor="#FF99FF";
var squares=new Array(true);
var score=0;
var where;
var oldwhere=0;
function moveto(square){
where=square.id;
if ((oldwhere==where-26 || oldwhere==where-30 || oldwhere==where-55 || oldwhere==where-57 || oldwhere-26==where || oldwhere-30==where || oldwhere-55==where || oldwhere-57==where))
{
score++;
document.getElementById("scorey").innerHTML=score;
document.getElementById(oldwhere).innerHTML=" ";
document.getElementById(where).innerHTML="<img src=horse.gif width=48 height=48>";
document.getElementById(where).bgColor="#FF99FF";
oldwhere=where;
squares[square.name]=true;
}
for (var i=0; i<63; i++) if (squares[i]!=true) var stuffed=true
if (stuffed!=true) {alert("You win in only "+score+" moves!");window.location.href=window.location.href;}
}
</script>
<p>Score: <span id=scorey>0</span><br>
<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: 2.06 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.