用Js写的贪吃蛇游戏
<!doctype html > < html > < head > < title >snake </ title > < script > function Snake(canvas){ this.canvas = canvas; this.length = 0; this.direction = 'down'; this.body = [], this.head = function(){ return this.length == 0 ? null : this.body[0]; }; this.isAlive = true; this.onDie = null; this.onEat = null; this.speed = 200; this.auto = null; this.turnLeft = function(){ if( this.direction == 'left' || this.direction == 'right'){ return; }else{ this.direction = 'left'; } }; this.turnRight = function(){ if( this.direction == 'left' || this.direction == 'right'){ return; }else{ this.direction =