Browse Source

Merge branch 'main' of https://gitlab.cs.hs-fulda.de/fdai7012/pacmayham

remotes/origin/playerRefactoring
fdai7753 11 months ago
parent
commit
30fa83303a
  1. 18
      src/main/java/pacmanGame/GameManager.java
  2. 15
      src/main/java/pacmanGame/VisualizerPlainText.java

18
src/main/java/pacmanGame/GameManager.java

@ -10,8 +10,12 @@ public class GameManager {
public boolean ghostIsEdible = false; public boolean ghostIsEdible = false;
public boolean isPaused; public boolean isPaused;
public final int ghostCount = 10; public final int ghostCount = 10;
public int livesRemaining;
public int failedAttempts;
public GameManager() { public GameManager() {
livesRemaining = 3;
failedAttempts = 0;
setupGame(); setupGame();
} }
@ -27,13 +31,27 @@ public class GameManager {
for (int i = 0; i < ghosts.length; i++) { for (int i = 0; i < ghosts.length; i++) {
ghosts[i].spawn(); 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() { public void Update() {
if(!isPaused) {
visualizer.Update(); visualizer.Update();
if(time%5 == 0) { if(time%5 == 0) {
player.Move(); player.Move();
} }
}
if(time == 300) { if(time == 300) {
spawnCherry(); spawnCherry();
} }

15
src/main/java/pacmanGame/VisualizerPlainText.java

@ -47,6 +47,18 @@ public class VisualizerPlainText implements Visualizer {
for(int y = 0; y < map.size.y; y++) { for(int y = 0; y < map.size.y; y++) {
for(int x = 0; x < map.size.x; x++) { for(int x = 0; x < map.size.x; x++) {
Cell cell = map.GetCell(new Vector2(x, map.size.y - 1 - y)); Cell cell = map.GetCell(new Vector2(x, map.size.y - 1 - y));
if(gameManager.isPaused && 5 < y && y <= 10){
if(x == 0) {
if(y == 8){
output += "Game Paused!";
}
else {
output += "";
}
}
}
else {
boolean containsGhosts = false; boolean containsGhosts = false;
boolean containsPlayer = false; boolean containsPlayer = false;
for( int i = 0; i < gameManager.ghosts.length; i++) { for( int i = 0; i < gameManager.ghosts.length; i++) {
@ -69,7 +81,8 @@ public class VisualizerPlainText implements Visualizer {
output += sprites.get(cell.type); output += sprites.get(cell.type);
} }
else { else {
System.out.println("unknown type " + cell.type);
System.out.println("unknown type" + cell.type);
}
} }
} }
output += "\n"; output += "\n";

Loading…
Cancel
Save