From e83ac8db4fe18f131e54692ccf78453537cd8896 Mon Sep 17 00:00:00 2001 From: fdai7910 Date: Sat, 3 Feb 2024 21:02:57 +0100 Subject: [PATCH 1/9] added updatePlayerCell function to GameManager --- src/main/java/pacmanGame/Cell.java | 5 +++-- src/main/java/pacmanGame/GameManager.java | 4 ++++ src/main/java/pacmanGame/Player.java | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/pacmanGame/Cell.java b/src/main/java/pacmanGame/Cell.java index 808cde1..db5751f 100644 --- a/src/main/java/pacmanGame/Cell.java +++ b/src/main/java/pacmanGame/Cell.java @@ -17,11 +17,13 @@ public class Cell { } public void triggerPill() { + this.type = "empty"; //todo: code } public void triggerFruit() { - //todo: code + this.type = "empty"; + map.gameManager.score += 505; } public void triggerItem() { @@ -38,5 +40,4 @@ public class Cell { 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..9ecaa26 100644 --- a/src/main/java/pacmanGame/GameManager.java +++ b/src/main/java/pacmanGame/GameManager.java @@ -59,4 +59,8 @@ public class GameManager { } return false; } + + public void updatePlayerCell() { + map.GetCell(player.position).triggerItem(); + } } 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) { From 054494cf2bdc4f9054a1376c4796dfad0313a597 Mon Sep 17 00:00:00 2001 From: fdai7910 Date: Sat, 3 Feb 2024 21:27:06 +0100 Subject: [PATCH 2/9] added spawnCherry function in GameManager --- src/main/java/pacmanGame/Cell.java | 2 +- src/main/java/pacmanGame/GameManager.java | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/pacmanGame/Cell.java b/src/main/java/pacmanGame/Cell.java index db5751f..46d21e3 100644 --- a/src/main/java/pacmanGame/Cell.java +++ b/src/main/java/pacmanGame/Cell.java @@ -37,7 +37,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 9ecaa26..9bf19bc 100644 --- a/src/main/java/pacmanGame/GameManager.java +++ b/src/main/java/pacmanGame/GameManager.java @@ -28,8 +28,15 @@ public class GameManager { if(time%5 == 0) { player.Move(); } + if(time == 300) { + spawnCherry(); + } time++; } + + public void spawnCherry() { + map.GetCell(map.playerSpawn).type = "cherry"; + } public void ProcessInput(char inputChar) { if(inputChar == 27) { From 737ace11bba9997ea9967c2b7381af414d75b7d5 Mon Sep 17 00:00:00 2001 From: fdai7910 Date: Sat, 3 Feb 2024 21:31:17 +0100 Subject: [PATCH 3/9] added visuals for cherry in VisualizerPlainText --- src/main/java/pacmanGame/VisualizerPlainText.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/pacmanGame/VisualizerPlainText.java b/src/main/java/pacmanGame/VisualizerPlainText.java index 8559f95..da56213 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"; From e060b184fbff799b82c5040a87e20c3a36debf08 Mon Sep 17 00:00:00 2001 From: fdai7910 Date: Sat, 3 Feb 2024 21:41:36 +0100 Subject: [PATCH 4/9] added destroyCherry function to GameManager --- src/main/java/pacmanGame/GameManager.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/pacmanGame/GameManager.java b/src/main/java/pacmanGame/GameManager.java index 9bf19bc..172cbd3 100644 --- a/src/main/java/pacmanGame/GameManager.java +++ b/src/main/java/pacmanGame/GameManager.java @@ -31,12 +31,19 @@ public class GameManager { 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) { From f06f86ca0e1ef68b8a4e427b91ed2787ec8c4c81 Mon Sep 17 00:00:00 2001 From: fdai7910 Date: Sun, 4 Feb 2024 18:34:16 +0100 Subject: [PATCH 5/9] refactoring: fixed error message in VisualizerPlainText --- src/main/java/pacmanGame/VisualizerPlainText.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/pacmanGame/VisualizerPlainText.java b/src/main/java/pacmanGame/VisualizerPlainText.java index da56213..95e3413 100644 --- a/src/main/java/pacmanGame/VisualizerPlainText.java +++ b/src/main/java/pacmanGame/VisualizerPlainText.java @@ -56,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"; From 15b9bd80cb343273419e9ab5df32d3804857d99c Mon Sep 17 00:00:00 2001 From: fdai7910 Date: Sun, 4 Feb 2024 18:50:44 +0100 Subject: [PATCH 6/9] added visuals for score in VisualizerPlaintText --- src/main/java/pacmanGame/VisualizerPlainText.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/pacmanGame/VisualizerPlainText.java b/src/main/java/pacmanGame/VisualizerPlainText.java index 95e3413..37f7768 100644 --- a/src/main/java/pacmanGame/VisualizerPlainText.java +++ b/src/main/java/pacmanGame/VisualizerPlainText.java @@ -28,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++) { From eb100975f1627ee997502c181d8c4a22e686a30e Mon Sep 17 00:00:00 2001 From: fdai7910 Date: Sun, 4 Feb 2024 19:16:08 +0100 Subject: [PATCH 7/9] added state for edible ghosts in GameManager --- src/main/java/pacmanGame/GameManager.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/pacmanGame/GameManager.java b/src/main/java/pacmanGame/GameManager.java index 172cbd3..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(); @@ -77,4 +78,11 @@ public class GameManager { public void updatePlayerCell() { map.GetCell(player.position).triggerItem(); } + + public void makeGhostEdible(int timeStopPillEffect) { + ghostIsEdible = true; + if(time == timeStopPillEffect) { + ghostIsEdible = false; + } + } } From 74ac6290911014daa3517e94d5b3b66133f1d2dd Mon Sep 17 00:00:00 2001 From: fdai7910 Date: Sun, 4 Feb 2024 19:16:41 +0100 Subject: [PATCH 8/9] added functionality for pill in Cell --- src/main/java/pacmanGame/Cell.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/pacmanGame/Cell.java b/src/main/java/pacmanGame/Cell.java index 46d21e3..b9dcb48 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; @@ -18,7 +19,9 @@ public class Cell { public void triggerPill() { this.type = "empty"; - //todo: code + gameManager.score += 100; + int timeStopPillEffect = gameManager.time + 200; + //ghost.triggerPillEffect(timeStopPillEffect); } public void triggerFruit() { From 9513c58b9cf7a421e1d7c6c956cfba443f16a524 Mon Sep 17 00:00:00 2001 From: fdai7910 Date: Sun, 4 Feb 2024 19:33:34 +0100 Subject: [PATCH 9/9] changed pill functionality in Cell --- src/main/java/pacmanGame/Cell.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/pacmanGame/Cell.java b/src/main/java/pacmanGame/Cell.java index b9dcb48..a077a59 100644 --- a/src/main/java/pacmanGame/Cell.java +++ b/src/main/java/pacmanGame/Cell.java @@ -21,7 +21,7 @@ public class Cell { this.type = "empty"; gameManager.score += 100; int timeStopPillEffect = gameManager.time + 200; - //ghost.triggerPillEffect(timeStopPillEffect); + gameManager.ghostIsEdible = true; } public void triggerFruit() {