From 9847527ba885e24052de6b7840fb291542fbc62e Mon Sep 17 00:00:00 2001 From: fdai2751 Date: Sun, 4 Feb 2024 17:47:32 +0100 Subject: [PATCH 1/5] added score to plaintextvisualizer --- src/main/java/pacmanGame/Program.java | 2 +- src/main/java/pacmanGame/VisualizerPlainText.java | 5 ++++- src/test/java/pacmanTests/VisualizerPlainTextTest.java | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/pacmanGame/Program.java b/src/main/java/pacmanGame/Program.java index 734bfc4..e62fa28 100644 --- a/src/main/java/pacmanGame/Program.java +++ b/src/main/java/pacmanGame/Program.java @@ -52,7 +52,7 @@ public class Program { frame = new JFrame("PacmaaaAAAYYYHAAAaaam"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - frame.setSize(500, 665); + frame.setSize(500, 685); textArea = new JTextArea("..."); textArea.setEditable(false); diff --git a/src/main/java/pacmanGame/VisualizerPlainText.java b/src/main/java/pacmanGame/VisualizerPlainText.java index 8559f95..7591711 100644 --- a/src/main/java/pacmanGame/VisualizerPlainText.java +++ b/src/main/java/pacmanGame/VisualizerPlainText.java @@ -3,7 +3,7 @@ package pacmanGame; import java.util.HashMap; public class VisualizerPlainText implements Visualizer { - + public boolean showScore = true; private String output; public final GameManager gameManager; @@ -28,6 +28,9 @@ public class VisualizerPlainText implements Visualizer { @Override public void Update() { output = ""; + if(showScore) { + output = "score: " + gameManager.score + "\n"; + } Map map = gameManager.map; for(int y = 0; y < map.size.y; y++) { diff --git a/src/test/java/pacmanTests/VisualizerPlainTextTest.java b/src/test/java/pacmanTests/VisualizerPlainTextTest.java index e73225c..7227f86 100644 --- a/src/test/java/pacmanTests/VisualizerPlainTextTest.java +++ b/src/test/java/pacmanTests/VisualizerPlainTextTest.java @@ -22,7 +22,7 @@ class VisualizerPlainTextTest { GameManager gameManager = new GameManager(); gameManager.map = new Map(mapTest, gameManager); VisualizerPlainText vpt = new VisualizerPlainText(gameManager); - + vpt.showScore = false; String expected = "" + "[]. []\n" + " . \n" @@ -46,6 +46,7 @@ class VisualizerPlainTextTest { GameManager gameManager = new GameManager(); gameManager.map = new Map(mapTest, gameManager); VisualizerPlainText vpt = new VisualizerPlainText(gameManager); + vpt.showScore = false; gameManager.ghosts[0].position = new Vector2(1, 1); From 25602d6ff23c459be0a1b723ef049ccc6671febf Mon Sep 17 00:00:00 2001 From: fdai2751 Date: Sun, 4 Feb 2024 18:07:15 +0100 Subject: [PATCH 2/5] added pause boolean to gameManager --- src/main/java/pacmanGame/GameManager.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/pacmanGame/GameManager.java b/src/main/java/pacmanGame/GameManager.java index 818d0ed..2a1a3b2 100644 --- a/src/main/java/pacmanGame/GameManager.java +++ b/src/main/java/pacmanGame/GameManager.java @@ -7,6 +7,7 @@ public class GameManager { public Visualizer visualizer; public Player player; public int score = 0; + public boolean isPaused; public GameManager() { setupGame(); @@ -21,6 +22,8 @@ public class GameManager { for(int i = 0; i < ghosts.length; i++) { ghosts[i] = new Ghost(this); } + isPaused = false; + } public void Update() { @@ -59,4 +62,5 @@ public class GameManager { } return false; } + } From ff7075f7e28fe1f27e2458600dfeb3230ce7adb8 Mon Sep 17 00:00:00 2001 From: fdai2751 Date: Sun, 4 Feb 2024 18:12:10 +0100 Subject: [PATCH 3/5] added Pause fontion into gameManager --- src/main/java/pacmanGame/GameManager.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/pacmanGame/GameManager.java b/src/main/java/pacmanGame/GameManager.java index 2a1a3b2..af640fd 100644 --- a/src/main/java/pacmanGame/GameManager.java +++ b/src/main/java/pacmanGame/GameManager.java @@ -62,5 +62,9 @@ public class GameManager { } return false; } + public void Pause() { + isPaused = true; + + } } From a4bdc9073ea5201a4bd4d60f3f5c9cd0c77b4266 Mon Sep 17 00:00:00 2001 From: fdai2751 Date: Sun, 4 Feb 2024 18:17:32 +0100 Subject: [PATCH 4/5] added the Unpause fonction into gameManager --- src/main/java/pacmanGame/GameManager.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/pacmanGame/GameManager.java b/src/main/java/pacmanGame/GameManager.java index af640fd..2b6e210 100644 --- a/src/main/java/pacmanGame/GameManager.java +++ b/src/main/java/pacmanGame/GameManager.java @@ -64,7 +64,9 @@ public class GameManager { } public void Pause() { isPaused = true; - + } + public void Unpause() { + isPaused = false; } } From 49c14a486ed4a728edfc5c51f351cbf2487d1d87 Mon Sep 17 00:00:00 2001 From: fdai2751 Date: Sun, 4 Feb 2024 18:39:51 +0100 Subject: [PATCH 5/5] added the togglePause fonction in to gameManager and changed the pause instruction on ESC --- src/main/java/pacmanGame/GameManager.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/pacmanGame/GameManager.java b/src/main/java/pacmanGame/GameManager.java index 2b6e210..ff8c542 100644 --- a/src/main/java/pacmanGame/GameManager.java +++ b/src/main/java/pacmanGame/GameManager.java @@ -35,8 +35,8 @@ public class GameManager { } public void ProcessInput(char inputChar) { - if(inputChar == 27) { - //todo: escape key pauses game + if(inputChar == 27) {// 27 = ESC + TogglePause(); } else if (inputChar == 'w' || inputChar == 's' || inputChar == 'd' || inputChar == 'a') { player.processInput(inputChar); @@ -68,5 +68,12 @@ public class GameManager { public void Unpause() { isPaused = false; } - + public void TogglePause() { + if(isPaused) { + Unpause(); + } + else { + Pause(); + } + } }