js抓人游戏 时间:2020-05-12 人气:0 无聊时写的游戏 啊! 这人好囧,快抓住他!得分:0剩余:60秒重新开始 剩骑士,来抓我啊? <script language="javascript" type="text/javascript"> var imgv,hitFlag=0,startTime,gameStatus=0,ret; var score=0,chato,delay=0; var chatArr=new Array(); chatArr[0]="剩骑士,来抓我啊?"; chatArr[1]="废柴职业 凸(- -)凸"; chatArr[2]="灌装奶粉 凸-_-凸"; chatArr[3]="万年三奶"; chatArr[4]="环保装哦"; chatArr[5]="咬我啊?"; function restart(){ var now = new Date(); startTime = now.getTime(); ret=setInterval("refreshTime()",10); gameStatus=1;hitFlag=0;score=0;delay=0; document.getElementById("score").innerHTML="得分:"+score; document.getElementById("restart").style.display="none"; } function moveTo(o,left,top){ clearTimeout(imgv); if (Math.abs(o.offsetLeft-left)<1 && Math.abs(o.offsetTop-top)<1){ o.style.left=left; o.style.top=top; }else{ var tx=o.offsetLeft-(o.offsetLeft-left)/6; var ty=o.offsetTop-(o.offsetTop-top)/6; o.style.left=tx +"px"; o.style.top=ty +"px"; chato.style.left=tx+15+"px"; chato.style.top=ty-20+"px"; imgv=setTimeout(function(){moveTo(o,left,top)},10); } hitFlag--; // www.qb5200.com } function randomMove(o){ if (gameStatus!=1) return; if (hitFlag<1){ moveTo(o,Math.random()*700,Math.random()*400+40); hitFlag=4; } } function getScore(){ if (gameStatus!=1) return; score++; alert('啊! 你抓到我了! 得分.'); document.getElementById("score").innerHTML="得分:"+score hitFlag=0; randomMove(this); } function refreshTime(){ var now = new Date(); var nowTime = now.getTime(); var leftTime=(3000-(parseInt((nowTime-startTime)/10)))/100; if (parseInt(leftTime) % 4 ==2 && delay==0) {sendChat();delay=1;setTimeout("delay=0",1000)} if (leftTime<=0){ leftTime=0; alert("抓囧人结束. 得分:"+score); gameStatus=0; clearInterval(ret); document.getElementById("restart").style.display="block"; } document.getElementById("time").innerHTML="剩余:"+leftTime+"秒"; } function sendChat(){ var n=parseInt(Math.random()*6); document.getElementById("chat").innerHTML=chatArr[n]; setTimeout("document.getElementById('chat').innerHTML=''",3000) } window.onload=function(){ chato=document.getElementById("chat"); restart(); } </script> [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行] 加载全部内容