34 lines
746 B
Java
34 lines
746 B
Java
import java.util.Timer;
|
|
import java.util.TimerTask;
|
|
|
|
public class GameOverTask extends TimerTask {
|
|
|
|
private Timer parent;
|
|
private SnakePanel game;
|
|
private int i;
|
|
|
|
public GameOverTask(SnakePanel game, Timer parent) {
|
|
this.game = game;
|
|
this.parent = parent;
|
|
i = 0;
|
|
}
|
|
|
|
@Override
|
|
public void run() {
|
|
for (int x = i; x >= 0; x--) {
|
|
int y = i - x;
|
|
if (x < game.sizeX && y < game.sizeY) {
|
|
game.getGrid()[x][y].setType(CellType.VOID);
|
|
|
|
if (x == game.sizeX - 1 && y == game.sizeY - 1) {
|
|
parent.cancel();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
i++;
|
|
game.repaint();
|
|
}
|
|
}
|