|
@ -21,40 +21,39 @@ public class GameManager { |
|
|
setupGame(); |
|
|
setupGame(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void setupGame(){ |
|
|
|
|
|
time = 0; |
|
|
|
|
|
moveSpeed = 5; |
|
|
|
|
|
ghosts = new Ghost[ghostCount]; |
|
|
|
|
|
for (int i = 0; i < ghosts.length; i++) { |
|
|
|
|
|
ghosts[i] = new Ghost(this, i); |
|
|
|
|
|
} |
|
|
|
|
|
map = new Map(Map.mapClassic, this); |
|
|
|
|
|
visualizer = new VisualizerPlainTextUltra(this); |
|
|
|
|
|
player = new Player(this); |
|
|
|
|
|
player.Spawn(); |
|
|
|
|
|
for (int i = 0; i < ghosts.length; i++) { |
|
|
|
|
|
ghosts[i].spawn(); |
|
|
|
|
|
} |
|
|
|
|
|
isPaused = false; |
|
|
|
|
|
|
|
|
public void setupGame(){ |
|
|
|
|
|
time = 0; |
|
|
|
|
|
moveSpeed = 5; |
|
|
|
|
|
ghosts = new Ghost[ghostCount]; |
|
|
|
|
|
for (int i = 0; i < ghosts.length; i++) { |
|
|
|
|
|
ghosts[i] = new Ghost(this, i); |
|
|
|
|
|
} |
|
|
|
|
|
map = new Map(Map.mapClassic, this); |
|
|
|
|
|
visualizer = new VisualizerPlainTextUltra(this); |
|
|
|
|
|
player = new Player(this); |
|
|
|
|
|
player.Spawn(); |
|
|
|
|
|
for (int i = 0; i < ghosts.length; i++) { |
|
|
|
|
|
ghosts[i].spawn(); |
|
|
} |
|
|
} |
|
|
|
|
|
isPaused = false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public void handleGhostCollision() { |
|
|
|
|
|
livesRemaining--; // Reduziere verbleibende leben um 1 |
|
|
|
|
|
|
|
|
public void handleGhostCollision() { |
|
|
|
|
|
livesRemaining--; |
|
|
|
|
|
|
|
|
failedAttempts++; // Erh�he die Anzahl der Fehlversuche |
|
|
|
|
|
if(livesRemaining <= 0) { |
|
|
|
|
|
gameOver(); //wenn Keine Leben mehr �brig sind. |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
failedAttempts++; |
|
|
|
|
|
if(livesRemaining <= 0) { |
|
|
|
|
|
gameOver(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public void gameOver() { |
|
|
public void gameOver() { |
|
|
System.out.println("Das Spiel ist vorbei! Pech!!"); |
|
|
System.out.println("Das Spiel ist vorbei! Pech!!"); |
|
|
} |
|
|
} |
|
|
public void Update() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Update() { |
|
|
visualizer.Update(); |
|
|
visualizer.Update(); |
|
|
|
|
|
|
|
|
if(!isPaused) { |
|
|
if(!isPaused) { |
|
|
if(time%moveSpeed == 0) { |
|
|
if(time%moveSpeed == 0) { |
|
|
player.Move(); |
|
|
player.Move(); |
|
@ -64,7 +63,6 @@ public class GameManager { |
|
|
} |
|
|
} |
|
|
time++; |
|
|
time++; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if(time == 300) { |
|
|
if(time == 300) { |
|
|
spawnFruit(); |
|
|
spawnFruit(); |
|
|
} |
|
|
} |
|
@ -105,15 +103,11 @@ public class GameManager { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void teleportPlayer(String destination) { |
|
|
public void teleportPlayer(String destination) { |
|
|
|
|
|
|
|
|
player.position = map.findCellByString(destination).pos; |
|
|
player.position = map.findCellByString(destination).pos; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public boolean GhostPlayerColisionTest() { |
|
|
public boolean GhostPlayerColisionTest() { |
|
|
|
|
|
|
|
|
for(int i = 0; i < ghosts.length; i++) { |
|
|
for(int i = 0; i < ghosts.length; i++) { |
|
|
|
|
|
|
|
|
for(int x = 0; x < map.size.x; x++) { |
|
|
for(int x = 0; x < map.size.x; x++) { |
|
|
for(int y = 0; y < map.size.y; y++) { |
|
|
for(int y = 0; y < map.size.y; y++) { |
|
|
if(player.position.equals(ghosts[i].position)) |
|
|
if(player.position.equals(ghosts[i].position)) |
|
@ -137,12 +131,15 @@ public class GameManager { |
|
|
ghostIsEdible = false; |
|
|
ghostIsEdible = false; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void Pause() { |
|
|
public void Pause() { |
|
|
isPaused = true; |
|
|
isPaused = true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void Unpause() { |
|
|
public void Unpause() { |
|
|
isPaused = false; |
|
|
isPaused = false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void TogglePause() { |
|
|
public void TogglePause() { |
|
|
if(isPaused) { |
|
|
if(isPaused) { |
|
|
Unpause(); |
|
|
Unpause(); |
|
|