源代码 分数 命中率 倒计时 js代码 var playing=false;var interId=null;var timeId=null;//分数var score=0;//打中率var success=0;//点击次数var beat=0;//时间var countDown=60;//击中次数var knock=0;//游戏结束function
js代码
var playing=false; var interId=null; var timeId=null; //分数 var score=0; //打中率 var success=0; //点击次数 var beat=0; //时间 var countDown=60; //击中次数 var knock=0; //游戏结束 function gameOver(){ timeStop(); playing=false; clearMouse(); alert("游戏结束!你击中了"+score+"只老鼠"+"很棒棒啊!"); score=0; success=0; } //时间显示 function timeShow(){ document.form1.remtime.value=countDown; if(countDown==0){ gameOver(); return ; }else{ countDown=countDown-1; timeId=setTimeout("timeShow()",1000); } } //中途停止 function timeStop(){ clearTimeout(timeId); clearInterval(interId); } //老鼠随机出现 function show(){ if(playing){ //获取随机数 var current=Math.floor(Math.random()*25); //换成老鼠图片 document.getElementById("td["+current+"]").innerHTML= ''; //隐藏图片 setTimeout("document.getElementById('td["+current+"]').innerHTML=''",500); } } //清除所有老鼠 function clearMouse(){ beat++; for(var i=1;i<26;i++){ document.getElementById("td["+i+"]").innerHTML=""; } } //打老鼠 function hit(i){ if(playing==false){ alert("请点击开始!"); return ; }else{ beat++; if(document.getElementById("td["+i+"]").innerHTML!=""){ score++; knock++; success=knock/beat; document.form1.score.value=score; document.form1.success.value=success; document.getElementById("td["+i+"]").innerHTML=""; }else{ score--; success=knock/beat; document.form1.score.value=score; document.form1.success.value=success; } } } //开始游戏 function gameStart(){ playing=true; interId=setInterval("show()",1000); document.form1.score.value=score; document.form1.success.value=success; timeShow(); }