topical media & game development
game-javascript-casual-typing-game.htm / htm
<!-- THREE STEPS TO INSTALL TYPE GAME:
1. Copy the coding into the HEAD of your HTML document
2. Add the onLoad event handler into the BODY tag
3. Put the last coding into the BODY of your HTML document -->
<!-- STEP ONE: Paste this code into the HEAD of your HTML document -->
<HEAD>
<!-- 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>
var currentspeed=1500;
var difficulty=new Array("25","10", "35")
var range=new Array("0", "25", "0")
var how;
var letters=new Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9");
function writeletters(){
if (writearea.innerHTML.substring(0, 1)=="<") writearea.innerHTML="";
var ranum=Math.round(Math.random()*difficulty[how]- -range[how])
if (currentspeed>50) currentspeed=currentspeed-10;
if (writearea.innerHTML.length<15) {writearea.innerHTML=writearea.innerHTML+letters[ranum];
setTimeout('writeletters()', currentspeed)}
else {endgame()}
}
function begingame(){
currentspeed=1500
scorearea.innerHTML="0";
how=hardness.options.selectedIndex
writeletters();
}
function keypress(butpush){
if (letters[butpush-65]==writearea.innerHTML.substring(0, 1)) {writearea.innerHTML=writearea.innerHTML.substring(1, writearea.innerHTML.length);scorearea.innerHTML=scorearea.innerHTML- -1}
var numbers2=new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9");
if (numbers2[butpush-48]==writearea.innerHTML.substring(0, 1)){writearea.innerHTML=writearea.innerHTML.substring(1, writearea.innerHTML.length);scorearea.innerHTML=scorearea.innerHTML- -1}
}
var doeeee=1;
function showwait(){
if (doeeee==1){waiting.innerHTML="_";doeeee=0;}
else {waiting.innerHTML=" ";doeeee=1;}
setTimeout('showwait()', 500)
}
function endgame(){
writearea.innerHTML='<input type="button" value="Begin Game" onclick=begingame()> <select id=hardness size="1"><option>Letters</option><option>Numbers</option><option>Letters And Numbers</option></select>'
}
</script>
</HEAD>
<!-- STEP TWO: Insert the onLoad event handler into your BODY tag -->
<BODY onKeyPress="if (event.keyCode > 96 && event.keyCode < 123) event.keyCode=event.keyCode-32; keypress(event.keyCode)" onload=focus();showwait();endgame()gt;
<!-- STEP THREE: Copy this code into the BODY of your HTML document -->
<!-- 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/ -->
<p><span id=writearea></span><span id=waiting></span></p>
<p>Score = <span id=scorearea>0</span>
<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.93 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.