diff --git a/src/main/java/pacmanGame/GameManager.java b/src/main/java/pacmanGame/GameManager.java index 9d79ebd..1e22a91 100644 --- a/src/main/java/pacmanGame/GameManager.java +++ b/src/main/java/pacmanGame/GameManager.java @@ -10,9 +10,13 @@ public class GameManager { public boolean ghostIsEdible = false; public boolean isPaused; public final int ghostCount = 10; + public int livesRemaining; + public int failedAttempts; public GameManager() { - setupGame(); + livesRemaining = 3; + failedAttempts = 0; + setupGame(); } public void setupGame(){ @@ -27,12 +31,26 @@ public class GameManager { for (int i = 0; i < ghosts.length; i++) { ghosts[i].spawn(); } + isPaused = false; } + public void handleGhostCollision() { + livesRemaining--; // Reduziere verbleibende leben um 1 + failedAttempts++; // Erh he die Anzahl der Fehlversuche + if(livesRemaining <= 0) { + gameOver(); //wenn Keine Leben mehr brig sind. + } + } + + public void gameOver() { + System.out.println("Das Spiel ist vorbei! Pech!!"); + } public void Update() { - visualizer.Update(); - if(time%5 == 0) { - player.Move(); + if(!isPaused) { + visualizer.Update(); + if(time%5 == 0) { + player.Move(); + } } if(time == 300) { spawnCherry(); diff --git a/src/main/java/pacmanGame/VisualizerPlainText.java b/src/main/java/pacmanGame/VisualizerPlainText.java index 330d7f5..d9c4595 100644 --- a/src/main/java/pacmanGame/VisualizerPlainText.java +++ b/src/main/java/pacmanGame/VisualizerPlainText.java @@ -47,29 +47,42 @@ public class VisualizerPlainText implements Visualizer { for(int y = 0; y < map.size.y; y++) { for(int x = 0; x < map.size.x; x++) { Cell cell = map.GetCell(new Vector2(x, map.size.y - 1 - y)); - boolean containsGhosts = false; - boolean containsPlayer = false; - for( int i = 0; i < gameManager.ghosts.length; i++) { - if(gameManager.ghosts[i].position.equals(cell.pos)) { - containsGhosts = true; - } - } - if(gameManager.player.position.equals(cell.pos)) { - containsPlayer = true; - } - if(containsPlayer) { - output += playerSprite; - } - else if(containsGhosts) { - output += ghostSprite; - } - else if (sprites.containsKey(cell.type)) { - - output += sprites.get(cell.type); + if(gameManager.isPaused && 5 < y && y <= 10){ + if(x == 0) { + if(y == 8){ + output += "Game Paused!"; + } + else { + output += ""; + } + } } else { - System.out.println("unknown type " + cell.type); + boolean containsGhosts = false; + boolean containsPlayer = false; + for( int i = 0; i < gameManager.ghosts.length; i++) { + if(gameManager.ghosts[i].position.equals(cell.pos)) { + containsGhosts = true; + } + } + if(gameManager.player.position.equals(cell.pos)) { + containsPlayer = true; + } + + if(containsPlayer) { + output += playerSprite; + } + else if(containsGhosts) { + output += ghostSprite; + } + else if (sprites.containsKey(cell.type)) { + + output += sprites.get(cell.type); + } + else { + System.out.println("unknown type" + cell.type); + } } } output += "\n";