纯JS之皮皮贪吃蛇之掉头就死了我也没办法之代码

先声明一下 有几个BUG 我自己也还在改。。 1.按相反的方向键会死 其实这个我的解决思路是 ASCII码相差为2的话本次操作无效。。但是不知道怎么搞的就是不行。。 2.。。。。。自己试试 懒得写了。 .map { width: 800px; height: 600px; position: relative; background-color: #F9F9F9; float: left; } .txt{ color: darkred; font-size: 14px; float: right; width: 300px; height: 600px; text-align: center; margin-right: 150px; } .txt span{ color: red; font-size: 24px; }
贪吃蛇(简易版)
难度1-5:推荐新手
难度6-9:正常水平
难度10:玩过了10格我请你吃饭,你定位置!
PS:开弓没有回头箭!
var level=parseInt(prompt("请输入挑战等级(1-10)")); var speed=0; switch (level){ case 1:speed=1200;break; case 2:speed=1000;break; case 3:speed=800;break; case 4:speed=600;break; case 5:speed=500;break; case 6:speed=400;break; case 7:speed=300;break; case 8:speed=200;break; case 9:speed=100;break; case 10:speed=50;break; default :alert("不认识字嘛!") } var map = document.querySelector(".map"); //封装 食物 ((function () { //存放小方块食物的数组 var eles = []; //小方块的构造函数 function Food(width, height, color, x, y) { this.width = width || 20; this.height = height || 20; this.color = color || "green"; this.x = x || 0; this.y = y || 0; this.ele = document.createElement("div"); //食物永远只能有一个 如果是在原型方法里面的话 就要加上del函数 } Food.prototype.show = function (map) { //设置变量存储 var div = this.ele; //设置样式 div.style.position = "absolute"; //子绝父相 div.style.width = this.width + "px"; //宽 div.style.height = this.height + "px"; //高 div.style.backgroundColor = this.color; //颜色 this.x = parseInt(Math.random() * (map.offsetWidth / this.width)) * this.width; this.y = parseInt(Math.random() * (map.offsetHeight / this.height)) * this.height; div.style.left = this.x + "px"; div.style.top = this.y + "px"; eles.push(div); map.appendChild(div); }; window.Food = Food; // function del(){ // for(var i=0;i
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值