diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..21359ba --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding//src/main/java/pacmanGame/VisualizerPlainTextUltra.java=UTF-8 diff --git a/src/main/java/pacmanGame/GameManager.java b/src/main/java/pacmanGame/GameManager.java index d04c4c6..77158d4 100644 --- a/src/main/java/pacmanGame/GameManager.java +++ b/src/main/java/pacmanGame/GameManager.java @@ -25,7 +25,7 @@ public class GameManager { ghosts[i] = new Ghost(this, i); } map = new Map(Map.mapClassic, this); - visualizer = new VisualizerPlainText(this); + visualizer = new VisualizerPlainTextUltra(this); player = new Player(this); player.Spawn(); for (int i = 0; i < ghosts.length; i++) { @@ -37,9 +37,9 @@ public class GameManager { public void handleGhostCollision() { livesRemaining--; // Reduziere verbleibende leben um 1 - failedAttempts++; // Erhφhe die Anzahl der Fehlversuche + failedAttempts++; // ErhοΏ½he die Anzahl der Fehlversuche if(livesRemaining <= 0) { - gameOver(); //wenn Keine Leben mehr όbrig sind. + gameOver(); //wenn Keine Leben mehr οΏ½brig sind. } } diff --git a/src/main/java/pacmanGame/Program.java b/src/main/java/pacmanGame/Program.java index da7b37c..1fce1a6 100644 --- a/src/main/java/pacmanGame/Program.java +++ b/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, 685); + frame.setSize(750, 950); textArea = new JTextArea("..."); textArea.setEditable(false); @@ -62,7 +62,7 @@ public class Program { textArea.setBackground(Color.black); textArea.setForeground(Color.blue); - Font font = new Font("Consolas", Font.PLAIN, 15); + Font font = new Font("Consolas", Font.PLAIN, 10); textArea.setFont(font); frame.add(textArea, BorderLayout.CENTER); diff --git a/src/main/java/pacmanGame/VisualizerPlainTextUltra.java b/src/main/java/pacmanGame/VisualizerPlainTextUltra.java new file mode 100644 index 0000000..5ad17d4 --- /dev/null +++ b/src/main/java/pacmanGame/VisualizerPlainTextUltra.java @@ -0,0 +1,208 @@ +package pacmanGame; + +import java.util.HashMap; + +public class VisualizerPlainTextUltra implements Visualizer { + + public boolean showScore = true; + + public final int playerAnimationTime = 2; + + private String output; + + public GameManager gameManager; + + public HashMap sprites = new HashMap(){{ + + this.put("empty", new String[] { + " ", + " " + }); + this.put("dot", new String[] { + " . ", + " " + }); + this.put("wall", new String[] { + "|''|", + "|__|" + }); + this.put("cherry", new String[] { + " /\\ ", + " 0O " + }); + }}; + + public final String[][] ghostSprites = { + { + "/--\\", + "~~~~" + }, + { + "/°°\\", + "~~~~" + }, + { + "/^^\\", + "~~~~" + }, + { + "/oo\\", + "~~~~" + }, + { + "/''\\", + "~~~~" + }, + { + "/**\\", + "~~~~" + }, + { + "/00\\", + "~~~~" + }, + { + "/++\\", + "~~~~" + }, + { + "/..\\", + "~~~~" + }, + { + "/§§\\", + "~~~~" } + }; + + public final String[] playerSprite = { + "β–„β–ˆβ–ˆβ–„", + "β–€β–ˆβ–ˆβ–€" + }; + + public final String[][] playerAltSprites = { + { + "β–„ β–„", + "β–€β–ˆβ–ˆβ–€" + }, + { + "β–„β–ˆβ–ˆβ–„", + "β–€ β–€" + }, + { + " β–€β–ˆβ–„", + " β–„β–ˆβ–€" + }, + { + "β–„β–ˆβ–€ ", + "β–€β–ˆβ–„ " + } + }; + + public VisualizerPlainTextUltra(GameManager gameManager) { + this.gameManager = gameManager; + } + + @Override + public Object GetOutput() { + return output; + } + + public void Update() { + + output = ""; + + if(showScore) { + output = "\nSCORE: " + gameManager.score + "\n\n"; + } + + int lineBufferSize = 2; + String[] lineBuffer = new String[lineBufferSize]; + + Map map = gameManager.map; + + for(int y = 0; y < map.size.y; y++) { + + if(gameManager.isPaused && y > 10 && y < 20) { + + + for(int i = 0; i < lineBufferSize; i++) { + if(y == 15 && i == 0) { + output += " Paused! \n"; + } + else{ + output += "\n"; + } + } + } + else { + for(int i = 0; i < lineBufferSize; i++) { + lineBuffer[i] = ""; + } + + 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; + int ghostIndex = -1; + + for( int i = 0; i < gameManager.ghosts.length; i++) { + if(gameManager.ghosts[i].position.equals(cell.pos)) { + containsGhosts = true; + ghostIndex = i; + } + } + if(gameManager.player.position.equals(cell.pos)) { + containsPlayer = true; + } + + if(containsPlayer) { + if((gameManager.time / playerAnimationTime) % 2 == 0) { + int directionIndex = 0; + + if(gameManager.player.direction.equals(new Vector2(0, 1))) { + directionIndex = 0; + } + else if(gameManager.player.direction.equals(new Vector2(0, -1))) { + directionIndex = 1; + } + else if(gameManager.player.direction.equals(new Vector2(-1, 0))) { + directionIndex = 2; + } + else if(gameManager.player.direction.equals(new Vector2(1, 0))) { + directionIndex = 3; + } + + lineBuffer = AttachToBuffer(lineBuffer, playerAltSprites[directionIndex]); + } + else { + lineBuffer = AttachToBuffer(lineBuffer, playerSprite); + } + } + else if(containsGhosts) { + lineBuffer = AttachToBuffer(lineBuffer, ghostSprites[ghostIndex]); + } + else if (sprites.containsKey(cell.type)) { + + lineBuffer = AttachToBuffer(lineBuffer, sprites.get(cell.type)); + } + else { + System.out.println("unknown type" + cell.type); + } + } + + for(int i = 0; i < lineBufferSize; i++) { + output += lineBuffer[i] + "\n"; + } + } + } + } + + public String[] AttachToBuffer(String[] buffer, String[] sprite) { + for(int i = 0; i < buffer.length; i++) { + buffer[i] += sprite[i]; + } + return buffer; + } + +} diff --git a/src/test/java/pacmanTests/GameManagerTest.java b/src/test/java/pacmanTests/GameManagerTest.java index 099d5f7..31380d4 100644 --- a/src/test/java/pacmanTests/GameManagerTest.java +++ b/src/test/java/pacmanTests/GameManagerTest.java @@ -34,6 +34,7 @@ class GameManagerTest { // arrange GameManager gameManager = new GameManager(); + gameManager.visualizer = new VisualizerPlainText(gameManager); VisualizerPlainText vpt = (VisualizerPlainText) gameManager.visualizer; // act