java课程设计-贪吃蛇代码(2)
发布时间:2021-06-06
发布时间:2021-06-06
sta = "Paused";
break;
case Snake.GAMEOVER:
sta = "GameOver";
break;
}
statusLabel.setText(sta);
scoreLabel.setText("" + snake.score);
try {
Thread.sleep(100);
} catch (Exception e) {
}
}
}
private JLabel scoreLabel;
private JLabel statusLabel;
private Snake snake;
}
// ----------蛇运动以及记录分数的线程
class SnakeRunnable implements Runnable {
public SnakeRunnable(Snake snake, Component component) {
this.snake = snake;
ponent = component;
}
public void run() {
while (true) {
try {
snake.move();
component.repaint();
Thread.sleep(snake.speed);
} catch (Exception e) {
}
}
}
private Snake snake;
private Component component;
}
class Snake {
boolean isRun; // ---------是否运动中
上一篇:硬笔书法 第一课时
下一篇:《聪明人和傻子和奴才》教学设计