From 531a97a1d2a091d693d3355a651f725b4ab4957a Mon Sep 17 00:00:00 2001 From: fdai2751 Date: Wed, 7 Feb 2024 22:58:56 +0100 Subject: [PATCH 01/12] refactoring: interface changed --- src/main/java/pacmanGame/GhostBehavior.java | 2 +- src/main/java/pacmanGame/GhostBehaviorChase.java | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/main/java/pacmanGame/GhostBehavior.java b/src/main/java/pacmanGame/GhostBehavior.java index 5d0cacd..bad3e66 100644 --- a/src/main/java/pacmanGame/GhostBehavior.java +++ b/src/main/java/pacmanGame/GhostBehavior.java @@ -1,7 +1,7 @@ package pacmanGame; public interface GhostBehavior { - public Vector2 GetDirection(); + public Vector2 GetDirection(Ghost ghost); } diff --git a/src/main/java/pacmanGame/GhostBehaviorChase.java b/src/main/java/pacmanGame/GhostBehaviorChase.java index ea698e6..e505fca 100644 --- a/src/main/java/pacmanGame/GhostBehaviorChase.java +++ b/src/main/java/pacmanGame/GhostBehaviorChase.java @@ -1,14 +1,10 @@ package pacmanGame; public class GhostBehaviorChase implements GhostBehavior { - public final Ghost ghost; - public GhostBehaviorChase(Ghost ghost) { - this.ghost = ghost; - } - @Override - public Vector2 GetDirection() { + public Vector2 GetDirection(Ghost ghost) { + return null; } From 69f420c0d8b88a1d79ae3381a0e0ba5ec86fc04a Mon Sep 17 00:00:00 2001 From: fdai2751 Date: Wed, 7 Feb 2024 23:00:43 +0100 Subject: [PATCH 02/12] added the class Ghostbehavior random --- src/main/java/pacmanGame/GhostBehaviorRandom.java | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/main/java/pacmanGame/GhostBehaviorRandom.java diff --git a/src/main/java/pacmanGame/GhostBehaviorRandom.java b/src/main/java/pacmanGame/GhostBehaviorRandom.java new file mode 100644 index 0000000..492892c --- /dev/null +++ b/src/main/java/pacmanGame/GhostBehaviorRandom.java @@ -0,0 +1,11 @@ +package pacmanGame; +import java.util.Random; +public class GhostBehaviorRandom implements GhostBehavior { + + @Override + public Vector2 GetDirection(Ghost ghost) { + + return null; + } + +} From f74ae35758a92d3316b2a80c34e2c42942e2c874 Mon Sep 17 00:00:00 2001 From: fdai2751 Date: Wed, 7 Feb 2024 23:03:35 +0100 Subject: [PATCH 03/12] added funtion Gohst moving in random stage --- src/main/java/pacmanGame/GhostBehaviorRandom.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/pacmanGame/GhostBehaviorRandom.java b/src/main/java/pacmanGame/GhostBehaviorRandom.java index 492892c..d461501 100644 --- a/src/main/java/pacmanGame/GhostBehaviorRandom.java +++ b/src/main/java/pacmanGame/GhostBehaviorRandom.java @@ -4,7 +4,20 @@ public class GhostBehaviorRandom implements GhostBehavior { @Override public Vector2 GetDirection(Ghost ghost) { - + Random random = new Random(); + int direction = random.nextInt(4); + switch(direction) { + case 0: //oben + return new Vector2(0,1); + case 1: //unten + return new Vector2(0,-1); + case 2:// links + return new Vector2(-1,0); + case 3: //rechts + return new Vector2(1,0); + default: + break; + } return null; } From 841238de2e0925f97674d66386392471770eacea Mon Sep 17 00:00:00 2001 From: fdai2751 Date: Thu, 8 Feb 2024 00:48:54 +0100 Subject: [PATCH 04/12] added the move function for Ghost in GameManager class and Ghost move in random stage --- src/main/java/pacmanGame/GameManager.java | 3 +++ src/main/java/pacmanGame/Ghost.java | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/pacmanGame/GameManager.java b/src/main/java/pacmanGame/GameManager.java index 9d79ebd..0063ad3 100644 --- a/src/main/java/pacmanGame/GameManager.java +++ b/src/main/java/pacmanGame/GameManager.java @@ -33,6 +33,9 @@ public class GameManager { visualizer.Update(); if(time%5 == 0) { player.Move(); + for(int i = 0; i Date: Thu, 8 Feb 2024 00:52:44 +0100 Subject: [PATCH 05/12] added Ghost BB in the Field --- src/main/java/pacmanGame/VisualizerPlainText.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/pacmanGame/VisualizerPlainText.java b/src/main/java/pacmanGame/VisualizerPlainText.java index 330d7f5..0c6fbd3 100644 --- a/src/main/java/pacmanGame/VisualizerPlainText.java +++ b/src/main/java/pacmanGame/VisualizerPlainText.java @@ -48,6 +48,7 @@ public class VisualizerPlainText implements Visualizer { for(int x = 0; x < map.size.x; x++) { Cell cell = map.GetCell(new Vector2(x, map.size.y - 1 - y)); boolean containsGhosts = false; + boolean containsGhosts1 = false; boolean containsPlayer = false; for( int i = 0; i < gameManager.ghosts.length; i++) { if(gameManager.ghosts[i].position.equals(cell.pos)) { @@ -64,6 +65,9 @@ public class VisualizerPlainText implements Visualizer { else if(containsGhosts) { output += ghostSprite; } + else if (containsGhosts1) { + output += ghostSprite1; + } else if (sprites.containsKey(cell.type)) { output += sprites.get(cell.type); From f912d1bb2be86f4c1c940a825c705e77bd2b86c7 Mon Sep 17 00:00:00 2001 From: fdai2751 Date: Thu, 8 Feb 2024 00:58:30 +0100 Subject: [PATCH 06/12] added the Ghost CC in the Field --- src/main/java/pacmanGame/VisualizerPlainText.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/pacmanGame/VisualizerPlainText.java b/src/main/java/pacmanGame/VisualizerPlainText.java index 0c6fbd3..196109c 100644 --- a/src/main/java/pacmanGame/VisualizerPlainText.java +++ b/src/main/java/pacmanGame/VisualizerPlainText.java @@ -49,6 +49,7 @@ public class VisualizerPlainText implements Visualizer { Cell cell = map.GetCell(new Vector2(x, map.size.y - 1 - y)); boolean containsGhosts = false; boolean containsGhosts1 = false; + boolean containsGhosts2 = false; boolean containsPlayer = false; for( int i = 0; i < gameManager.ghosts.length; i++) { if(gameManager.ghosts[i].position.equals(cell.pos)) { @@ -68,6 +69,9 @@ public class VisualizerPlainText implements Visualizer { else if (containsGhosts1) { output += ghostSprite1; } + else if (containsGhosts2) { + output += ghostSprite2; + } else if (sprites.containsKey(cell.type)) { output += sprites.get(cell.type); From ba5d3c3fa453590c9e8f7bb02e1a138eb1e44cea Mon Sep 17 00:00:00 2001 From: fdai2751 Date: Thu, 8 Feb 2024 01:05:51 +0100 Subject: [PATCH 07/12] added the Ghost CC in the Field --- src/main/java/pacmanGame/VisualizerPlainText.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/pacmanGame/VisualizerPlainText.java b/src/main/java/pacmanGame/VisualizerPlainText.java index 196109c..26ef95f 100644 --- a/src/main/java/pacmanGame/VisualizerPlainText.java +++ b/src/main/java/pacmanGame/VisualizerPlainText.java @@ -50,6 +50,7 @@ public class VisualizerPlainText implements Visualizer { boolean containsGhosts = false; boolean containsGhosts1 = false; boolean containsGhosts2 = false; + boolean containsGhosts3 = false; boolean containsPlayer = false; for( int i = 0; i < gameManager.ghosts.length; i++) { if(gameManager.ghosts[i].position.equals(cell.pos)) { @@ -72,6 +73,9 @@ public class VisualizerPlainText implements Visualizer { else if (containsGhosts2) { output += ghostSprite2; } + else if (containsGhosts3) { + output += ghostSprite3; + } else if (sprites.containsKey(cell.type)) { output += sprites.get(cell.type); From e84e771caea13186ee648d9e5c55694a90a3bc97 Mon Sep 17 00:00:00 2001 From: fdai2751 Date: Thu, 8 Feb 2024 01:08:59 +0100 Subject: [PATCH 08/12] added the Ghost DD in the Field --- src/main/java/pacmanGame/VisualizerPlainText.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/pacmanGame/VisualizerPlainText.java b/src/main/java/pacmanGame/VisualizerPlainText.java index 26ef95f..949ae9c 100644 --- a/src/main/java/pacmanGame/VisualizerPlainText.java +++ b/src/main/java/pacmanGame/VisualizerPlainText.java @@ -51,6 +51,7 @@ public class VisualizerPlainText implements Visualizer { boolean containsGhosts1 = false; boolean containsGhosts2 = false; boolean containsGhosts3 = false; + boolean containsGhosts4 = false; boolean containsPlayer = false; for( int i = 0; i < gameManager.ghosts.length; i++) { if(gameManager.ghosts[i].position.equals(cell.pos)) { @@ -76,6 +77,9 @@ public class VisualizerPlainText implements Visualizer { else if (containsGhosts3) { output += ghostSprite3; } + else if (containsGhosts4) { + output += ghostSprite4; + } else if (sprites.containsKey(cell.type)) { output += sprites.get(cell.type); From 6c6b6b10aae12df19e01320dddf41c838f0a48ba Mon Sep 17 00:00:00 2001 From: fdai2751 Date: Thu, 8 Feb 2024 01:11:42 +0100 Subject: [PATCH 09/12] added the Ghost EE in the Field --- src/main/java/pacmanGame/VisualizerPlainText.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/pacmanGame/VisualizerPlainText.java b/src/main/java/pacmanGame/VisualizerPlainText.java index 949ae9c..95ca08e 100644 --- a/src/main/java/pacmanGame/VisualizerPlainText.java +++ b/src/main/java/pacmanGame/VisualizerPlainText.java @@ -52,6 +52,7 @@ public class VisualizerPlainText implements Visualizer { boolean containsGhosts2 = false; boolean containsGhosts3 = false; boolean containsGhosts4 = false; + boolean containsGhosts5 = false; boolean containsPlayer = false; for( int i = 0; i < gameManager.ghosts.length; i++) { if(gameManager.ghosts[i].position.equals(cell.pos)) { @@ -80,6 +81,9 @@ public class VisualizerPlainText implements Visualizer { else if (containsGhosts4) { output += ghostSprite4; } + else if (containsGhosts5) { + output += ghostSprite5; + } else if (sprites.containsKey(cell.type)) { output += sprites.get(cell.type); From aaecaa88077fa88d2f31f971ecaa8321f84a27b3 Mon Sep 17 00:00:00 2001 From: fdai2751 Date: Thu, 8 Feb 2024 01:27:57 +0100 Subject: [PATCH 10/12] added the Ghost FF in the Field --- src/main/java/pacmanGame/VisualizerPlainText.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/pacmanGame/VisualizerPlainText.java b/src/main/java/pacmanGame/VisualizerPlainText.java index 95ca08e..f020534 100644 --- a/src/main/java/pacmanGame/VisualizerPlainText.java +++ b/src/main/java/pacmanGame/VisualizerPlainText.java @@ -53,6 +53,7 @@ public class VisualizerPlainText implements Visualizer { boolean containsGhosts3 = false; boolean containsGhosts4 = false; boolean containsGhosts5 = false; + boolean containsGhosts6 = false; boolean containsPlayer = false; for( int i = 0; i < gameManager.ghosts.length; i++) { if(gameManager.ghosts[i].position.equals(cell.pos)) { @@ -84,6 +85,9 @@ public class VisualizerPlainText implements Visualizer { else if (containsGhosts5) { output += ghostSprite5; } + else if (containsGhosts6) { + output += ghostSprite6; + } else if (sprites.containsKey(cell.type)) { output += sprites.get(cell.type); From 6615bb9b1cfe996db7c057ff84a194b13a771bc4 Mon Sep 17 00:00:00 2001 From: fdai2751 Date: Thu, 8 Feb 2024 01:31:14 +0100 Subject: [PATCH 11/12] added the Ghost GG in the Field --- src/main/java/pacmanGame/VisualizerPlainText.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/pacmanGame/VisualizerPlainText.java b/src/main/java/pacmanGame/VisualizerPlainText.java index f020534..bcf0d22 100644 --- a/src/main/java/pacmanGame/VisualizerPlainText.java +++ b/src/main/java/pacmanGame/VisualizerPlainText.java @@ -54,6 +54,7 @@ public class VisualizerPlainText implements Visualizer { boolean containsGhosts4 = false; boolean containsGhosts5 = false; boolean containsGhosts6 = false; + boolean containsGhosts7 = false; boolean containsPlayer = false; for( int i = 0; i < gameManager.ghosts.length; i++) { if(gameManager.ghosts[i].position.equals(cell.pos)) { @@ -88,6 +89,9 @@ public class VisualizerPlainText implements Visualizer { else if (containsGhosts6) { output += ghostSprite6; } + else if (containsGhosts7) { + output += ghostSprite7; + } else if (sprites.containsKey(cell.type)) { output += sprites.get(cell.type); From 43ea7fde925257e17624f30b3b05978dd98912e0 Mon Sep 17 00:00:00 2001 From: fdai2751 Date: Thu, 8 Feb 2024 01:36:30 +0100 Subject: [PATCH 12/12] added the Ghost HH in the Field --- src/main/java/pacmanGame/VisualizerPlainText.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/pacmanGame/VisualizerPlainText.java b/src/main/java/pacmanGame/VisualizerPlainText.java index bcf0d22..73ff16e 100644 --- a/src/main/java/pacmanGame/VisualizerPlainText.java +++ b/src/main/java/pacmanGame/VisualizerPlainText.java @@ -55,6 +55,7 @@ public class VisualizerPlainText implements Visualizer { boolean containsGhosts5 = false; boolean containsGhosts6 = false; boolean containsGhosts7 = false; + boolean containsGhosts8 = false; boolean containsPlayer = false; for( int i = 0; i < gameManager.ghosts.length; i++) { if(gameManager.ghosts[i].position.equals(cell.pos)) { @@ -92,6 +93,9 @@ public class VisualizerPlainText implements Visualizer { else if (containsGhosts7) { output += ghostSprite7; } + else if (containsGhosts8) { + output += ghostSprite8; + } else if (sprites.containsKey(cell.type)) { output += sprites.get(cell.type);