From fea82c0a736cd215438bfbf261858ddd07974a28 Mon Sep 17 00:00:00 2001 From: fdai7910 Date: Sun, 4 Feb 2024 21:43:57 +0100 Subject: [PATCH 01/28] changed movement behaviour in Player --- src/main/java/pacmanGame/Player.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/pacmanGame/Player.java b/src/main/java/pacmanGame/Player.java index b729254..40b5e70 100644 --- a/src/main/java/pacmanGame/Player.java +++ b/src/main/java/pacmanGame/Player.java @@ -4,6 +4,7 @@ public class Player { public Vector2 position; public Vector2 direction; public GameManager gameManager; + public Vector2 oldDirection; public Player(GameManager gameManager) { this.gameManager = gameManager; @@ -14,22 +15,27 @@ public class Player { public void Spawn() { position = gameManager.map.playerSpawn; direction = new Vector2(0, -1); + oldDirection = direction; } public void Move() { Vector2 newPosition = position.Add(direction); - boolean newPosIsWall = gameManager.map.GetCell(newPosition).type.equals("wall"); if(!newPosIsWall) { position = newPosition; } + else if(oldDirection != direction) { + direction = oldDirection; + Move(); + } gameManager.updatePlayerCell(); } public void processInput(char inputchar) { + oldDirection = direction; - if(inputchar == 'w') { + if(inputchar == 'w') { direction = new Vector2(0,1); } From 2a54b4bdd0bc2e3b4802c24490aa6aa33ff3df05 Mon Sep 17 00:00:00 2001 From: fdai7910 Date: Mon, 5 Feb 2024 19:48:24 +0100 Subject: [PATCH 02/28] updated Uptdate to check if ghostIsEdible needs to be turned off in GameManager --- src/main/java/pacmanGame/Cell.java | 3 ++- src/main/java/pacmanGame/GameManager.java | 14 ++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main/java/pacmanGame/Cell.java b/src/main/java/pacmanGame/Cell.java index a077a59..f9cd74b 100644 --- a/src/main/java/pacmanGame/Cell.java +++ b/src/main/java/pacmanGame/Cell.java @@ -20,8 +20,9 @@ public class Cell { public void triggerPill() { this.type = "empty"; gameManager.score += 100; - int timeStopPillEffect = gameManager.time + 200; + gameManager.timeStopPillEffect = gameManager.time + 200; gameManager.ghostIsEdible = true; + } public void triggerFruit() { diff --git a/src/main/java/pacmanGame/GameManager.java b/src/main/java/pacmanGame/GameManager.java index 6c60efb..544b401 100644 --- a/src/main/java/pacmanGame/GameManager.java +++ b/src/main/java/pacmanGame/GameManager.java @@ -7,7 +7,8 @@ public class GameManager { public Visualizer visualizer; public Player player; public int score = 0; - public Boolean ghostIsEdible = false; + public boolean ghostIsEdible = false; + public int timeStopPillEffect; public GameManager() { setupGame(); @@ -35,6 +36,10 @@ public class GameManager { if (time == 600) { destroyCherry(); } + if(ghostIsEdible) { + if(time == timeStopPillEffect) + ghostIsEdible = false; + } time++; } @@ -78,11 +83,4 @@ public class GameManager { public void updatePlayerCell() { map.GetCell(player.position).triggerItem(); } - - public void makeGhostEdible(int timeStopPillEffect) { - ghostIsEdible = true; - if(time == timeStopPillEffect) { - ghostIsEdible = false; - } - } } From 5adcced8fbcd722bc0da3c92900bae7c8d19667f Mon Sep 17 00:00:00 2001 From: fdai7910 Date: Mon, 5 Feb 2024 20:02:24 +0100 Subject: [PATCH 03/28] fixed spamming input into wall would make player stop in Player --- src/main/java/pacmanGame/Player.java | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/main/java/pacmanGame/Player.java b/src/main/java/pacmanGame/Player.java index 40b5e70..852b90d 100644 --- a/src/main/java/pacmanGame/Player.java +++ b/src/main/java/pacmanGame/Player.java @@ -4,7 +4,6 @@ public class Player { public Vector2 position; public Vector2 direction; public GameManager gameManager; - public Vector2 oldDirection; public Player(GameManager gameManager) { this.gameManager = gameManager; @@ -15,7 +14,6 @@ public class Player { public void Spawn() { position = gameManager.map.playerSpawn; direction = new Vector2(0, -1); - oldDirection = direction; } public void Move() { @@ -25,32 +23,36 @@ public class Player { if(!newPosIsWall) { position = newPosition; } - else if(oldDirection != direction) { - direction = oldDirection; - Move(); - } + gameManager.updatePlayerCell(); } public void processInput(char inputchar) { - oldDirection = direction; if(inputchar == 'w') { - direction = new Vector2(0,1); + checkInput(new Vector2(0,1)); } else if(inputchar == 's') { - direction = new Vector2(0,-1); + checkInput(new Vector2(0,-1)); } else if(inputchar == 'd') { - direction = new Vector2(1,0); + checkInput(new Vector2(1,0)); } else if(inputchar == 'a') { - direction = new Vector2(-1,0); + checkInput(new Vector2(-1,0)); } } + public void checkInput(Vector2 input) { + Vector2 newPosition = position.Add(input); + boolean newPosIsWall = gameManager.map.GetCell(newPosition).type.equals("wall"); + if(!newPosIsWall) { + direction = input; + } + } + } From 9a31f0960b6742913b72bbf1c26fac489b879923 Mon Sep 17 00:00:00 2001 From: fdai7910 Date: Mon, 5 Feb 2024 20:09:34 +0100 Subject: [PATCH 04/28] added checkInput function to Player --- src/main/java/pacmanGame/Player.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/pacmanGame/Player.java b/src/main/java/pacmanGame/Player.java index 852b90d..411f504 100644 --- a/src/main/java/pacmanGame/Player.java +++ b/src/main/java/pacmanGame/Player.java @@ -4,6 +4,7 @@ public class Player { public Vector2 position; public Vector2 direction; public GameManager gameManager; + public Vector2 savedDirection; public Player(GameManager gameManager) { this.gameManager = gameManager; @@ -23,6 +24,9 @@ public class Player { if(!newPosIsWall) { position = newPosition; } + if(savedDirection != null) { + checkInput(savedDirection); + } gameManager.updatePlayerCell(); } @@ -52,6 +56,10 @@ public class Player { boolean newPosIsWall = gameManager.map.GetCell(newPosition).type.equals("wall"); if(!newPosIsWall) { direction = input; + savedDirection = null; + } + else { + savedDirection = input; } } From bd9559e5d0917de65ddaec17fc22d2b7cd779ef8 Mon Sep 17 00:00:00 2001 From: fdai7910 Date: Mon, 5 Feb 2024 20:49:16 +0100 Subject: [PATCH 05/28] fixed test for VisualizerPlainText --- src/main/java/pacmanGame/VisualizerPlainText.java | 9 ++++++++- src/test/java/pacmanTests/VisualizerPlainTextTest.java | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/pacmanGame/VisualizerPlainText.java b/src/main/java/pacmanGame/VisualizerPlainText.java index 37f7768..9bcc354 100644 --- a/src/main/java/pacmanGame/VisualizerPlainText.java +++ b/src/main/java/pacmanGame/VisualizerPlainText.java @@ -6,6 +6,7 @@ public class VisualizerPlainText implements Visualizer { private String output; public final GameManager gameManager; + public boolean showScore = true; public HashMap sprites = new HashMap(){{ this.put("empty", " "); @@ -28,7 +29,13 @@ public class VisualizerPlainText implements Visualizer { @Override public void Update() { - output = "Score: " + gameManager.score + "\n"; + if(showScore) { + output = "Score: " + gameManager.score + "\n"; + } + else { + output = ""; + } + Map map = gameManager.map; for(int y = 0; y < map.size.y; y++) { diff --git a/src/test/java/pacmanTests/VisualizerPlainTextTest.java b/src/test/java/pacmanTests/VisualizerPlainTextTest.java index e73225c..8979476 100644 --- a/src/test/java/pacmanTests/VisualizerPlainTextTest.java +++ b/src/test/java/pacmanTests/VisualizerPlainTextTest.java @@ -22,6 +22,7 @@ class VisualizerPlainTextTest { GameManager gameManager = new GameManager(); gameManager.map = new Map(mapTest, gameManager); VisualizerPlainText vpt = new VisualizerPlainText(gameManager); + vpt.showScore = false; String expected = "" + "[]. []\n" @@ -46,6 +47,7 @@ class VisualizerPlainTextTest { GameManager gameManager = new GameManager(); gameManager.map = new Map(mapTest, gameManager); VisualizerPlainText vpt = new VisualizerPlainText(gameManager); + vpt.showScore = false; gameManager.ghosts[0].position = new Vector2(1, 1); From e4a90e9da5da7ea6698cd3957bbb8eac455c65fe Mon Sep 17 00:00:00 2001 From: fdai7910 Date: Mon, 5 Feb 2024 20:49:40 +0100 Subject: [PATCH 06/28] added test for Cell --- src/test/java/pacmanTests/CellTest.java | 26 +++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/test/java/pacmanTests/CellTest.java diff --git a/src/test/java/pacmanTests/CellTest.java b/src/test/java/pacmanTests/CellTest.java new file mode 100644 index 0000000..9c65b44 --- /dev/null +++ b/src/test/java/pacmanTests/CellTest.java @@ -0,0 +1,26 @@ +package pacmanTests; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + +import pacmanGame.*; + + +class CellTest { + + @Test + void cell_triggerItem_505cherryScore() { + // arrange + GameManager gameManager = new GameManager(); + Cell cell = gameManager.map.GetCell(new Vector2(0,0)); + cell.type = "cherry"; + int expectedScore = 505; + // act + cell.triggerItem(); + int resultingScore = gameManager.score; + // assert + assertThat(expectedScore).isEqualTo(resultingScore); + } +} From c129d69538b0e7f17922150132c74affe7c2fb51 Mon Sep 17 00:00:00 2001 From: fdai7910 Date: Mon, 5 Feb 2024 20:52:33 +0100 Subject: [PATCH 07/28] added test for dotScore --- src/test/java/pacmanTests/CellTest.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/test/java/pacmanTests/CellTest.java b/src/test/java/pacmanTests/CellTest.java index 9c65b44..d3a5db5 100644 --- a/src/test/java/pacmanTests/CellTest.java +++ b/src/test/java/pacmanTests/CellTest.java @@ -23,4 +23,19 @@ class CellTest { // assert assertThat(expectedScore).isEqualTo(resultingScore); } + + void cell_triggerItem_10dotScore() { + // arrange + GameManager gameManager = new GameManager(); + Cell cell = gameManager.map.GetCell(new Vector2(0,0)); + cell.type = "dot"; + int expectedScore = 10; + // act + cell.triggerItem(); + int resultingScore = gameManager.score; + // assert + assertThat(expectedScore).isEqualTo(resultingScore); + } + + } From 079f330c117b461ef3f83e9ac679b1d6ea81854d Mon Sep 17 00:00:00 2001 From: fdai7910 Date: Mon, 5 Feb 2024 20:54:49 +0100 Subject: [PATCH 08/28] added test for pillScore --- src/test/java/pacmanTests/CellTest.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/test/java/pacmanTests/CellTest.java b/src/test/java/pacmanTests/CellTest.java index d3a5db5..ca10733 100644 --- a/src/test/java/pacmanTests/CellTest.java +++ b/src/test/java/pacmanTests/CellTest.java @@ -37,5 +37,18 @@ class CellTest { assertThat(expectedScore).isEqualTo(resultingScore); } + void cell_triggerItem_100pillScore() { + // arrange + GameManager gameManager = new GameManager(); + Cell cell = gameManager.map.GetCell(new Vector2(0,0)); + cell.type = "pill"; + int expectedScore = 100; + // act + cell.triggerItem(); + int resultingScore = gameManager.score; + // assert + assertThat(expectedScore).isEqualTo(resultingScore); + } + } From 8c8bf20c02d147c39fe8d9a90a861a107e2fb290 Mon Sep 17 00:00:00 2001 From: fdai7910 Date: Mon, 5 Feb 2024 21:23:08 +0100 Subject: [PATCH 09/28] added randomFruit function to GameManager --- src/main/java/pacmanGame/GameManager.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/java/pacmanGame/GameManager.java b/src/main/java/pacmanGame/GameManager.java index 544b401..7f11a92 100644 --- a/src/main/java/pacmanGame/GameManager.java +++ b/src/main/java/pacmanGame/GameManager.java @@ -31,10 +31,10 @@ public class GameManager { player.Move(); } if(time == 300) { - spawnCherry(); + spawnFruit(); } if (time == 600) { - destroyCherry(); + destroyFruit(); } if(ghostIsEdible) { if(time == timeStopPillEffect) @@ -43,13 +43,19 @@ public class GameManager { time++; } - public void spawnCherry() { - map.GetCell(map.playerSpawn).type = "cherry"; + public void spawnFruit() { + map.GetCell(map.playerSpawn).type = randomFruit(); } - public void destroyCherry() { + public void destroyFruit() { map.GetCell(map.playerSpawn).type = "empty"; } + + public String randomFruit() { + String fruitTypes[] = {"cherry"}; + int randomNumber = (int) (Math. random() * fruitTypes.length); + return fruitTypes[randomNumber]; + } public void ProcessInput(char inputChar) { if(inputChar == 27) { From d1fc48f36d6bfe081d6f165b6ecc19dafb87d107 Mon Sep 17 00:00:00 2001 From: fdai7910 Date: Mon, 5 Feb 2024 21:33:52 +0100 Subject: [PATCH 10/28] added strawberry fruit type --- src/main/java/pacmanGame/Cell.java | 13 +++++++++++-- src/main/java/pacmanGame/GameManager.java | 6 +++--- src/main/java/pacmanGame/VisualizerPlainText.java | 1 + 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main/java/pacmanGame/Cell.java b/src/main/java/pacmanGame/Cell.java index f9cd74b..8c427b0 100644 --- a/src/main/java/pacmanGame/Cell.java +++ b/src/main/java/pacmanGame/Cell.java @@ -25,11 +25,16 @@ public class Cell { } - public void triggerFruit() { + public void triggerCherry() { this.type = "empty"; map.gameManager.score += 505; } + public void triggerStrawberry() { + this.type = "empty"; + map.gameManager.score += 405; + } + public void triggerItem() { if(type.equals("dot")) { triggerDot(); @@ -38,10 +43,14 @@ public class Cell { triggerPill(); } else if(type.equals("cherry")) { - triggerFruit(); + triggerCherry(); + } + else if(type.equals("strawberry")) { + triggerStrawberry(); } 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 7f11a92..c79f8e6 100644 --- a/src/main/java/pacmanGame/GameManager.java +++ b/src/main/java/pacmanGame/GameManager.java @@ -30,7 +30,7 @@ public class GameManager { if(time%5 == 0) { player.Move(); } - if(time == 300) { + if(time == 30) { spawnFruit(); } if (time == 600) { @@ -52,8 +52,8 @@ public class GameManager { } public String randomFruit() { - String fruitTypes[] = {"cherry"}; - int randomNumber = (int) (Math. random() * fruitTypes.length); + String fruitTypes[] = {"cherry","strawberry"}; + int randomNumber = (int) (Math. random() * (fruitTypes.length)); return fruitTypes[randomNumber]; } diff --git a/src/main/java/pacmanGame/VisualizerPlainText.java b/src/main/java/pacmanGame/VisualizerPlainText.java index 9bcc354..e5f315a 100644 --- a/src/main/java/pacmanGame/VisualizerPlainText.java +++ b/src/main/java/pacmanGame/VisualizerPlainText.java @@ -13,6 +13,7 @@ public class VisualizerPlainText implements Visualizer { this.put("dot", ". "); this.put("wall", "[]"); this.put("cherry", "OO"); + this.put("strawberry", "T7"); }}; public final String ghostSprite = "AA"; From fab9670220e5aa8ae3dd70020318f4b299cf58c7 Mon Sep 17 00:00:00 2001 From: fdai7910 Date: Mon, 5 Feb 2024 21:35:42 +0100 Subject: [PATCH 11/28] added test for strawberry --- src/test/java/pacmanTests/CellTest.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/test/java/pacmanTests/CellTest.java b/src/test/java/pacmanTests/CellTest.java index ca10733..ba78b06 100644 --- a/src/test/java/pacmanTests/CellTest.java +++ b/src/test/java/pacmanTests/CellTest.java @@ -50,5 +50,16 @@ class CellTest { assertThat(expectedScore).isEqualTo(resultingScore); } - + void cell_triggerItem_405strawberryScore() { + // arrange + GameManager gameManager = new GameManager(); + Cell cell = gameManager.map.GetCell(new Vector2(0,0)); + cell.type = "strawberry"; + int expectedScore = 405; + // act + cell.triggerItem(); + int resultingScore = gameManager.score; + // assert + assertThat(expectedScore).isEqualTo(resultingScore); + } } From 6a7147d683eef98036eadc5c275cf63fd75f6bd5 Mon Sep 17 00:00:00 2001 From: fdai7910 Date: Mon, 5 Feb 2024 21:37:42 +0100 Subject: [PATCH 12/28] added new orange fruit --- src/main/java/pacmanGame/Cell.java | 8 ++++++++ src/main/java/pacmanGame/GameManager.java | 2 +- src/main/java/pacmanGame/VisualizerPlainText.java | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/pacmanGame/Cell.java b/src/main/java/pacmanGame/Cell.java index 8c427b0..6e2ed06 100644 --- a/src/main/java/pacmanGame/Cell.java +++ b/src/main/java/pacmanGame/Cell.java @@ -35,6 +35,11 @@ public class Cell { map.gameManager.score += 405; } + public void triggerOrange() { + this.type = "empty"; + map.gameManager.score += 305; + } + public void triggerItem() { if(type.equals("dot")) { triggerDot(); @@ -48,6 +53,9 @@ public class Cell { else if(type.equals("strawberry")) { triggerStrawberry(); } + else if(type.equals("orange")) { + triggerStrawberry(); + } 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 c79f8e6..af69fb1 100644 --- a/src/main/java/pacmanGame/GameManager.java +++ b/src/main/java/pacmanGame/GameManager.java @@ -52,7 +52,7 @@ public class GameManager { } public String randomFruit() { - String fruitTypes[] = {"cherry","strawberry"}; + String fruitTypes[] = {"cherry","strawberry","orange"}; int randomNumber = (int) (Math. random() * (fruitTypes.length)); return fruitTypes[randomNumber]; } diff --git a/src/main/java/pacmanGame/VisualizerPlainText.java b/src/main/java/pacmanGame/VisualizerPlainText.java index e5f315a..283d761 100644 --- a/src/main/java/pacmanGame/VisualizerPlainText.java +++ b/src/main/java/pacmanGame/VisualizerPlainText.java @@ -14,6 +14,7 @@ public class VisualizerPlainText implements Visualizer { this.put("wall", "[]"); this.put("cherry", "OO"); this.put("strawberry", "T7"); + this.put("orange", "CO"); }}; public final String ghostSprite = "AA"; From af6645d5f281fe7d6ac64819a2691dc8bf771830 Mon Sep 17 00:00:00 2001 From: fdai7910 Date: Mon, 5 Feb 2024 21:38:36 +0100 Subject: [PATCH 13/28] added test for orange --- src/test/java/pacmanTests/CellTest.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/test/java/pacmanTests/CellTest.java b/src/test/java/pacmanTests/CellTest.java index ba78b06..e22e328 100644 --- a/src/test/java/pacmanTests/CellTest.java +++ b/src/test/java/pacmanTests/CellTest.java @@ -62,4 +62,16 @@ class CellTest { // assert assertThat(expectedScore).isEqualTo(resultingScore); } + void cell_triggerItem_305orangeScore() { + // arrange + GameManager gameManager = new GameManager(); + Cell cell = gameManager.map.GetCell(new Vector2(0,0)); + cell.type = "orange"; + int expectedScore = 305; + // act + cell.triggerItem(); + int resultingScore = gameManager.score; + // assert + assertThat(expectedScore).isEqualTo(resultingScore); + } } From 379414258fe4c8215714711712699a695af528e7 Mon Sep 17 00:00:00 2001 From: fdai7910 Date: Mon, 5 Feb 2024 21:41:26 +0100 Subject: [PATCH 14/28] added new fruit apple --- src/main/java/pacmanGame/Cell.java | 10 +++++++++- src/main/java/pacmanGame/GameManager.java | 4 ++-- src/main/java/pacmanGame/VisualizerPlainText.java | 1 + 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/pacmanGame/Cell.java b/src/main/java/pacmanGame/Cell.java index 6e2ed06..23f698e 100644 --- a/src/main/java/pacmanGame/Cell.java +++ b/src/main/java/pacmanGame/Cell.java @@ -40,6 +40,11 @@ public class Cell { map.gameManager.score += 305; } + public void triggerApple() { + this.type = "empty"; + map.gameManager.score += 205; + } + public void triggerItem() { if(type.equals("dot")) { triggerDot(); @@ -54,7 +59,10 @@ public class Cell { triggerStrawberry(); } else if(type.equals("orange")) { - triggerStrawberry(); + triggerOrange(); + } + else if(type.equals("apple")) { + triggerApple(); } 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 af69fb1..db231b4 100644 --- a/src/main/java/pacmanGame/GameManager.java +++ b/src/main/java/pacmanGame/GameManager.java @@ -30,7 +30,7 @@ public class GameManager { if(time%5 == 0) { player.Move(); } - if(time == 30) { + if(time == 300) { spawnFruit(); } if (time == 600) { @@ -52,7 +52,7 @@ public class GameManager { } public String randomFruit() { - String fruitTypes[] = {"cherry","strawberry","orange"}; + String fruitTypes[] = {"cherry","strawberry","orange","apple"}; int randomNumber = (int) (Math. random() * (fruitTypes.length)); return fruitTypes[randomNumber]; } diff --git a/src/main/java/pacmanGame/VisualizerPlainText.java b/src/main/java/pacmanGame/VisualizerPlainText.java index 283d761..527e711 100644 --- a/src/main/java/pacmanGame/VisualizerPlainText.java +++ b/src/main/java/pacmanGame/VisualizerPlainText.java @@ -15,6 +15,7 @@ public class VisualizerPlainText implements Visualizer { this.put("cherry", "OO"); this.put("strawberry", "T7"); this.put("orange", "CO"); + this.put("apple", "@ "); }}; public final String ghostSprite = "AA"; From 0f58fd0680c22ccdee7810f15c6b12872642eb1a Mon Sep 17 00:00:00 2001 From: fdai7910 Date: Mon, 5 Feb 2024 21:42:24 +0100 Subject: [PATCH 15/28] added test for apple --- src/test/java/pacmanTests/CellTest.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/test/java/pacmanTests/CellTest.java b/src/test/java/pacmanTests/CellTest.java index e22e328..afa318c 100644 --- a/src/test/java/pacmanTests/CellTest.java +++ b/src/test/java/pacmanTests/CellTest.java @@ -74,4 +74,17 @@ class CellTest { // assert assertThat(expectedScore).isEqualTo(resultingScore); } + + void cell_triggerItem_205appleScore() { + // arrange + GameManager gameManager = new GameManager(); + Cell cell = gameManager.map.GetCell(new Vector2(0,0)); + cell.type = "apple"; + int expectedScore = 205; + // act + cell.triggerItem(); + int resultingScore = gameManager.score; + // assert + assertThat(expectedScore).isEqualTo(resultingScore); + } } From 9b36ee55f4f12d48d0c692eeb4282c59223905ed Mon Sep 17 00:00:00 2001 From: fdai7910 Date: Mon, 5 Feb 2024 21:55:11 +0100 Subject: [PATCH 16/28] added game restart key --- src/main/java/pacmanGame/GameManager.java | 6 ++++-- src/main/java/pacmanGame/Player.java | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/pacmanGame/GameManager.java b/src/main/java/pacmanGame/GameManager.java index db231b4..02c15a4 100644 --- a/src/main/java/pacmanGame/GameManager.java +++ b/src/main/java/pacmanGame/GameManager.java @@ -9,12 +9,14 @@ public class GameManager { public int score = 0; public boolean ghostIsEdible = false; public int timeStopPillEffect; + public int moveSpeed = 5; public GameManager() { setupGame(); } public void setupGame(){ + time = 0; map = new Map(Map.mapClassic,this); visualizer = new VisualizerPlainText(this); player = new Player(this); @@ -27,7 +29,7 @@ public class GameManager { public void Update() { visualizer.Update(); - if(time%5 == 0) { + if(time%moveSpeed == 0) { player.Move(); } if(time == 300) { @@ -61,7 +63,7 @@ public class GameManager { if(inputChar == 27) { //todo: escape key pauses game } - else if (inputChar == 'w' || inputChar == 's' || inputChar == 'd' || inputChar == 'a') { + else if (inputChar == 'w' || inputChar == 's' || inputChar == 'd' || inputChar == 'a' || inputChar == 'r') { player.processInput(inputChar); } else { diff --git a/src/main/java/pacmanGame/Player.java b/src/main/java/pacmanGame/Player.java index 411f504..3731680 100644 --- a/src/main/java/pacmanGame/Player.java +++ b/src/main/java/pacmanGame/Player.java @@ -48,6 +48,9 @@ public class Player { else if(inputchar == 'a') { checkInput(new Vector2(-1,0)); } + else if(inputchar == 'r') { + gameManager.setupGame(); + } } From 2954a0c8667c70e6f6257cd129d78b4b94928831 Mon Sep 17 00:00:00 2001 From: fdai7910 Date: Mon, 5 Feb 2024 22:16:56 +0100 Subject: [PATCH 17/28] fixed nullPointerException in Cell --- src/main/java/pacmanGame/Cell.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/pacmanGame/Cell.java b/src/main/java/pacmanGame/Cell.java index 23f698e..ddafff3 100644 --- a/src/main/java/pacmanGame/Cell.java +++ b/src/main/java/pacmanGame/Cell.java @@ -19,9 +19,9 @@ public class Cell { public void triggerPill() { this.type = "empty"; - gameManager.score += 100; - gameManager.timeStopPillEffect = gameManager.time + 200; - gameManager.ghostIsEdible = true; + map.gameManager.score += 100; + map.gameManager.timeStopPillEffect = map.gameManager.time + 200; + map.gameManager.ghostIsEdible = true; } @@ -45,6 +45,8 @@ public class Cell { map.gameManager.score += 205; } + + public void triggerItem() { if(type.equals("dot")) { triggerDot(); @@ -64,6 +66,7 @@ public class Cell { else if(type.equals("apple")) { triggerApple(); } + else { //System.out.println("cell contains no item!"); } From 012e6215880b970b7d2d86a8f24cf064987572be Mon Sep 17 00:00:00 2001 From: fdai7910 Date: Mon, 5 Feb 2024 22:18:18 +0100 Subject: [PATCH 18/28] added new crystal fruit --- src/main/java/pacmanGame/Cell.java | 10 ++++++++-- src/main/java/pacmanGame/GameManager.java | 5 +++-- src/main/java/pacmanGame/VisualizerPlainText.java | 1 + 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/pacmanGame/Cell.java b/src/main/java/pacmanGame/Cell.java index ddafff3..0607d20 100644 --- a/src/main/java/pacmanGame/Cell.java +++ b/src/main/java/pacmanGame/Cell.java @@ -44,8 +44,11 @@ public class Cell { this.type = "empty"; map.gameManager.score += 205; } - - + public void triggerCrystal() { + this.type = "empty"; + map.gameManager.score += 506; + map.gameManager.moveSpeed = 3; + } public void triggerItem() { if(type.equals("dot")) { @@ -66,6 +69,9 @@ public class Cell { else if(type.equals("apple")) { triggerApple(); } + else if(type.equals("crystal")) { + triggerCrystal(); + } 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 02c15a4..5206599 100644 --- a/src/main/java/pacmanGame/GameManager.java +++ b/src/main/java/pacmanGame/GameManager.java @@ -9,7 +9,7 @@ public class GameManager { public int score = 0; public boolean ghostIsEdible = false; public int timeStopPillEffect; - public int moveSpeed = 5; + public int moveSpeed; public GameManager() { setupGame(); @@ -17,6 +17,7 @@ public class GameManager { public void setupGame(){ time = 0; + moveSpeed = 5; map = new Map(Map.mapClassic,this); visualizer = new VisualizerPlainText(this); player = new Player(this); @@ -54,7 +55,7 @@ public class GameManager { } public String randomFruit() { - String fruitTypes[] = {"cherry","strawberry","orange","apple"}; + String fruitTypes[] = {"cherry","strawberry","orange","apple","crystal"}; int randomNumber = (int) (Math. random() * (fruitTypes.length)); return fruitTypes[randomNumber]; } diff --git a/src/main/java/pacmanGame/VisualizerPlainText.java b/src/main/java/pacmanGame/VisualizerPlainText.java index 527e711..d7c2ea3 100644 --- a/src/main/java/pacmanGame/VisualizerPlainText.java +++ b/src/main/java/pacmanGame/VisualizerPlainText.java @@ -16,6 +16,7 @@ public class VisualizerPlainText implements Visualizer { this.put("strawberry", "T7"); this.put("orange", "CO"); this.put("apple", "@ "); + this.put("crystal", "<>"); }}; public final String ghostSprite = "AA"; From 31cb38ac08cf4e5709ea607c31478d8c9c00db3d Mon Sep 17 00:00:00 2001 From: fdai7910 Date: Mon, 5 Feb 2024 22:20:29 +0100 Subject: [PATCH 19/28] added test for moveSpeed change by crystal fruit --- src/test/java/pacmanTests/CellTest.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/test/java/pacmanTests/CellTest.java b/src/test/java/pacmanTests/CellTest.java index afa318c..790f5ed 100644 --- a/src/test/java/pacmanTests/CellTest.java +++ b/src/test/java/pacmanTests/CellTest.java @@ -87,4 +87,17 @@ class CellTest { // assert assertThat(expectedScore).isEqualTo(resultingScore); } + + void cell_triggerItem_3crystalMoveSpeed() { + // arrange + GameManager gameManager = new GameManager(); + Cell cell = gameManager.map.GetCell(new Vector2(0,0)); + cell.type = "crystal"; + int expectedMoveSpeed = 3; + // act + cell.triggerItem(); + int resultingMoveSpeed = gameManager.moveSpeed; + // assert + assertThat(expectedMoveSpeed).isEqualTo(resultingMoveSpeed); + } } From 4ec117fe7db5aeda68beebf662336b15384af103 Mon Sep 17 00:00:00 2001 From: fdai7910 Date: Mon, 5 Feb 2024 22:25:28 +0100 Subject: [PATCH 20/28] refactoring: removed spaces in Cell --- src/main/java/pacmanGame/Cell.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/pacmanGame/Cell.java b/src/main/java/pacmanGame/Cell.java index 0607d20..7e85d0c 100644 --- a/src/main/java/pacmanGame/Cell.java +++ b/src/main/java/pacmanGame/Cell.java @@ -22,7 +22,6 @@ public class Cell { map.gameManager.score += 100; map.gameManager.timeStopPillEffect = map.gameManager.time + 200; map.gameManager.ghostIsEdible = true; - } public void triggerCherry() { From 0a380cea3341d19b2579961f48825aac3b9e84ce Mon Sep 17 00:00:00 2001 From: fdai7910 Date: Wed, 7 Feb 2024 23:07:11 +0100 Subject: [PATCH 21/28] made pills spawnable in Map --- src/main/java/pacmanGame/Map.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/pacmanGame/Map.java b/src/main/java/pacmanGame/Map.java index 40ab6aa..5e119f9 100644 --- a/src/main/java/pacmanGame/Map.java +++ b/src/main/java/pacmanGame/Map.java @@ -10,7 +10,7 @@ public class Map { "wwwwwwwwwwwwwwwwwwwwwwwwwwwwww", "ww............ww............ww", "ww.wwww.wwwww.ww.wwwww.wwww.ww", - "ww.wwww.wwwww.ww.wwwww.wwww.ww", + "wwpwwww.wwwww.ww.wwwww.wwwwpww", "ww.wwww.wwwww.ww.wwwww.wwww.ww", "ww..........................ww", "ww.wwww.ww.wwwwwwww.ww.wwww.ww", @@ -30,7 +30,7 @@ public class Map { "ww............ww............ww", "ww.wwww.wwwww.ww.wwwww.wwww.ww", "ww.wwww.wwwww.ww.wwwww.wwww.ww", - "ww...ww.......s........ww...ww", + "wwp..ww.......s........ww..pww", "wwww.ww.ww.wwwwwwww.ww.ww.wwww", "wwww.ww.ww.wwwwwwww.ww.ww.wwww", "ww......ww....ww....ww......ww", @@ -46,6 +46,7 @@ public class Map { this.put("s", "empty"); this.put(".", "dot"); this.put("w", "wall"); + this.put("p", "pill"); }}; public Cell[][] cells; From eaadc4229a5883890530159d5c7a58ad92c90a93 Mon Sep 17 00:00:00 2001 From: fdai7910 Date: Wed, 7 Feb 2024 23:10:50 +0100 Subject: [PATCH 22/28] added visualization for pill 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 d7c2ea3..41ee414 100644 --- a/src/main/java/pacmanGame/VisualizerPlainText.java +++ b/src/main/java/pacmanGame/VisualizerPlainText.java @@ -17,6 +17,7 @@ public class VisualizerPlainText implements Visualizer { this.put("orange", "CO"); this.put("apple", "@ "); this.put("crystal", "<>"); + this.put("pill", "o "); }}; public final String ghostSprite = "AA"; From 7380944cfcce14838aa0e0c4431ed339a7c6ae07 Mon Sep 17 00:00:00 2001 From: fdai7910 Date: Thu, 8 Feb 2024 00:13:03 +0100 Subject: [PATCH 23/28] added findCellByString method to Map --- src/main/java/pacmanGame/Map.java | 126 ++++++++++++++---------------- 1 file changed, 59 insertions(+), 67 deletions(-) diff --git a/src/main/java/pacmanGame/Map.java b/src/main/java/pacmanGame/Map.java index 5e119f9..b9d45d4 100644 --- a/src/main/java/pacmanGame/Map.java +++ b/src/main/java/pacmanGame/Map.java @@ -3,98 +3,90 @@ package pacmanGame; import java.util.HashMap; public class Map { - + public final GameManager gameManager; - public static String[] mapClassic = { - "wwwwwwwwwwwwwwwwwwwwwwwwwwwwww", - "wwwwwwwwwwwwwwwwwwwwwwwwwwwwww", - "ww............ww............ww", - "ww.wwww.wwwww.ww.wwwww.wwww.ww", - "wwpwwww.wwwww.ww.wwwww.wwwwpww", - "ww.wwww.wwwww.ww.wwwww.wwww.ww", - "ww..........................ww", - "ww.wwww.ww.wwwwwwww.ww.wwww.ww", - "ww.wwww.ww.wwwwwwww.ww.wwww.ww", - "ww......ww....ww....ww......ww", - "wwwwwww.wwwwwewwewwwww.wwwwwww", - "wwwwwww.wwwwwewwewwwww.wwwwwww", - "wwwwwww.wweeeeeeeeeeww.wwwwwww", - "wwwwwww.wwewwwwwwwweww.wwwwwww", - "wwwwwww.wweweeeeeeweww.wwwwwww", - "eeeeeee.eeeweeeeeeweee.eeeeeee", - "wwwwwww.wweweeeeeeweww.wwwwwww", - "wwwwwww.wweweeeeeeweww.wwwwwww", - "wwwwwww.wwewwwwwwwweww.wwwwwww", - "wwwwwww.wweeeeeeeeeeww.wwwwwww", - "wwwwwww.wwewwwwwwwweww.wwwwwww", - "ww............ww............ww", - "ww.wwww.wwwww.ww.wwwww.wwww.ww", - "ww.wwww.wwwww.ww.wwwww.wwww.ww", - "wwp..ww.......s........ww..pww", - "wwww.ww.ww.wwwwwwww.ww.ww.wwww", - "wwww.ww.ww.wwwwwwww.ww.ww.wwww", - "ww......ww....ww....ww......ww", - "ww.wwwwwwwwww.ww.wwwwwwwwww.ww", - "ww.wwwwwwwwww.ww.wwwwwwwwww.ww", - "ww..........................ww", - "wwwwwwwwwwwwwwwwwwwwwwwwwwwwww", - "wwwwwwwwwwwwwwwwwwwwwwwwwwwwww" - }; - - public final HashMap mapTypes = new HashMap(){{ - this.put("e", "empty"); - this.put("s", "empty"); - this.put(".", "dot"); - this.put("w", "wall"); - this.put("p", "pill"); - }}; - + public static String[] mapClassic = { "wwwwwwwwwwwwwwwwwwwwwwwwwwwwww", "wwwwwwwwwwwwwwwwwwwwwwwwwwwwww", + "ww............ww............ww", "ww.wwww.wwwww.ww.wwwww.wwww.ww", "wwpwwww.wwwww.ww.wwwww.wwwwpww", + "ww.wwww.wwwww.ww.wwwww.wwww.ww", "ww..........................ww", "ww.wwww.ww.wwwwwwww.ww.wwww.ww", + "ww.wwww.ww.wwwwwwww.ww.wwww.ww", "ww......ww....ww....ww......ww", "wwwwwww.wwwwwewwewwwww.wwwwwww", + "wwwwwww.wwwwwewwewwwww.wwwwwww", "wwwwwww.wweeeeeeeeeeww.wwwwwww", "wwwwwww.wwewwwwwwwweww.wwwwwww", + "wwwwwww.wweweeeeeeweww.wwwwwww", "Teeeeee.eeeweeeeeeweee.eeeeeet", "wwwwwww.wweweeeeeeweww.wwwwwww", + "wwwwwww.wweweeeeeeweww.wwwwwww", "wwwwwww.wwewwwwwwwweww.wwwwwww", "wwwwwww.wweeeeeeeeeeww.wwwwwww", + "wwwwwww.wwewwwwwwwweww.wwwwwww", "ww............ww............ww", "ww.wwww.wwwww.ww.wwwww.wwww.ww", + "ww.wwww.wwwww.ww.wwwww.wwww.ww", "wwp..ww.......s........ww..pww", "wwww.ww.ww.wwwwwwww.ww.ww.wwww", + "wwww.ww.ww.wwwwwwww.ww.ww.wwww", "ww......ww....ww....ww......ww", "ww.wwwwwwwwww.ww.wwwwwwwwww.ww", + "ww.wwwwwwwwww.ww.wwwwwwwwww.ww", "ww..........................ww", "wwwwwwwwwwwwwwwwwwwwwwwwwwwwww", + "wwwwwwwwwwwwwwwwwwwwwwwwwwwwww" }; + + public final HashMap mapTypes = new HashMap() { + { + this.put("e", "empty"); + this.put("s", "empty"); + this.put(".", "dot"); + this.put("w", "wall"); + this.put("p", "pill"); + this.put("T", "tpLeft"); + this.put("t", "tpRight"); + } + }; + public Cell[][] cells; public Vector2 size; - - public Vector2 playerSpawn = new Vector2(2,2); + + public Vector2 playerSpawn = new Vector2(2, 2); public char playerSpawnChar = 's'; - + public Map(String[] mapData, GameManager gameManager) { GenerateMap(mapData); this.gameManager = gameManager; } public void GenerateMap(String[] mapData) { - + int sizeY = mapData.length; int sizeX = mapData[0].length(); - + size = new Vector2(sizeX, sizeY); - + cells = new Cell[size.x][size.y]; - - for(int x = 0; x < size.x; x++) { - for(int y = 0; y < size.y; y++) { - Vector2 cellPos = new Vector2(x,y); + + for (int x = 0; x < size.x; x++) { + for (int y = 0; y < size.y; y++) { + Vector2 cellPos = new Vector2(x, y); char cellChar = mapData[size.y - 1 - y].charAt(x); - + String cellType = mapTypes.get(String.valueOf(cellChar)); - + cells[x][y] = new Cell(cellPos, cellType, this); - - if(cellChar == playerSpawnChar) { + + if (cellChar == playerSpawnChar) { playerSpawn = cellPos.Clone(); } - } + } } } public Cell GetCell(Vector2 pos) { - if(pos.isWithin(size)) { - - return cells[pos.x][pos.y]; + if (pos.isWithin(size)) { + + return cells[pos.x][pos.y]; + } else { + + return cells[0][0]; } - else { - - return cells[0][0]; + + } + + public Cell findCellByString(String target) { + for (int x = 0; x < size.x; x++) { + for (int y = 0; y < size.y; y++) { + if (cells[x][y].type == target) { + return cells[x][y]; + } + } } - + + return null; } } From c4d577bfb2881673326df8ccb2e86e9820f45ce2 Mon Sep 17 00:00:00 2001 From: fdai7910 Date: Thu, 8 Feb 2024 00:38:15 +0100 Subject: [PATCH 24/28] fixed findCellByString funcition in Map --- src/main/java/pacmanGame/Map.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/pacmanGame/Map.java b/src/main/java/pacmanGame/Map.java index b9d45d4..b53711e 100644 --- a/src/main/java/pacmanGame/Map.java +++ b/src/main/java/pacmanGame/Map.java @@ -81,12 +81,12 @@ public class Map { public Cell findCellByString(String target) { for (int x = 0; x < size.x; x++) { for (int y = 0; y < size.y; y++) { - if (cells[x][y].type == target) { + if (cells[x][y].type.equals(target)) { return cells[x][y]; } } } - + System.out.println("couldnt find cell " + target); return null; } } From 4a084f1cc3e20bf0e43c0c82cf852ee971af47bd Mon Sep 17 00:00:00 2001 From: fdai7910 Date: Thu, 8 Feb 2024 00:39:48 +0100 Subject: [PATCH 25/28] refactoring: changed mapClassic string array for easier reading --- src/main/java/pacmanGame/Map.java | 44 +++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/src/main/java/pacmanGame/Map.java b/src/main/java/pacmanGame/Map.java index b53711e..c6e279f 100644 --- a/src/main/java/pacmanGame/Map.java +++ b/src/main/java/pacmanGame/Map.java @@ -5,17 +5,39 @@ import java.util.HashMap; public class Map { public final GameManager gameManager; - public static String[] mapClassic = { "wwwwwwwwwwwwwwwwwwwwwwwwwwwwww", "wwwwwwwwwwwwwwwwwwwwwwwwwwwwww", - "ww............ww............ww", "ww.wwww.wwwww.ww.wwwww.wwww.ww", "wwpwwww.wwwww.ww.wwwww.wwwwpww", - "ww.wwww.wwwww.ww.wwwww.wwww.ww", "ww..........................ww", "ww.wwww.ww.wwwwwwww.ww.wwww.ww", - "ww.wwww.ww.wwwwwwww.ww.wwww.ww", "ww......ww....ww....ww......ww", "wwwwwww.wwwwwewwewwwww.wwwwwww", - "wwwwwww.wwwwwewwewwwww.wwwwwww", "wwwwwww.wweeeeeeeeeeww.wwwwwww", "wwwwwww.wwewwwwwwwweww.wwwwwww", - "wwwwwww.wweweeeeeeweww.wwwwwww", "Teeeeee.eeeweeeeeeweee.eeeeeet", "wwwwwww.wweweeeeeeweww.wwwwwww", - "wwwwwww.wweweeeeeeweww.wwwwwww", "wwwwwww.wwewwwwwwwweww.wwwwwww", "wwwwwww.wweeeeeeeeeeww.wwwwwww", - "wwwwwww.wwewwwwwwwweww.wwwwwww", "ww............ww............ww", "ww.wwww.wwwww.ww.wwwww.wwww.ww", - "ww.wwww.wwwww.ww.wwwww.wwww.ww", "wwp..ww.......s........ww..pww", "wwww.ww.ww.wwwwwwww.ww.ww.wwww", - "wwww.ww.ww.wwwwwwww.ww.ww.wwww", "ww......ww....ww....ww......ww", "ww.wwwwwwwwww.ww.wwwwwwwwww.ww", - "ww.wwwwwwwwww.ww.wwwwwwwwww.ww", "ww..........................ww", "wwwwwwwwwwwwwwwwwwwwwwwwwwwwww", + public static String[] mapClassic = { + "wwwwwwwwwwwwwwwwwwwwwwwwwwwwww", + "wwwwwwwwwwwwwwwwwwwwwwwwwwwwww", + "ww............ww............ww", + "ww.wwww.wwwww.ww.wwwww.wwww.ww", + "wwpwwww.wwwww.ww.wwwww.wwwwpww", + "ww.wwww.wwwww.ww.wwwww.wwww.ww", + "ww..........................ww", + "ww.wwww.ww.wwwwwwww.ww.wwww.ww", + "ww.wwww.ww.wwwwwwww.ww.wwww.ww", + "ww......ww....ww....ww......ww", + "wwwwwww.wwwwwewwewwwww.wwwwwww", + "wwwwwww.wwwwwewwewwwww.wwwwwww", + "wwwwwww.wweeeeeeeeeeww.wwwwwww", + "wwwwwww.wwewwwwwwwweww.wwwwwww", + "wwwwwww.wweweeeeeeweww.wwwwwww", + "Teeeeee.eeeweeeeeeweee.eeeeeet", + "wwwwwww.wweweeeeeeweww.wwwwwww", + "wwwwwww.wweweeeeeeweww.wwwwwww", + "wwwwwww.wwewwwwwwwweww.wwwwwww", + "wwwwwww.wweeeeeeeeeeww.wwwwwww", + "wwwwwww.wwewwwwwwwweww.wwwwwww", + "ww............ww............ww", + "ww.wwww.wwwww.ww.wwwww.wwww.ww", + "ww.wwww.wwwww.ww.wwwww.wwww.ww", + "wwp..ww.......s........ww..pww", + "wwww.ww.ww.wwwwwwww.ww.ww.wwww", + "wwww.ww.ww.wwwwwwww.ww.ww.wwww", + "ww......ww....ww....ww......ww", + "ww.wwwwwwwwww.ww.wwwwwwwwww.ww", + "ww.wwwwwwwwww.ww.wwwwwwwwww.ww", + "ww..........................ww", + "wwwwwwwwwwwwwwwwwwwwwwwwwwwwww", "wwwwwwwwwwwwwwwwwwwwwwwwwwwwww" }; public final HashMap mapTypes = new HashMap() { From c96fa7b4bca9ba27e35c23088e163579917ee967 Mon Sep 17 00:00:00 2001 From: fdai7910 Date: Thu, 8 Feb 2024 00:40:50 +0100 Subject: [PATCH 26/28] added ability for player to teleport in the tunnel --- src/main/java/pacmanGame/Cell.java | 6 ++++++ src/main/java/pacmanGame/GameManager.java | 6 ++++++ src/main/java/pacmanGame/VisualizerPlainText.java | 2 ++ 3 files changed, 14 insertions(+) diff --git a/src/main/java/pacmanGame/Cell.java b/src/main/java/pacmanGame/Cell.java index 7e85d0c..ce5247e 100644 --- a/src/main/java/pacmanGame/Cell.java +++ b/src/main/java/pacmanGame/Cell.java @@ -71,6 +71,12 @@ public class Cell { else if(type.equals("crystal")) { triggerCrystal(); } + else if(type.equals("tpLeft")) { + map.gameManager.teleportPlayer("tpRight"); + } + else if(type.equals("tpRight")) { + map.gameManager.teleportPlayer("tpLeft"); + } 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 5206599..b27edfb 100644 --- a/src/main/java/pacmanGame/GameManager.java +++ b/src/main/java/pacmanGame/GameManager.java @@ -72,6 +72,12 @@ public class GameManager { } } + public void teleportPlayer(String destination) { + + player.position = map.findCellByString(destination).pos; + + } + public boolean GhostPlayerColisionTest() { for(int i = 0; i < ghosts.length; i++) { diff --git a/src/main/java/pacmanGame/VisualizerPlainText.java b/src/main/java/pacmanGame/VisualizerPlainText.java index 41ee414..d61ec1a 100644 --- a/src/main/java/pacmanGame/VisualizerPlainText.java +++ b/src/main/java/pacmanGame/VisualizerPlainText.java @@ -18,6 +18,8 @@ public class VisualizerPlainText implements Visualizer { this.put("apple", "@ "); this.put("crystal", "<>"); this.put("pill", "o "); + this.put("tpRight" , " "); + this.put("tpLeft" , " "); }}; public final String ghostSprite = "AA"; From 755039e1a19b612e6c0a0b4a8ba53c4e76dd74b2 Mon Sep 17 00:00:00 2001 From: fdai7910 Date: Thu, 8 Feb 2024 00:49:41 +0100 Subject: [PATCH 27/28] fixed tests in CellTest --- src/test/java/pacmanTests/CellTest.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/test/java/pacmanTests/CellTest.java b/src/test/java/pacmanTests/CellTest.java index 790f5ed..4d58241 100644 --- a/src/test/java/pacmanTests/CellTest.java +++ b/src/test/java/pacmanTests/CellTest.java @@ -24,6 +24,7 @@ class CellTest { assertThat(expectedScore).isEqualTo(resultingScore); } + @Test void cell_triggerItem_10dotScore() { // arrange GameManager gameManager = new GameManager(); @@ -36,7 +37,8 @@ class CellTest { // assert assertThat(expectedScore).isEqualTo(resultingScore); } - + + @Test void cell_triggerItem_100pillScore() { // arrange GameManager gameManager = new GameManager(); @@ -49,7 +51,8 @@ class CellTest { // assert assertThat(expectedScore).isEqualTo(resultingScore); } - + + @Test void cell_triggerItem_405strawberryScore() { // arrange GameManager gameManager = new GameManager(); @@ -62,6 +65,8 @@ class CellTest { // assert assertThat(expectedScore).isEqualTo(resultingScore); } + + @Test void cell_triggerItem_305orangeScore() { // arrange GameManager gameManager = new GameManager(); @@ -74,7 +79,8 @@ class CellTest { // assert assertThat(expectedScore).isEqualTo(resultingScore); } - + + @Test void cell_triggerItem_205appleScore() { // arrange GameManager gameManager = new GameManager(); @@ -87,7 +93,8 @@ class CellTest { // assert assertThat(expectedScore).isEqualTo(resultingScore); } - + + @Test void cell_triggerItem_3crystalMoveSpeed() { // arrange GameManager gameManager = new GameManager(); From 2f409d259e760fd9dbe966f6ca4eef061a16b899 Mon Sep 17 00:00:00 2001 From: fdai7910 Date: Thu, 8 Feb 2024 00:56:13 +0100 Subject: [PATCH 28/28] added Test for findCellByString --- src/test/java/pacmanTests/MapTest.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/test/java/pacmanTests/MapTest.java b/src/test/java/pacmanTests/MapTest.java index f94d0bd..57fe927 100644 --- a/src/test/java/pacmanTests/MapTest.java +++ b/src/test/java/pacmanTests/MapTest.java @@ -58,4 +58,22 @@ class MapTest { assertThat(expectedMiddle).isEqualTo(middle); assertThat(expectedBottomRight).isEqualTo(bottomRight); } + + @Test + void Map_findCellByString_cellT() { + // arrange + String[] mapTest = { + "wew", + "w.t", + "ee." + }; + GameManager gameManager = new GameManager(); + gameManager.map = new Map(mapTest, gameManager); + Map testMap = gameManager.map; + Cell expectedT = testMap.cells[2][1]; + // act + Cell foundT = testMap.findCellByString("tpRight"); + // assert + assertThat(expectedT).isEqualTo(foundT); + } }