Browse Source

Fixed map coordinates being inverted

remotes/origin/menu
fdai7012 11 months ago
parent
commit
b0d7129e1c
  1. 2
      src/main/java/pacmanGame/Map.java
  2. 2
      src/main/java/pacmanGame/VisualizerPlainText.java
  3. 14
      src/test/java/pacmanTests/MapTest.java

2
src/main/java/pacmanGame/Map.java

@ -69,7 +69,7 @@ public class Map {
for(int y = 0; y < size.y; y++) { for(int y = 0; y < size.y; y++) {
Vector2 cellPos = new Vector2(x,y); Vector2 cellPos = new Vector2(x,y);
String cellType = mapTypes.get(String.valueOf(mapData[y].charAt(x)));
String cellType = mapTypes.get(String.valueOf(mapData[size.y - 1 - y].charAt(x)));
cells[x][y] = new Cell(cellPos, cellType); cells[x][y] = new Cell(cellPos, cellType);
} }

2
src/main/java/pacmanGame/VisualizerPlainText.java

@ -31,7 +31,7 @@ public class VisualizerPlainText implements Visualizer {
for(int y = 0; y < map.size.y; y++) { for(int y = 0; y < map.size.y; y++) {
for(int x = 0; x < map.size.x; x++) { for(int x = 0; x < map.size.x; x++) {
Cell cell = map.GetCell(new Vector2(x,y));
Cell cell = map.GetCell(new Vector2(x, map.size.y - 1 - y));
boolean containsGhosts = false; boolean containsGhosts = false;
for( int i = 0; i < gameManager.ghosts.length; i++) { for( int i = 0; i < gameManager.ghosts.length; i++) {
if(gameManager.ghosts[i].position.equals(cell.pos)) { if(gameManager.ghosts[i].position.equals(cell.pos)) {

14
src/test/java/pacmanTests/MapTest.java

@ -24,15 +24,15 @@ class MapTest {
// act // act
Map testMap = new Map(mapTest); Map testMap = new Map(mapTest);
String topLeft = testMap.cells[0][0].type;
String topLeft = testMap.cells[0][2].type;
String middle = testMap.cells[1][1].type; String middle = testMap.cells[1][1].type;
String bottomRight = testMap.cells[2][2].type;
String bottomRight = testMap.cells[2][0].type;
// assert // assert
assertThat(expectedTopLeft).isEqualTo(topLeft); assertThat(expectedTopLeft).isEqualTo(topLeft);
assertThat(expectedMiddle).isEqualTo(middle); assertThat(expectedMiddle).isEqualTo(middle);
assertThat(expectedBottomRight).isEqualTo(bottomRight); assertThat(expectedBottomRight).isEqualTo(bottomRight);
} }
@Test @Test
void Map_getCell_returnsCorrectCells() { void Map_getCell_returnsCorrectCells() {
// arrange // arrange
@ -42,13 +42,13 @@ class MapTest {
"ee." "ee."
}; };
Map testMap = new Map(mapTest); Map testMap = new Map(mapTest);
Cell expectedTopLeft = testMap.cells[0][0];
Cell expectedTopLeft = testMap.cells[0][2];
Cell expectedMiddle = testMap.cells[1][1]; Cell expectedMiddle = testMap.cells[1][1];
Cell expectedBottomRight = testMap.cells[2][2];
Cell expectedBottomRight = testMap.cells[2][0];
// act // act
Cell topLeft = testMap.GetCell(new Vector2(0, 0));
Cell topLeft = testMap.GetCell(new Vector2(0, 2));
Cell middle = testMap.GetCell(new Vector2(1, 1)); Cell middle = testMap.GetCell(new Vector2(1, 1));
Cell bottomRight = testMap.GetCell(new Vector2(2, 2));
Cell bottomRight = testMap.GetCell(new Vector2(2, 0));
// assert // assert
assertThat(expectedTopLeft).isEqualTo(topLeft); assertThat(expectedTopLeft).isEqualTo(topLeft);
assertThat(expectedMiddle).isEqualTo(middle); assertThat(expectedMiddle).isEqualTo(middle);

Loading…
Cancel
Save