diff --git a/src/main/java/pacmanGame/GameManager.java b/src/main/java/pacmanGame/GameManager.java index 6c60efb..236dd2c 100644 --- a/src/main/java/pacmanGame/GameManager.java +++ b/src/main/java/pacmanGame/GameManager.java @@ -7,7 +7,8 @@ public class GameManager { public Visualizer visualizer; public Player player; public int score = 0; - public Boolean ghostIsEdible = false; + public boolean ghostIsEdible = false; + public boolean isPaused; public GameManager() { setupGame(); @@ -22,6 +23,8 @@ public class GameManager { for(int i = 0; i < ghosts.length; i++) { ghosts[i] = new Ghost(this); } + isPaused = false; + } public void Update() { @@ -47,8 +50,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); @@ -85,4 +88,18 @@ public class GameManager { ghostIsEdible = false; } } + public void Pause() { + isPaused = true; + } + public void Unpause() { + isPaused = false; + } + public void TogglePause() { + if(isPaused) { + Unpause(); + } + else { + Pause(); + } + } } diff --git a/src/main/java/pacmanGame/Program.java b/src/main/java/pacmanGame/Program.java index d835fa4..da7b37c 100644 --- a/src/main/java/pacmanGame/Program.java +++ b/src/main/java/pacmanGame/Program.java @@ -22,7 +22,7 @@ public class Program { gameManager = new GameManager(); GameLoop(); - + } public void GameLoop() { @@ -54,7 +54,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 37f7768..9e71590 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,7 +28,11 @@ public class VisualizerPlainText implements Visualizer { @Override public void Update() { - output = "Score: " + gameManager.score + "\n"; + 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);