From 5fe25f68e5b62f355e72cef5bd5172a0e0e86a7f Mon Sep 17 00:00:00 2001 From: fdai7012 Date: Wed, 17 Jan 2024 16:54:17 +0100 Subject: [PATCH] Added GetCell Function to Map --- src/main/java/pacmanGame/Map.java | 4 ++++ src/test/java/pacmanTests/MapTest.java | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/main/java/pacmanGame/Map.java b/src/main/java/pacmanGame/Map.java index ac317c8..ed5db46 100644 --- a/src/main/java/pacmanGame/Map.java +++ b/src/main/java/pacmanGame/Map.java @@ -75,4 +75,8 @@ public class Map { } } } + + public Cell GetCell(Vector2 pos) { + return cells[pos.x][pos.y]; + } } diff --git a/src/test/java/pacmanTests/MapTest.java b/src/test/java/pacmanTests/MapTest.java index 0a67ce2..e895acf 100644 --- a/src/test/java/pacmanTests/MapTest.java +++ b/src/test/java/pacmanTests/MapTest.java @@ -32,4 +32,26 @@ class MapTest { assertThat(expectedMiddle).isEqualTo(middle); assertThat(expectedBottomRight).isEqualTo(bottomRight); } + + @Test + void Map_getCell_returnsCorrectCells() { + // arrange + String[] mapTest = { + "wew", + "w..", + "ee." + }; + Map testMap = new Map(mapTest); + Cell expectedTopLeft = testMap.cells[0][0]; + Cell expectedMiddle = testMap.cells[1][1]; + Cell expectedBottomRight = testMap.cells[2][2]; + // act + Cell topLeft = testMap.GetCell(new Vector2(0, 0)); + Cell middle = testMap.GetCell(new Vector2(1, 1)); + Cell bottomRight = testMap.GetCell(new Vector2(2, 2)); + // assert + assertThat(expectedTopLeft).isEqualTo(topLeft); + assertThat(expectedMiddle).isEqualTo(middle); + assertThat(expectedBottomRight).isEqualTo(bottomRight); + } }