diff --git a/src/main/java/pacmanGame/Cell.java b/src/main/java/pacmanGame/Cell.java index 808cde1..a077a59 100644 --- a/src/main/java/pacmanGame/Cell.java +++ b/src/main/java/pacmanGame/Cell.java @@ -4,6 +4,7 @@ public class Cell { public Vector2 pos; public String type; public final Map map; + public GameManager gameManager; public Cell(Vector2 pos, String type, Map map) { this.pos = pos; @@ -17,11 +18,15 @@ public class Cell { } public void triggerPill() { - //todo: code + this.type = "empty"; + gameManager.score += 100; + int timeStopPillEffect = gameManager.time + 200; + gameManager.ghostIsEdible = true; } public void triggerFruit() { - //todo: code + this.type = "empty"; + map.gameManager.score += 505; } public void triggerItem() { @@ -35,8 +40,7 @@ public class Cell { triggerFruit(); } else { - System.out.println("cell contains no item!"); + //System.out.println("cell contains no item!"); } } - } diff --git a/src/main/java/pacmanGame/GameManager.java b/src/main/java/pacmanGame/GameManager.java index 818d0ed..6c60efb 100644 --- a/src/main/java/pacmanGame/GameManager.java +++ b/src/main/java/pacmanGame/GameManager.java @@ -7,6 +7,7 @@ public class GameManager { public Visualizer visualizer; public Player player; public int score = 0; + public Boolean ghostIsEdible = false; public GameManager() { setupGame(); @@ -28,8 +29,22 @@ public class GameManager { if(time%5 == 0) { player.Move(); } + if(time == 300) { + spawnCherry(); + } + if (time == 600) { + destroyCherry(); + } time++; } + + public void spawnCherry() { + map.GetCell(map.playerSpawn).type = "cherry"; + } + + public void destroyCherry() { + map.GetCell(map.playerSpawn).type = "empty"; + } public void ProcessInput(char inputChar) { if(inputChar == 27) { @@ -59,4 +74,15 @@ public class GameManager { } return false; } + + public void updatePlayerCell() { + map.GetCell(player.position).triggerItem(); + } + + public void makeGhostEdible(int timeStopPillEffect) { + ghostIsEdible = true; + if(time == timeStopPillEffect) { + ghostIsEdible = false; + } + } } diff --git a/src/main/java/pacmanGame/Player.java b/src/main/java/pacmanGame/Player.java index fb8c3f0..b729254 100644 --- a/src/main/java/pacmanGame/Player.java +++ b/src/main/java/pacmanGame/Player.java @@ -24,6 +24,7 @@ public class Player { if(!newPosIsWall) { position = newPosition; } + gameManager.updatePlayerCell(); } public void processInput(char inputchar) { diff --git a/src/main/java/pacmanGame/VisualizerPlainText.java b/src/main/java/pacmanGame/VisualizerPlainText.java index 8559f95..37f7768 100644 --- a/src/main/java/pacmanGame/VisualizerPlainText.java +++ b/src/main/java/pacmanGame/VisualizerPlainText.java @@ -11,6 +11,7 @@ public class VisualizerPlainText implements Visualizer { this.put("empty", " "); this.put("dot", ". "); this.put("wall", "[]"); + this.put("cherry", "OO"); }}; public final String ghostSprite = "AA"; @@ -27,7 +28,7 @@ public class VisualizerPlainText implements Visualizer { @Override public void Update() { - output = ""; + output = "Score: " + gameManager.score + "\n"; Map map = gameManager.map; for(int y = 0; y < map.size.y; y++) { @@ -55,7 +56,7 @@ public class VisualizerPlainText implements Visualizer { output += sprites.get(cell.type); } else { - System.out.println("unknown type" + cell.type); + System.out.println("unknown type " + cell.type); } } output += "\n";