From cc83727a1da6f81307175433f7b3cb4fb4d9ca65 Mon Sep 17 00:00:00 2001 From: Justin Senn Date: Mon, 6 Feb 2023 22:14:13 +0100 Subject: [PATCH] update --- src/main/java/Snake/Controller.java | 37 +++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/main/java/Snake/Controller.java b/src/main/java/Snake/Controller.java index 2c5ec16..3ae5372 100644 --- a/src/main/java/Snake/Controller.java +++ b/src/main/java/Snake/Controller.java @@ -2,6 +2,7 @@ package Snake; import javax.swing.*; +import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -21,6 +22,42 @@ public class Controller { private GameState gameState; private int score; + Controller(Window window, Snake snakeModel, SnakeView snakeView, Apple appleModel, AppleView appleView) + { + gameView = window.getGameView(); + this.snakeModel = snakeModel; + this.snakeView = snakeView; + this.appleModel = appleModel; + this.appleView = appleView; + + scoreView = new TextView("Scores: 9", new Point(15, 15)); + messageView = new TextView("Click 'Start Game' to Begin . (W-up, S-down, A-left, D-Right)", + new Point(gameView.getWidth()/2, gameView.getHeight() - 15)); + + scoreView.setAnchor(TextView.AnchorType.Left); + + gameView.addView(scoreView); + gameView.addView(messageView); + + initializeInputHandling(); + addButtonActionListeners(window); + + timer = new Timer(10, new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + timerTick(); + } + }); + + gameState = GameState.Paused; + inputHandled = true; + score = 0; + + selectApplesPosition(); + updateSnakeViewPosition(); + } private void initializeInputHandling() { final int CONDITION = JComponent.WHEN_IN_FOCUSED_WINDOW;