var snakeBox = document.getElementById("snake_box"); // 创建游戏对象 var snakeGame = new SnakeGame(snakeBox, { speed: speedSelect.value, // 吃到食物时的回调 eated: function() { gradeEle.innerHTML = this.getCount(); }, // 死亡时的回调 onDie: function() { alert("Game Over!"); } }); // 开始游戏 snakeGame.start();