fdai7910 11 months ago
parent
commit
c0ef968fc7
  1. 17
      src/main/java/pacmanGame/GameManager.java
  2. 11
      src/main/java/pacmanGame/Program.java

17
src/main/java/pacmanGame/GameManager.java

@ -39,11 +39,11 @@ public class GameManager {
} }
public void handleGhostCollision() { public void handleGhostCollision() {
livesRemaining--; // Reduziere verbleibende leben um 1
livesRemaining--;
failedAttempts++; // Erhhe die Anzahl der Fehlversuche
failedAttempts++;
if(livesRemaining <= 0) { if(livesRemaining <= 0) {
gameOver(); //wenn Keine Leben mehr brig sind.
gameOver();
} }
} }
@ -51,10 +51,9 @@ public class GameManager {
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();

11
src/main/java/pacmanGame/Program.java

@ -20,21 +20,17 @@ public class Program {
createAndShowGUI(); createAndShowGUI();
gameManager = new GameManager(); gameManager = new GameManager();
gameLoop(); gameLoop();
} }
public void gameLoop() { public void gameLoop() {
boolean running = true; boolean running = true;
while(running) { while(running) {
forwardInputToGameManager(); forwardInputToGameManager();
gameManager.Update(); gameManager.Update();
textArea.setText((String)gameManager.visualizer.GetOutput()); textArea.setText((String)gameManager.visualizer.GetOutput());
try { try {
Thread.sleep(100); Thread.sleep(100);
} catch (InterruptedException e) {} } catch (InterruptedException e) {}
@ -53,22 +49,17 @@ public class Program {
public void createAndShowGUI() { public void createAndShowGUI() {
frame = new JFrame("PacmaaaAAAYYYHAAAaaam"); frame = new JFrame("PacmaaaAAAYYYHAAAaaam");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(750, 950); frame.setSize(750, 950);
textArea = new JTextArea("..."); textArea = new JTextArea("...");
textArea.setEditable(false); textArea.setEditable(false);
textArea.setFocusable(false); textArea.setFocusable(false);
textArea.setBackground(Color.black); textArea.setBackground(Color.black);
textArea.setForeground(Color.yellow); textArea.setForeground(Color.yellow);
Font font = new Font("Consolas", Font.PLAIN, 10); Font font = new Font("Consolas", Font.PLAIN, 10);
textArea.setFont(font); textArea.setFont(font);
frame.add(textArea, BorderLayout.CENTER); frame.add(textArea, BorderLayout.CENTER);
frame.setLocationRelativeTo(null); frame.setLocationRelativeTo(null);
frame.setVisible(true); frame.setVisible(true);
input = new MyKeyListener(); input = new MyKeyListener();
frame.addKeyListener(input); frame.addKeyListener(input);
} }

Loading…
Cancel
Save