1
<p id='show1'>None</p><p id='show'>None</p>
<canvas id='mcvs' width='300' height='300'></canvas>
<script>var ctx=mcvs.getContext('2d')
var fgs=30,col=10,row=10,siv=null,page='main',gste='pause',jj=[4*30,4.5*30,5*30,5.5*30,6*30],jjrn=0
var me={soe:0,ste:'stand',dir:'u',pos:[60,270],sd:1,sdn:0.8}
var block={pos:[150,270]}
var bks=[{pos:[270,270]}]
function gog(){show.innerHTML=me.pos
me.ste='fly';me.pos[1]-=me.sd;me.sd-=0.9;if(me.pos[1]+30>300){me.ste='stand';me.pos[1]=270}
for(let a=0;a<bks.length;a++){let bk=bks[a];if(bk.pos[0]+fgs<=0){me.soe++;bks.splice(a,1);jjrn=Math.floor(Math.random()*jj.length)}else{bk.pos[0]-=5}}
for(let a=0;a<bks.length;a++){let bk=bks[a];if(iscoletn(me,bk)){gover()}}
if(bks.length<3){bks.push({pos:[bks[bks.length-1].pos[0]+jj[jjrn],270]})}
gdisupdate();if(gste=='over'){gover()} }
function gdisupdate(){show.innerHTML=me.soe
ctx.clearRect(0,0,300,300);dboard();dgame()
ctx.strokeRect(me.pos[0],me.pos[1],fgs,fgs)
for(let a=0;a<bks.length;a++){let bk=bks[a];ctx.strokeStyle='green';ctx.strokeRect(bk.pos[0],bk.pos[1],fgs,fgs)}
}
function gstart(){if(gste=='pause'){gste='gaming';siv=setInterval('gog()',50)}}
function gpause(){gste='pause';clearInterval(siv)}
function dboard(){for(let a=0;a<col*row;a++){let x=a%col,y=(a-x)/col;ctx.strokeStyle='#ddd';ctx.strokeRect(x*fgs,y*fgs,fgs,fgs)}}
function gover(){gste='over';page='gover';clearInterval(siv);dgover();}
function dmain(){ctx.clearRect(0,0,300,300,);dboard();ctx.strokeStyle='black';ctx.strokeText('开始游戏',3*fgs,4*fgs);ctx.strokeRect(3*fgs,4*fgs,3*fgs,1*fgs)}
dboard();dmain()
function dgame(){ctx.clearRect(0,0,300,300,);dboard();ctx.strokeStyle='black';ctx.strokeText('暂停',9*fgs,9*fgs);ctx.strokeRect(9*fgs,9*fgs,1*fgs,1*fgs)}
function dpause(){ctx.clearRect(0,0,300,300,);dboard();ctx.strokeStyle='orange';ctx.strokeText('主菜单',5*fgs,9*fgs);ctx.strokeRect(5*fgs,9*fgs,1*fgs,1*fgs);ctx.strokeText('继续',2*fgs,9*fgs);ctx.strokeRect(2*fgs,9*fgs,1*fgs,1*fgs)}
function dgover(){ctx.clearRect(0,0,300,300,);dboard();ctx.strokeStyle='red';ctx.strokeText('主菜单',5*fgs,9*fgs);ctx.strokeRect(5*fgs,9*fgs,1*fgs,1*fgs);ctx.strokeText('重来',2*fgs,9*fgs);ctx.strokeRect(2*fgs,9*fgs,1*fgs,1*fgs)}
mcvs.onclick=function(e){
let x=e.layerX,y=e.layerY;x=(x-x%fgs)/fgs;y=(y-y%fgs)/fgs
if(page=='main'){ if(y==4&&x>=3&&x<=5){page='game';dgame();gstart()}
}else if(page=='game'){ if(y==9&&x==9){page='pause';dpause();gpause()}else{gctl()}
}else if(page=='pause'){ if(y==9&&x==5){greset();page='main';dmain()};if(y==9&&x==2){page='game';dgame();gstart()}
}else if(page=='gover'){if(y==9&&x==5){greset();page='main';dmain()};if(y==9&&x==2){page='game';greset();dgame();gstart()} }
}
function gctl(){if(me.pos[1]>0&&me.ste=='stand'){me.sd=10;me.dir='u';/*me.pos[1]-=30;me.sd=1;me.sdn=-me.sdn*/};if(me.pos[1]<0){me.pos[1]=0}}
function iscoletn(a,b){let ax=a.pos[0],ay=a.pos[1],bx=b.pos[0],by=b.pos[1];if(ay+fgs>=by&&ay<=by+fgs&&ax+30>=bx&&ax<=bx+fgs){return true};return false}
function greset(){gste='pause';bks=[{pos:[270,270]}];me={soe:0,dir:'d',pos:[60,270],sd:1,sdn:0.8};block={pos:[150,270]}}
</script>