diff --git a/src/main/java/Snake/Controller.java b/src/main/java/Snake/Controller.java index 625ed14..2c5ec16 100644 --- a/src/main/java/Snake/Controller.java +++ b/src/main/java/Snake/Controller.java @@ -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 {