java课程设计-贪吃蛇代码(8)
发布时间:2021-06-06
发布时间:2021-06-06
if (e.getSource() == fastItem) {
snake.speed = Snake.FAST;
speedLabel.setText("Fast");
}
}
};
pauseItem.addActionListener(l);
beginItem.addActionListener(l);
newItem.addActionListener(l);
aboutItem.addActionListener(l);
slowItem.addActionListener(l);
midItem.addActionListener(l);
fastItem.addActionListener(l);
addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
switch (e.getKeyCode()) {
// ------------方向键改变蛇运行方向
case KeyEvent.VK_DOWN://
snake.changeDerection(Snake.DOWN); break;
case KeyEvent.VK_UP://
snake.changeDerection(Snake.UP); break;
case KeyEvent.VK_LEFT://
snake.changeDerection(Snake.LEFT); break;
case KeyEvent.VK_RIGHT://
snake.changeDerection(Snake.RIGHT); break;
// 空格键,游戏暂停或继续
case KeyEvent.VK_SPACE://
if (snake.isRun == true) {
snake.isRun = false;
snake.status = Snake.PAUSED; break;
}
if (snake.isRun == false) {
snake.isRun = true;
snake.status = Snake.RUNNING; break;
}
}
}
上一篇:硬笔书法 第一课时
下一篇:《聪明人和傻子和奴才》教学设计