欢迎光临
我们一直在努力

html5小游戏源码-扫雷

<!doctype html> <html> <head> <meta name="author" content="苏道涵"/> <meta name="keywords" content="扫雷,html5小游戏"/> <meta name="description" content="经典扫雷小游戏"/> <meta http-equiv="content-Type" content="text/html;charset=gb2312"/> <title>扫雷小游戏</title> <style> div.yangshi1{ font-size:25px; margin-bottom:30px; text-align:center;} div.yangshi2{ width:100px; height:50px; border-style:solid; text-align:center; float:right; } </style> </head> <body> <h1 align=center>扫雷小游戏</h1> <canvas width=1000px height=400px style="float:left" id="g"></canvas> <div class="yangshi1" onclick="start()">开始</div> <div class="yangshi1">计时</div> <div id="time" class="yangshi2"></div> <script> var tArray=new Array(); for(var k=0;k<40;k++){ tArray[k]=new Array(); for(var j=0;j<16;j++){ tArray[k][j]=0; } } var foody; var foodx; for(var i=0;i<100;i++){ foody=Math.ceil(Math.random()*16-1); foodx=Math.ceil(Math.random()*40-1); while(foodx==-1||foody==-1||tArray[foodx][foody]==-1){ foody=Math.ceil(Math.random()*16-1); foodx=Math.ceil(Math.random()*40-1); } tArray[foodx][foody]=-1; for(var t=-1;t<2;t++){ for(var k=-1;k<2;k++){ if((foodx+t)!=-1&amp;&(foody+k)!=-1&&(foodx+t)!=40&&(foody+k)!=16&&tArray [foodx+t][foody+k]!=-1 ){ tArray[foodx+t][foody+k]++; } } } } var time=0; function start(){ document.onclick=function(event){ var e=event||window.event; var clickX=((e.screenX-50)/14.5*16)>>5; var clickY=((e.screenY-195)/14.5*16)>>5; var name=1 context.fillStyle="white"; if(tArray[clickX][clickY]==-1){ window.alert("gameover"); window.location.reload(); } else { context.fillRect(clickX*25,clickY*25,25,25); context.font="20px Georgia"; context.fillStyle="black"; context.fillText(tArray[clickX][clickY],clickX*25+10,clickY*25+15); } } window.setInterval(timing,1000); } function timing(){ time++; document.getElementById("time").innerHTML=time; } var drawing=document.getElementById("g"); if(drawing.getContext){ var context=drawing.getContext("2d"); context.fillStyle="gray"; context.fillRect(0,0,1000,400); context.fillStyle="black"; context.beginPath(); context.lineWidth=2; for(var i=25;i<=400;i=i+25){ context.moveTo(0,i); context.lineTo(1000,i); } for(var t=25;t<=1000;t=t+25){ context.moveTo(t,0); context.lineTo(t,400); } context.stroke(); } </script> </body> </html> 

  • 海报
海报图正在生成中...
赞(0) 打赏
声明:
1、本博客不从事任何主机及服务器租赁业务,不参与任何交易,也绝非中介。博客内容仅记录博主个人感兴趣的服务器测评结果及一些服务器相关的优惠活动,信息均摘自网络或来自服务商主动提供;所以对本博客提及的内容不作直接、间接、法定、约定的保证,博客内容也不具备任何参考价值及引导作用,访问者需自行甄别。
2、访问本博客请务必遵守有关互联网的相关法律、规定与规则;不能利用本博客所提及的内容从事任何违法、违规操作;否则造成的一切后果由访问者自行承担。
3、未成年人及不能独立承担法律责任的个人及群体请勿访问本博客。
4、一旦您访问本博客,即表示您已经知晓并接受了以上声明通告。
文章名称:《html5小游戏源码-扫雷》
文章链接:https://www.456zj.com/36898.html
本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址