diff --git a/src/main/java/pacmanGame/VisualizerPlainText.java b/src/main/java/pacmanGame/VisualizerPlainText.java index 17ceb9f..eea95a2 100644 --- a/src/main/java/pacmanGame/VisualizerPlainText.java +++ b/src/main/java/pacmanGame/VisualizerPlainText.java @@ -13,6 +13,8 @@ public class VisualizerPlainText implements Visualizer { this.put("wall", "[]"); }}; + public final String ghostSprite = "AA"; + public VisualizerPlainText(GameManager gameManager) { this.gameManager = gameManager; } @@ -30,8 +32,17 @@ public class VisualizerPlainText implements Visualizer { for(int y = 0; y < map.size.y; y++) { for(int x = 0; x < map.size.x; x++) { Cell cell = map.GetCell(new Vector2(x,y)); - - if (sprites.containsKey(cell.type)) { + boolean containsGhosts = false; + for( int i = 0; i < gameManager.ghosts.length; i++) { + if(gameManager.ghosts[i].position.equals(cell.pos)) { + containsGhosts = true; + } + } + + if(containsGhosts) { + output += ghostSprite; + } + else if (sprites.containsKey(cell.type)) { output += sprites.get(cell.type); } @@ -42,5 +53,7 @@ public class VisualizerPlainText implements Visualizer { output += "\n"; } } + + } diff --git a/src/test/java/pacmanTests/VisualizerPlainTextTest.java b/src/test/java/pacmanTests/VisualizerPlainTextTest.java index d948611..92276e2 100644 --- a/src/test/java/pacmanTests/VisualizerPlainTextTest.java +++ b/src/test/java/pacmanTests/VisualizerPlainTextTest.java @@ -33,4 +33,30 @@ class VisualizerPlainTextTest { // assert assertThat(expected).isEqualTo(result); } + + @Test + void VisualizerPlainText_ghosts_areVisualized() { + // arrange + String[] mapTest = { + "w.w", + "e.e", + "w.w" + }; + + GameManager gameManager = new GameManager(); + gameManager.map = new Map(mapTest); + VisualizerPlainText vpt = new VisualizerPlainText(gameManager); + + gameManager.ghosts[0].position = new Vector2(1, 1); + + String expected = "" + + "[]. []\n" + + " AA \n" + + "[]. []\n"; + // act + vpt.Update(); + String result = (String)vpt.GetOutput(); + // assert + assertThat(expected).isEqualTo(result); + } }