<html> <head> <title>タイピングゲーム</title> <script language="JavaScript"><!-- for(i=0;i<10;i++){ img=new Array(); img[i]=new Image(); img[i].src="image/"+i+".jpg"; } function game(){ count=0; miss=0; n=Math.floor(Math.random()*10); document.images["Num"].src ="image/"+n+".jpg"; //setTimeout("game()",1000); date=new Date(); miri=date.getTime(); } function key(){ k=event.keyCode-48; if(k>=48){ k=k-48; } if(k==n){ check=n; //重複を消す処理 n=Math.floor(Math.random()*10); while(check==n){ n=Math.floor(Math.random()*10); } count=count+1; if(count==10){ //終了処理 date=new Date(); endmiri=date.getTime(); time=endmiri-miri; time=Math.floor(time/1000); alert("ゲーム終了です。\n"+time+"秒 ミス"+miss+"回"); document.images["Num"].src ="image/s.jpg"; return; } document.images["Num"].src ="image/"+n+".jpg"; }else{ miss=miss+1; } } //--></script> </head> <body onKeydown="key()"> 早押しゲーム<br><br> <img src="image/s.jpg" name="Num"> <form> <input type="button" value="ゲーム開始" onClick="game()" > </form> </body> </html>