diff --git a/src/main/java/pacmanGame/VisualizerPlainTextUltra.java b/src/main/java/pacmanGame/VisualizerPlainTextUltra.java index a687d4a..2db5054 100644 --- a/src/main/java/pacmanGame/VisualizerPlainTextUltra.java +++ b/src/main/java/pacmanGame/VisualizerPlainTextUltra.java @@ -72,12 +72,30 @@ public class VisualizerPlainTextUltra implements Visualizer { "~~~~" } }; - public final String[] playerSprite = { "▄██▄", "▀██▀" }; + public final String[][] playerAltSprites = { + { + "▄ ▄", + "▀██▀" + }, + { + "▄██▄", + "▀ ▀" + }, + { + " ▀█▄", + " ▄█▀" + }, + { + "▄█▀ ", + "▀█▄ " + } + }; + public VisualizerPlainTextUltra(GameManager gameManager) { this.gameManager = gameManager; } @@ -87,10 +105,82 @@ public class VisualizerPlainTextUltra implements Visualizer { return output; } - @Override public void Update() { - // TODO Auto-generated method stub + 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) { + 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; } }