【JS运动追逐】拓展游戏

演示网站:http://getlove.7ta.cn/article/5515576/136198


<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<body><style type="text/css">
.a{position:absolute;width:100px;height:100px;}
.b{left:300px;top:300px;url(http: //img142.poco.cn/mypoco/myphoto/20130729/13/5692517620130729134644050.png)}
.c{ url(http: //img142.poco.cn/mypoco/myphoto/20130729/13/5692517620130729134702061.png)}
.d{position:absolute;left:0;top:0;background:#effbbb;height:750px;width:100%; z-index:999}
#c,#d,#e,#f,#g,#h{display:none}</style>
<div class="d">
    <div class="a b" id="b">
        &nbsp;</div>
    <div class="a c" id="a">
        &nbsp;</div>
    <div class="a c" id="c">
        &nbsp;</div>
    <div class="a c" id="d">
        &nbsp;</div>
    <div class="a c" id="e">
        &nbsp;</div>
    <div class="a c" id="f">
        &nbsp;</div>
    <div class="a c" id="g">
        &nbsp;</div>
    <div class="a c" id="h">
        &nbsp;</div>
    <input id="showtime" style="color:#f00;width:200px;" type="text" value="0时0分0秒" /></div>
<script>alert('开始,别让粉色球追上,一共7关,加油哦');document. bunnyRun(){var b=document.getElementById('b');b.style.left=event.clientX-50+'px';b.style.top=event.clientY-50+'px';}
function r(speed,obj){var b=document.getElementById('b');if(obj.offsetLeft>b.offsetLeft)
obj.style.left=obj.offsetLeft- speed+'px';else if(obj.offsetLeft<b.offsetLeft)
obj.style.left=obj.offsetLeft+ speed+'px';if(obj.offsetTop>b.offsetTop)
obj.style.top=obj.offsetTop- speed+'px';else if(obj.offsetTop<b.offsetTop)
obj.style.top=obj.offsetTop+ speed+'px';if(Math.abs(obj.offsetLeft-b.offsetLeft)<speed&&Math.abs(obj.offsetTop-b.offsetTop)<speed)
{obj.style.left=b.offsetLeft+'px';obj.style.top=b.offsetTop+'px';}
if(Math.abs(obj.offsetLeft-b.offsetLeft)<speed&&Math.abs(obj.offsetTop-b.offsetTop)>speed)
obj.style.left=b.offsetLeft+'px';if(Math.abs(obj.offsetLeft-b.offsetLeft)>speed&&Math.abs(obj.offsetTop-b.offsetTop)<speed)
obj.style.top=b.offsetTop+'px';}
window. init(){var i=0,se=null,m=0,h=0,s=0,ss=1,level=1;function run(text,x){var timer=setInterval(function()
{if(i==1){clearInterval(timer);}
r(text,x);if(x.offsetTop==b.offsetTop&&x.offsetLeft==b.offsetLeft&&level<=6)
{clearInterval(timer);i=1;alert('级别'+level+'\n'+'失败,所用时间:'+'\n'+'\n'+t+'\n'+'\n'+'按F5重新挑战');clearInterval(se);}
else if(x.offsetTop==b.offsetTop&&x.offsetLeft==b.offsetLeft&&level==7)
{clearInterval(timer);i=1;alert('通关,所用时间:'+'\n'+'\n'+t+'\n'+'\n'+'您真的是太厉害了!'+level);clearInterval(se);}},1);}
var a=document.getElementById('a'),c=document.getElementById('c'),d=document.getElementById("d"),e=document.getElementById("e"),f=document.getElementById("f"),g=document.getElementById("g"),j=document.getElementById("h");se=setInterval(function second(){if((ss%100)==0){s+=1;ss=1;}
if(s>0&&(s%60)==0){m+=1;s=0;}
if(m>0&&(m%60)==0){h+=1;m=0;}
t=h+"时"+m+"分"+s+"秒"+ss+"毫秒";document.getElementById("showtime").value=t;ss+=1;if(s==5&&m==0&&h==0&&level==1)
{c.style.display='block';level=2;run(2,c)}
else if(s==15&&m==0&&h==0&&level==2)
{d.style.display='block';level=3;run(3,d)}
else if(s==20&&m==0&&h==0&&level==3)
{e.style.display='block';level=4;run(4,e)}
else if(s==30&&m==0&&h==0&&level==4)
{f.style.display='block';level=5;run(5,f)}
else if(s==40&&m==0&&h==0&&level==5)
{g.style.display='block';level=6;run(6,g)}
else if(s==50&&m==0&&h==0&&level==6)
{j.style.display='block';level=7;run(7,j)}},1)
run(1,a);}</script></body></html>


本文出自 “学我所用” 博客,谢绝转载!

你可能感兴趣的:(js,游戏,追逐)