|
|
@ -103,6 +103,31 @@ public class Controller { |
|
|
|
snakeView.setPositions(snakeModel.getBodySegments()); |
|
|
|
} |
|
|
|
|
|
|
|
private void timerTick() |
|
|
|
{ |
|
|
|
snakeModel.update(); |
|
|
|
inputHandled = true; |
|
|
|
checkIfAppleWasEaten(); |
|
|
|
if(snakeModel.isSelfColliding()) |
|
|
|
{ |
|
|
|
messageView.setText("You Lose! Click 'Start Game' to play agaiin."); |
|
|
|
messageView.setVisibility(true); |
|
|
|
gameState = GameState.PlayerLosed; |
|
|
|
timer.stop(); |
|
|
|
} |
|
|
|
updateSnakeViewPosition(); |
|
|
|
gameView.repaint(); |
|
|
|
} |
|
|
|
private void checkIfAppleWasEaten() |
|
|
|
{ |
|
|
|
if(appleModel.getPosition().equals(snakeModel.getHeadPosition())) |
|
|
|
{ |
|
|
|
score += 1; |
|
|
|
scoreView.setText("Score: " + Integer.toString(score)); |
|
|
|
snakeModel.grow(); |
|
|
|
selectApplesPosition(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private class MoveAction extends AbstractAction |
|
|
|
{ |
|
|
|