Browse Source

Implemented visualization update to VisualizerPlainText

remotes/origin/menu
fdai7012 11 months ago
committed by Julian
parent
commit
c68803a846
  1. 27
      src/main/java/pacmanGame/VisualizerPlainText.java
  2. 36
      src/test/java/pacmanTests/VisualizerPlainTextTest.java

27
src/main/java/pacmanGame/VisualizerPlainText.java

@ -7,6 +7,12 @@ public class VisualizerPlainText implements Visualizer {
private String output;
public final GameManager gameManager;
public HashMap<String, String> sprites = new HashMap<String,String>(){{
this.put("empty", " ");
this.put("dot", ". ");
this.put("wall", "[]");
}};
public VisualizerPlainText(GameManager gameManager) {
this.gameManager = gameManager;
}
@ -15,9 +21,26 @@ public class VisualizerPlainText implements Visualizer {
public Object GetOutput() {
return output;
}
@Override
public void Update() {
// TODO Auto-generated method stub
output = "";
Map map = gameManager.map;
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)) {
output += sprites.get(cell.type);
}
else {
System.out.println("unknown type" + cell.type);
}
}
output += "\n";
}
}
}

36
src/test/java/pacmanTests/VisualizerPlainTextTest.java

@ -0,0 +1,36 @@
package pacmanTests;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import pacmanGame.*;
class VisualizerPlainTextTest {
@Test
void VisualizerPlainText_mapCells_areVisualized() {
// arrange
String[] mapTest = {
"w.w",
"e.e",
"w.w"
};
GameManager gameManager = new GameManager();
gameManager.map = new Map(mapTest);
VisualizerPlainText vpt = new VisualizerPlainText(gameManager);
String expected = ""
+ "[]. []\n"
+ " . \n"
+ "[]. []\n";
// act
vpt.Update();
String result = (String)vpt.GetOutput();
// assert
assertThat(expected).isEqualTo(result);
}
}
Loading…
Cancel
Save