From af93a2a3189904721e6b3f2d11730a2586f31041 Mon Sep 17 00:00:00 2001
From: Justin Senn <justin.senn@informatik.hs-fulda.de>
Date: Mon, 6 Feb 2023 22:11:42 +0100
Subject: [PATCH] update

---
 src/main/java/Snake/Controller.java | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

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
     {