diff --git a/src/main/java/pacmanGame/Cell.java b/src/main/java/pacmanGame/Cell.java index 53105af..808cde1 100644 --- a/src/main/java/pacmanGame/Cell.java +++ b/src/main/java/pacmanGame/Cell.java @@ -3,9 +3,40 @@ package pacmanGame; public class Cell { public Vector2 pos; public String type; + public final Map map; - public Cell(Vector2 pos, String type) { + public Cell(Vector2 pos, String type, Map map) { this.pos = pos; this.type = type; + this.map = map; } + + public void triggerDot() { + this.type = "empty"; + map.gameManager.score += 10; + } + + public void triggerPill() { + //todo: code + } + + public void triggerFruit() { + //todo: code + } + + public void triggerItem() { + if(type.equals("dot")) { + triggerDot(); + } + else if(type.equals("pill")) { + triggerPill(); + } + else if(type.equals("cherry")) { + triggerFruit(); + } + else { + System.out.println("cell contains no item!"); + } + } + } diff --git a/src/main/java/pacmanGame/GameManager.java b/src/main/java/pacmanGame/GameManager.java index 8a154d5..818d0ed 100644 --- a/src/main/java/pacmanGame/GameManager.java +++ b/src/main/java/pacmanGame/GameManager.java @@ -6,22 +6,23 @@ public class GameManager { public Map map; public Visualizer visualizer; public Player player; + public int score = 0; public GameManager() { setupGame(); } public void setupGame(){ - map = new Map(); + map = new Map(Map.mapClassic,this); visualizer = new VisualizerPlainText(this); player = new Player(this); player.Spawn(); ghosts = new Ghost[4]; for(int i = 0; i < ghosts.length; i++) { ghosts[i] = new Ghost(this); - } - + } } + public void Update() { visualizer.Update(); if(time%5 == 0) { @@ -30,23 +31,19 @@ public class GameManager { time++; } - public void ProcessInput(char inputChar) { if(inputChar == 27) { //todo: escape key pauses game } - else if (inputChar == 'w' || inputChar == 's' || inputChar == 'd' || inputChar == 'a') { player.processInput(inputChar); } - - else { System.out.println("Unprocessed Input: " + inputChar + " (" + (int)inputChar + ")"); } } - public boolean GostPlayerColisionTest() - { + + public boolean GhostPlayerColisionTest() { for(int i = 0; i < ghosts.length; i++) { @@ -56,9 +53,7 @@ public class GameManager { { return true; } - - } - + } } } diff --git a/src/main/java/pacmanGame/Map.java b/src/main/java/pacmanGame/Map.java index 8e9371f..40ab6aa 100644 --- a/src/main/java/pacmanGame/Map.java +++ b/src/main/java/pacmanGame/Map.java @@ -3,7 +3,9 @@ package pacmanGame; import java.util.HashMap; public class Map { - public final String[] mapClassic = { + + public final GameManager gameManager; + public static String[] mapClassic = { "wwwwwwwwwwwwwwwwwwwwwwwwwwwwww", "wwwwwwwwwwwwwwwwwwwwwwwwwwwwww", "ww............ww............ww", @@ -52,12 +54,9 @@ public class Map { public Vector2 playerSpawn = new Vector2(2,2); public char playerSpawnChar = 's'; - public Map() { - GenerateMap(mapClassic); - } - - public Map(String[] mapData) { + public Map(String[] mapData, GameManager gameManager) { GenerateMap(mapData); + this.gameManager = gameManager; } public void GenerateMap(String[] mapData) { @@ -77,7 +76,7 @@ public class Map { String cellType = mapTypes.get(String.valueOf(cellChar)); - cells[x][y] = new Cell(cellPos, cellType); + cells[x][y] = new Cell(cellPos, cellType, this); if(cellChar == playerSpawnChar) { playerSpawn = cellPos.Clone(); diff --git a/src/test/java/pacmanTests/GameManagerTest.java b/src/test/java/pacmanTests/GameManagerTest.java index 9495c45..175852b 100644 --- a/src/test/java/pacmanTests/GameManagerTest.java +++ b/src/test/java/pacmanTests/GameManagerTest.java @@ -54,7 +54,7 @@ class GameManagerTest { GameManager gameManager = new GameManager(); gameManager.player.position = gameManager.ghosts[0].position.Clone(); //act - boolean colision = gameManager.GostPlayerColisionTest(); + boolean colision = gameManager.GhostPlayerColisionTest(); boolean expected = true; // assert @@ -69,7 +69,7 @@ class GameManagerTest { gameManager.player.position = new Vector2(2,3); gameManager.ghosts[0].position = new Vector2(4,5); //act - boolean colision = gameManager.GostPlayerColisionTest(); + boolean colision = gameManager.GhostPlayerColisionTest(); boolean expected = false; // assert diff --git a/src/test/java/pacmanTests/MapTest.java b/src/test/java/pacmanTests/MapTest.java index cc94256..f94d0bd 100644 --- a/src/test/java/pacmanTests/MapTest.java +++ b/src/test/java/pacmanTests/MapTest.java @@ -22,8 +22,10 @@ class MapTest { String expectedMiddle = "dot"; String expectedBottomRight = "dot"; // 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 middle = testMap.cells[1][1].type; String bottomRight = testMap.cells[2][0].type; @@ -41,7 +43,9 @@ class MapTest { "w..", "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 expectedMiddle = testMap.cells[1][1]; Cell expectedBottomRight = testMap.cells[2][0]; diff --git a/src/test/java/pacmanTests/VisualizerPlainTextTest.java b/src/test/java/pacmanTests/VisualizerPlainTextTest.java index 92276e2..e73225c 100644 --- a/src/test/java/pacmanTests/VisualizerPlainTextTest.java +++ b/src/test/java/pacmanTests/VisualizerPlainTextTest.java @@ -20,7 +20,7 @@ class VisualizerPlainTextTest { }; GameManager gameManager = new GameManager(); - gameManager.map = new Map(mapTest); + gameManager.map = new Map(mapTest, gameManager); VisualizerPlainText vpt = new VisualizerPlainText(gameManager); String expected = "" @@ -44,7 +44,7 @@ class VisualizerPlainTextTest { }; GameManager gameManager = new GameManager(); - gameManager.map = new Map(mapTest); + gameManager.map = new Map(mapTest, gameManager); VisualizerPlainText vpt = new VisualizerPlainText(gameManager); gameManager.ghosts[0].position = new Vector2(1, 1);