贪吃蛇
来源:互联网 发布:linux防御软件 编辑:程序博客网 时间:2024/04/30 09:10
贪吃蛇的简易代码<html> <body> <canvas id="can" width="400" height="400" style="background:Black"></canvas> <script> var sn=[42,41],dz=43,fx=1,n,ctx=document.getElementById("can").getContext("2d"); function draw(t,c){ ctx.fillStyle=c; ctx.fillRect(t%20*20+1,~~(t/20)*20+1,18,18); } document.onkeydown=function(e){fx=sn[1]-sn[0]==(n=[-1,-20,1,20][(e||event).keyCode-37]||fx)?fx:n}; !function(){ sn.unshift(n=sn[0]+fx); if(sn.indexOf(n,1)>0 || n<0||n>399||fx==1&&n%20==0||fx==-1&&n%20==19){ return alert("GAME OVER"); refesh(); } draw(n,"Lime"); if(n==dz){ while(sn.indexOf(dz=~~(Math.random()*400))>=0); draw(dz,"Yellow"); }else{ draw(sn.pop(),"Black"); } setTimeout(arguments.callee,130); }(); function refesh(){ location.reload(); } </script> </body> </html>
0 0
- 贪吃蛇
- 贪吃蛇
- 贪吃蛇
- 贪吃蛇
- 贪吃蛇
- 贪吃蛇
- 贪吃蛇
- 贪吃蛇
- 贪吃蛇
- 贪吃蛇
- 贪吃蛇
- 贪吃蛇
- 贪吃蛇
- 贪吃蛇
- 贪吃蛇
- 贪吃蛇
- 贪吃蛇
- 贪吃蛇
- ubuntu 无法登陆桌面问题
- css中的度量单位
- css实现图片等比例缩小不变形
- 读深入理解Linux内核 (第4章 中断和例外)
- 最近的总结
- 贪吃蛇
- Java 多线程(二) 线程的实现
- java xml操作实例
- ios developer tiny share-20160916
- 计算分数精确值
- pyspark中使用categoricalFeaturesInfo来标记分类型变量
- CSS表格与列表
- C#的第一个小程序
- hdoj 1018 Big Number(数学)