Browse Source

added reference from Map to GameManager

remotes/origin/menu
fdai7910 11 months ago
parent
commit
d93047ffac
  1. 2
      src/main/java/pacmanGame/GameManager.java
  2. 4
      src/main/java/pacmanGame/Map.java
  3. 10
      src/test/java/pacmanTests/MapTest.java
  4. 4
      src/test/java/pacmanTests/VisualizerPlainTextTest.java

2
src/main/java/pacmanGame/GameManager.java

@ -13,7 +13,7 @@ public class GameManager {
} }
public void setupGame(){ public void setupGame(){
map = new Map(Map.mapClassic);
map = new Map(Map.mapClassic,this);
visualizer = new VisualizerPlainText(this); visualizer = new VisualizerPlainText(this);
player = new Player(this); player = new Player(this);
player.Spawn(); player.Spawn();

4
src/main/java/pacmanGame/Map.java

@ -4,6 +4,7 @@ import java.util.HashMap;
public class Map { public class Map {
public final GameManager gameManager;
public static String[] mapClassic = { public static String[] mapClassic = {
"wwwwwwwwwwwwwwwwwwwwwwwwwwwwww", "wwwwwwwwwwwwwwwwwwwwwwwwwwwwww",
"wwwwwwwwwwwwwwwwwwwwwwwwwwwwww", "wwwwwwwwwwwwwwwwwwwwwwwwwwwwww",
@ -53,8 +54,9 @@ public class Map {
public Vector2 playerSpawn = new Vector2(2,2); public Vector2 playerSpawn = new Vector2(2,2);
public char playerSpawnChar = 's'; public char playerSpawnChar = 's';
public Map(String[] mapData) {
public Map(String[] mapData, GameManager gameManager) {
GenerateMap(mapData); GenerateMap(mapData);
this.gameManager = gameManager;
} }
public void GenerateMap(String[] mapData) { public void GenerateMap(String[] mapData) {

10
src/test/java/pacmanTests/MapTest.java

@ -22,8 +22,10 @@ class MapTest {
String expectedMiddle = "dot"; String expectedMiddle = "dot";
String expectedBottomRight = "dot"; String expectedBottomRight = "dot";
// act // act
Map testMap = new Map(mapTest);
GameManager gameManager = new GameManager();
gameManager.map = new Map(mapTest, gameManager);
Map testMap = gameManager.map;
String topLeft = testMap.cells[0][2].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][0].type; String bottomRight = testMap.cells[2][0].type;
@ -41,7 +43,9 @@ class MapTest {
"w..", "w..",
"ee." "ee."
}; };
Map testMap = new Map(mapTest);
GameManager gameManager = new GameManager();
gameManager.map = new Map(mapTest, gameManager);
Map testMap = gameManager.map;
Cell expectedTopLeft = testMap.cells[0][2]; Cell expectedTopLeft = testMap.cells[0][2];
Cell expectedMiddle = testMap.cells[1][1]; Cell expectedMiddle = testMap.cells[1][1];
Cell expectedBottomRight = testMap.cells[2][0]; Cell expectedBottomRight = testMap.cells[2][0];

4
src/test/java/pacmanTests/VisualizerPlainTextTest.java

@ -20,7 +20,7 @@ class VisualizerPlainTextTest {
}; };
GameManager gameManager = new GameManager(); GameManager gameManager = new GameManager();
gameManager.map = new Map(mapTest);
gameManager.map = new Map(mapTest, gameManager);
VisualizerPlainText vpt = new VisualizerPlainText(gameManager); VisualizerPlainText vpt = new VisualizerPlainText(gameManager);
String expected = "" String expected = ""
@ -44,7 +44,7 @@ class VisualizerPlainTextTest {
}; };
GameManager gameManager = new GameManager(); GameManager gameManager = new GameManager();
gameManager.map = new Map(mapTest);
gameManager.map = new Map(mapTest, gameManager);
VisualizerPlainText vpt = new VisualizerPlainText(gameManager); VisualizerPlainText vpt = new VisualizerPlainText(gameManager);
gameManager.ghosts[0].position = new Vector2(1, 1); gameManager.ghosts[0].position = new Vector2(1, 1);

Loading…
Cancel
Save