Browse Source

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

remotes/origin/ghostsbehaviour
fdai7910 11 months ago
parent
commit
f0ed90a72f
  1. 23
      src/main/java/pacmanGame/GameManager.java
  2. 2
      src/main/java/pacmanGame/Program.java
  3. 8
      src/main/java/pacmanGame/VisualizerPlainText.java
  4. 3
      src/test/java/pacmanTests/VisualizerPlainTextTest.java

23
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();
}
}
}

2
src/main/java/pacmanGame/Program.java

@ -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);

8
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++) {

3
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);

Loading…
Cancel
Save