这个贪吃蛇的思路来源于网上的一位后台程序员的作品。所以作为一个思想剽窃者我也分享我的代码。
首先建两个对象snake和组成snake的node对象:
function Snake(){ this.direction = "down"; this.operate = []; this.head = null; this.end = null; this.status = "live"; this.speed=500; }
function Node(rowNum,colNum){ //当前节点所必须的属性 this.row = rowNum; this.col = colNum; this.prevNode = null; this.nextNode = null; }
对象的方法放在原型里,以免实例化而重复方法。
如果有什么BUG或者用户体验的问题可以评论反馈给我,我尽量修改。
有关于速度的问题我已经发现问题了,稍后解决。可能页面不是很好看。我也会在以后的更新中修改样式。
demo地址:http://cowll.com/demo/snake.html
如果实在没什么好留言的可以把玩的最高纪录评论到文章后面,来了看了总得留下点什么吧。