diff --git a/src/main/java/pacmanGame/Map.java b/src/main/java/pacmanGame/Map.java index 681891b..ac317c8 100644 --- a/src/main/java/pacmanGame/Map.java +++ b/src/main/java/pacmanGame/Map.java @@ -1,7 +1,78 @@ package pacmanGame; +import java.util.HashMap; + public class Map { + public final String[] mapClassic = { + "wwwwwwwwwwwwwwwwwwwwwwwwwwwwww", + "wwwwwwwwwwwwwwwwwwwwwwwwwwwwww", + "ww............ww............ww", + "ww.wwww.wwwww.ww.wwwww.wwww.ww", + "ww.wwww.wwwww.ww.wwwww.wwww.ww", + "ww.wwww.wwwww.ww.wwwww.wwww.ww", + "ww..........................ww", + "ww.wwww.ww.wwwwwwww.ww.wwww.ww", + "ww.wwww.ww.wwwwwwww.ww.wwww.ww", + "ww......ww....ww....ww......ww", + "wwwwwww.wwwwwewwewwwww.wwwwwww", + "wwwwwww.wwwwwewwewwwww.wwwwwww", + "wwwwwww.wweeeeeeeeeeww.wwwwwww", + "wwwwwww.wwewwwwwwwweww.wwwwwww", + "wwwwwww.wweweeeeeeweww.wwwwwww", + "eeeeeee.eeeweeeeeeweee.eeeeeee", + "wwwwwww.wweweeeeeeweww.wwwwwww", + "wwwwwww.wweweeeeeeweww.wwwwwww", + "wwwwwww.wwewwwwwwwweww.wwwwwww", + "wwwwwww.wweeeeeeeeeeww.wwwwwww", + "wwwwwww.wwewwwwwwwweww.wwwwwww", + "ww............ww............ww", + "ww.wwww.wwwww.ww.wwwww.wwww.ww", + "ww.wwww.wwwww.ww.wwwww.wwww.ww", + "ww...ww................ww...ww", + "wwww.ww.ww.wwwwwwww.ww.ww.wwww", + "wwww.ww.ww.wwwwwwww.ww.ww.wwww", + "ww......ww....ww....ww......ww", + "ww.wwwwwwwwww.ww.wwwwwwwwww.ww", + "ww.wwwwwwwwww.ww.wwwwwwwwww.ww", + "ww..........................ww", + "wwwwwwwwwwwwwwwwwwwwwwwwwwwwww", + "wwwwwwwwwwwwwwwwwwwwwwwwwwwwww" + }; + + public final HashMap mapTypes = new HashMap(){{ + this.put("e", "empty"); + this.put(".", "dot"); + this.put("w", "wall"); + }}; + public Cell[][] cells; public Vector2 size; + public Map() { + GenerateMap(mapClassic); + } + + public Map(String[] mapData) { + GenerateMap(mapData); + } + + public void GenerateMap(String[] mapData) { + + int sizeY = mapData.length; + int sizeX = mapData[0].length(); + + size = new Vector2(sizeX, sizeY); + + cells = new Cell[size.x][size.y]; + + for(int x = 0; x < size.x; x++) { + for(int y = 0; y < size.y; y++) { + Vector2 cellPos = new Vector2(x,y); + + String cellType = mapTypes.get(String.valueOf(mapData[y].charAt(x))); + + cells[x][y] = new Cell(cellPos, cellType); + } + } + } } diff --git a/src/test/java/pacmanTests/MapTest.java b/src/test/java/pacmanTests/MapTest.java new file mode 100644 index 0000000..0a67ce2 --- /dev/null +++ b/src/test/java/pacmanTests/MapTest.java @@ -0,0 +1,35 @@ +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 MapTest { + + @Test + void Map_differentCellTypes_areInterpretedCorrectly() { + // arrange + String[] mapTest = { + "wew", + "w..", + "ee." + }; + String expectedTopLeft = "wall"; + String expectedMiddle = "dot"; + String expectedBottomRight = "dot"; + // act + Map testMap = new Map(mapTest); + + String topLeft = testMap.cells[0][0].type; + String middle = testMap.cells[1][1].type; + String bottomRight = testMap.cells[2][2].type; + // assert + assertThat(expectedTopLeft).isEqualTo(topLeft); + assertThat(expectedMiddle).isEqualTo(middle); + assertThat(expectedBottomRight).isEqualTo(bottomRight); + } +}