From c1efe11b684fa3cc66c4960ad150b1a5e5404a6f Mon Sep 17 00:00:00 2001 From: fdai7753 Date: Sun, 4 Feb 2024 19:40:27 +0100 Subject: [PATCH 01/26] Added ghost spawns to Map --- src/main/java/pacmanGame/Map.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/pacmanGame/Map.java b/src/main/java/pacmanGame/Map.java index 8e9371f..5768e63 100644 --- a/src/main/java/pacmanGame/Map.java +++ b/src/main/java/pacmanGame/Map.java @@ -19,8 +19,8 @@ public class Map { "wwwwwww.wweeeeeeeeeeww.wwwwwww", "wwwwwww.wwewwwwwwwweww.wwwwwww", "wwwwwww.wweweeeeeeweww.wwwwwww", - "eeeeeee.eeeweeeeeeweee.eeeeeee", - "wwwwwww.wweweeeeeeweww.wwwwwww", + "eeeeeee.eeewe1ee3eweee.eeeeeee", + "wwwwwww.wwewe2ee4eweww.wwwwwww", "wwwwwww.wweweeeeeeweww.wwwwwww", "wwwwwww.wwewwwwwwwweww.wwwwwww", "wwwwwww.wweeeeeeeeeeww.wwwwwww", @@ -38,12 +38,18 @@ public class Map { "wwwwwwwwwwwwwwwwwwwwwwwwwwwwww", "wwwwwwwwwwwwwwwwwwwwwwwwwwwwww" }; - + + public final int ghostSpawnCount = 4; + public final HashMap mapTypes = new HashMap(){{ this.put("e", "empty"); this.put("s", "empty"); this.put(".", "dot"); this.put("w", "wall"); + + for(int i = 0; i < 10; i++) { + this.put(i+"", "empty"); + } }}; public Cell[][] cells; From 6b78ab00f89a56296fdf233799c7755dfda91a0c Mon Sep 17 00:00:00 2001 From: fdai7753 Date: Sun, 4 Feb 2024 21:00:19 +0100 Subject: [PATCH 02/26] Added ghost number system in Map.java and GameManager.java --- src/main/java/pacmanGame/GameManager.java | 19 ++++++++--------- src/main/java/pacmanGame/Ghost.java | 25 +++++++++++++++-------- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/main/java/pacmanGame/GameManager.java b/src/main/java/pacmanGame/GameManager.java index 8a154d5..739359c 100644 --- a/src/main/java/pacmanGame/GameManager.java +++ b/src/main/java/pacmanGame/GameManager.java @@ -12,16 +12,15 @@ public class GameManager { } public void setupGame(){ - map = new Map(); - 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); - } - - } + map = new Map(); + 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, i); + } + } public void Update() { visualizer.Update(); if(time%5 == 0) { diff --git a/src/main/java/pacmanGame/Ghost.java b/src/main/java/pacmanGame/Ghost.java index dc8a7d9..9e7f6b3 100644 --- a/src/main/java/pacmanGame/Ghost.java +++ b/src/main/java/pacmanGame/Ghost.java @@ -1,12 +1,21 @@ package pacmanGame; public class Ghost { - public Vector2 position; - public final GameManager gameManager; - - public Ghost(GameManager gameManager) { - this.gameManager = gameManager; - this.position = new Vector2(-1, -1); - } - + public Vector2 position; + public final GameManager gameManager; + public final int ghostNumber; + + public Ghost(GameManager gameManager, int ghostNumber) { + this.gameManager = gameManager; + this.ghostNumber = ghostNumber; + this.position = new Vector2(-1, -1); + } + + public void setPosition(Vector2 newPosition) { + this.position = newPosition; + } + + public void move(Vector2 direction) { + this.position = this.position.Add(direction); + } } From 9b2da8a4d6f0e2f13101e44c5ba376b7efdfc31c Mon Sep 17 00:00:00 2001 From: fdai7753 Date: Sun, 4 Feb 2024 21:02:07 +0100 Subject: [PATCH 03/26] Added move directions to ghosts --- src/main/java/pacmanGame/Map.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/pacmanGame/Map.java b/src/main/java/pacmanGame/Map.java index 5768e63..8468537 100644 --- a/src/main/java/pacmanGame/Map.java +++ b/src/main/java/pacmanGame/Map.java @@ -19,8 +19,8 @@ public class Map { "wwwwwww.wweeeeeeeeeeww.wwwwwww", "wwwwwww.wwewwwwwwwweww.wwwwwww", "wwwwwww.wweweeeeeeweww.wwwwwww", - "eeeeeee.eeewe1ee3eweee.eeeeeee", - "wwwwwww.wwewe2ee4eweww.wwwwwww", + "eeeeeee.eeewe0ee2eweee.eeeeeee", + "wwwwwww.wwewe1ee3eweww.wwwwwww", "wwwwwww.wweweeeeeeweww.wwwwwww", "wwwwwww.wwewwwwwwwweww.wwwwwww", "wwwwwww.wweeeeeeeeeeww.wwwwwww", @@ -39,8 +39,10 @@ public class Map { "wwwwwwwwwwwwwwwwwwwwwwwwwwwwww" }; - public final int ghostSpawnCount = 4; - + public Vector2[] ghostSpawns; + public String ghostSpawnChars = "0123456789"; + + public final HashMap mapTypes = new HashMap(){{ this.put("e", "empty"); this.put("s", "empty"); From 7a402cddf970ef5efbeb195b777252d5acd66936 Mon Sep 17 00:00:00 2001 From: fdai7910 Date: Sun, 4 Feb 2024 21:40:05 +0100 Subject: [PATCH 04/26] changed movement behaviour in Player --- src/main/java/pacmanGame/Player.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/pacmanGame/Player.java b/src/main/java/pacmanGame/Player.java index b729254..0780614 100644 --- a/src/main/java/pacmanGame/Player.java +++ b/src/main/java/pacmanGame/Player.java @@ -4,6 +4,8 @@ public class Player { public Vector2 position; public Vector2 direction; public GameManager gameManager; + public Vector2 oldDirection; + public Vector2 futureDirection; public Player(GameManager gameManager) { this.gameManager = gameManager; @@ -14,23 +16,28 @@ 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') { - direction = new Vector2(0,1); + direction = new Vector2(0,1); } else if(inputchar == 's') { From c25a45f196d81f0df8a5409b12c608f369d69107 Mon Sep 17 00:00:00 2001 From: fdai7753 Date: Mon, 5 Feb 2024 21:31:39 +0100 Subject: [PATCH 05/26] Fixed ghosts branch crashes --- src/main/java/pacmanGame/GameManager.java | 2 +- src/main/java/pacmanGame/Ghost.java | 1 + src/main/java/pacmanGame/Map.java | 34 ++++++++++++++++--- src/test/java/pacmanTests/MapTest.java | 14 +++++--- .../pacmanTests/VisualizerPlainTextTest.java | 4 +-- 5 files changed, 43 insertions(+), 12 deletions(-) diff --git a/src/main/java/pacmanGame/GameManager.java b/src/main/java/pacmanGame/GameManager.java index 739359c..d7c22d3 100644 --- a/src/main/java/pacmanGame/GameManager.java +++ b/src/main/java/pacmanGame/GameManager.java @@ -12,7 +12,7 @@ public class GameManager { } public void setupGame(){ - map = new Map(); + map = new Map(this); visualizer = new VisualizerPlainText(this); player = new Player(this); player.Spawn(); diff --git a/src/main/java/pacmanGame/Ghost.java b/src/main/java/pacmanGame/Ghost.java index 9e7f6b3..26e9845 100644 --- a/src/main/java/pacmanGame/Ghost.java +++ b/src/main/java/pacmanGame/Ghost.java @@ -4,6 +4,7 @@ public class Ghost { public Vector2 position; public final GameManager gameManager; public final int ghostNumber; + public Ghost(GameManager gameManager, int ghostNumber) { this.gameManager = gameManager; diff --git a/src/main/java/pacmanGame/Map.java b/src/main/java/pacmanGame/Map.java index 8468537..2379e89 100644 --- a/src/main/java/pacmanGame/Map.java +++ b/src/main/java/pacmanGame/Map.java @@ -41,7 +41,7 @@ public class Map { public Vector2[] ghostSpawns; public String ghostSpawnChars = "0123456789"; - + public final HashMap mapTypes = new HashMap(){{ this.put("e", "empty"); @@ -53,6 +53,7 @@ public class Map { this.put(i+"", "empty"); } }}; + public GameManager gameManager; public Cell[][] cells; public Vector2 size; @@ -60,12 +61,14 @@ public class Map { public Vector2 playerSpawn = new Vector2(2,2); public char playerSpawnChar = 's'; - public Map() { + public Map(GameManager gameManager) { + initializeGhostSpawns(); GenerateMap(mapClassic); + this.gameManager = gameManager; } - - public Map(String[] mapData) { + public Map(String[] mapData,GameManager gameManager) { GenerateMap(mapData); + this.gameManager = gameManager; } public void GenerateMap(String[] mapData) { @@ -87,6 +90,8 @@ public class Map { cells[x][y] = new Cell(cellPos, cellType); + //for(int i = 0; i < gameManager.ghosts.length; i++) + if(cellChar == playerSpawnChar) { playerSpawn = cellPos.Clone(); } @@ -105,4 +110,25 @@ public class Map { } } + private void initializeGhostSpawns() { + int count = 0; + for (int y = 0; y < mapClassic.length; y++) { + for (int x = 0; x < mapClassic[y].length(); x++) { + char cellChar = mapClassic[y].charAt(x); + if (ghostSpawnChars.indexOf(cellChar) != -1) { + count++; + } + } + } + ghostSpawns = new Vector2[count]; + count = 0; + for (int y = 0; y < mapClassic.length; y++) { + for (int x = 0; x < mapClassic[y].length(); x++) { + char cellChar = mapClassic[y].charAt(x); + if (ghostSpawnChars.indexOf(cellChar) != -1) { + ghostSpawns[count++] = new Vector2(x, mapClassic.length - 1 - y); + } + } + } + } } diff --git a/src/test/java/pacmanTests/MapTest.java b/src/test/java/pacmanTests/MapTest.java index cc94256..2f91479 100644 --- a/src/test/java/pacmanTests/MapTest.java +++ b/src/test/java/pacmanTests/MapTest.java @@ -21,12 +21,13 @@ class MapTest { String expectedTopLeft = "wall"; String expectedMiddle = "dot"; String expectedBottomRight = "dot"; + GameManager gameManager = new GameManager(); // act - Map testMap = new Map(mapTest); + gameManager.map = new Map(mapTest, gameManager); - String topLeft = testMap.cells[0][2].type; - String middle = testMap.cells[1][1].type; - String bottomRight = testMap.cells[2][0].type; + String topLeft = gameManager.map.cells[0][2].type; + String middle = gameManager.map.cells[1][1].type; + String bottomRight = gameManager.map.cells[2][0].type; // assert assertThat(expectedTopLeft).isEqualTo(topLeft); assertThat(expectedMiddle).isEqualTo(middle); @@ -41,7 +42,10 @@ class MapTest { "w..", "ee." }; - Map testMap = new Map(mapTest); + GameManager gameManager = new GameManager(); + // act + 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); From 3b4a3f89c453d4b9f61de2242d04c381564f380d Mon Sep 17 00:00:00 2001 From: fdai7753 Date: Wed, 7 Feb 2024 14:45:37 +0100 Subject: [PATCH 06/26] Continuation of adding ghost spawns --- src/main/java/pacmanGame/Map.java | 47 +++++++++++++++---------------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/src/main/java/pacmanGame/Map.java b/src/main/java/pacmanGame/Map.java index 2379e89..efca6cf 100644 --- a/src/main/java/pacmanGame/Map.java +++ b/src/main/java/pacmanGame/Map.java @@ -52,6 +52,8 @@ public class Map { for(int i = 0; i < 10; i++) { this.put(i+"", "empty"); } + this.put("0", "empty"); + }}; public GameManager gameManager; @@ -72,31 +74,28 @@ public class Map { } 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); + int sizeY = mapData.length; + int sizeX = mapData[0].length(); - char cellChar = mapData[size.y - 1 - y].charAt(x); - - String cellType = mapTypes.get(String.valueOf(cellChar)); - - cells[x][y] = new Cell(cellPos, cellType); - - //for(int i = 0; i < gameManager.ghosts.length; i++) - - if(cellChar == playerSpawnChar) { - playerSpawn = cellPos.Clone(); - } - } - } + 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); + + char cellChar = mapData[size.y - 1 - y].charAt(x); + + String cellType = mapTypes.get(String.valueOf(cellChar)); + + cells[x][y] = new Cell(cellPos, cellType); + + if(cellChar == playerSpawnChar) { + playerSpawn = cellPos.Clone(); + } + } + } } public Cell GetCell(Vector2 pos) { From 004abc7cf6f507ab66f8faacfac1e6bcf30c01fa Mon Sep 17 00:00:00 2001 From: fdai7753 Date: Wed, 7 Feb 2024 14:49:50 +0100 Subject: [PATCH 07/26] Addition of ghost spawn 1 on map --- src/main/java/pacmanGame/Map.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/pacmanGame/Map.java b/src/main/java/pacmanGame/Map.java index efca6cf..0d9beb8 100644 --- a/src/main/java/pacmanGame/Map.java +++ b/src/main/java/pacmanGame/Map.java @@ -53,7 +53,8 @@ public class Map { this.put(i+"", "empty"); } this.put("0", "empty"); - + this.put("1", "empty"); + }}; public GameManager gameManager; From 1a0812f5d5d93ddafce96a2ea100961cc962f3c1 Mon Sep 17 00:00:00 2001 From: fdai7753 Date: Wed, 7 Feb 2024 14:56:35 +0100 Subject: [PATCH 08/26] Addition of ghost spawn 2 on map --- src/main/java/pacmanGame/Map.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/pacmanGame/Map.java b/src/main/java/pacmanGame/Map.java index 0d9beb8..02f2abc 100644 --- a/src/main/java/pacmanGame/Map.java +++ b/src/main/java/pacmanGame/Map.java @@ -54,6 +54,7 @@ public class Map { } this.put("0", "empty"); this.put("1", "empty"); + this.put("2", "empty"); }}; public GameManager gameManager; From 694632982fd331f8d0ea6502c5ddba8e9ff7a988 Mon Sep 17 00:00:00 2001 From: fdai7753 Date: Wed, 7 Feb 2024 15:00:13 +0100 Subject: [PATCH 09/26] Addition of ghost spawn 3 on map --- src/main/java/pacmanGame/Map.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/pacmanGame/Map.java b/src/main/java/pacmanGame/Map.java index 02f2abc..b36f205 100644 --- a/src/main/java/pacmanGame/Map.java +++ b/src/main/java/pacmanGame/Map.java @@ -55,7 +55,7 @@ public class Map { this.put("0", "empty"); this.put("1", "empty"); this.put("2", "empty"); - + this.put("3", "empty"); }}; public GameManager gameManager; From fd806f977cd31afca52766c4bc21831d2d9be036 Mon Sep 17 00:00:00 2001 From: fdai7753 Date: Wed, 7 Feb 2024 15:09:09 +0100 Subject: [PATCH 10/26] Added ghost spawn 4 on Map grid --- src/main/java/pacmanGame/Map.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/pacmanGame/Map.java b/src/main/java/pacmanGame/Map.java index b36f205..4ac2306 100644 --- a/src/main/java/pacmanGame/Map.java +++ b/src/main/java/pacmanGame/Map.java @@ -19,7 +19,7 @@ public class Map { "wwwwwww.wweeeeeeeeeeww.wwwwwww", "wwwwwww.wwewwwwwwwweww.wwwwwww", "wwwwwww.wweweeeeeeweww.wwwwwww", - "eeeeeee.eeewe0ee2eweee.eeeeeee", + "eeeeeee.eeewe04e2eweee.eeeeeee", "wwwwwww.wwewe1ee3eweww.wwwwwww", "wwwwwww.wweweeeeeeweww.wwwwwww", "wwwwwww.wwewwwwwwwweww.wwwwwww", From da64069250b2d0b7727344a3af8d902c5c66044c Mon Sep 17 00:00:00 2001 From: fdai7753 Date: Wed, 7 Feb 2024 15:13:02 +0100 Subject: [PATCH 11/26] Added ghost spawn 5 on Map grid --- src/main/java/pacmanGame/Map.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/pacmanGame/Map.java b/src/main/java/pacmanGame/Map.java index 4ac2306..1e992e7 100644 --- a/src/main/java/pacmanGame/Map.java +++ b/src/main/java/pacmanGame/Map.java @@ -20,7 +20,7 @@ public class Map { "wwwwwww.wwewwwwwwwweww.wwwwwww", "wwwwwww.wweweeeeeeweww.wwwwwww", "eeeeeee.eeewe04e2eweee.eeeeeee", - "wwwwwww.wwewe1ee3eweww.wwwwwww", + "wwwwwww.wwewe15e3eweww.wwwwwww", "wwwwwww.wweweeeeeeweww.wwwwwww", "wwwwwww.wwewwwwwwwweww.wwwwwww", "wwwwwww.wweeeeeeeeeeww.wwwwwww", From 63ba36d6ef78d11b2315926ac27a72831afdfcb5 Mon Sep 17 00:00:00 2001 From: fdai7753 Date: Wed, 7 Feb 2024 15:17:04 +0100 Subject: [PATCH 12/26] Added ghost spawn 6 on Map grid --- src/main/java/pacmanGame/Map.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/pacmanGame/Map.java b/src/main/java/pacmanGame/Map.java index 1e992e7..bb361db 100644 --- a/src/main/java/pacmanGame/Map.java +++ b/src/main/java/pacmanGame/Map.java @@ -19,7 +19,7 @@ public class Map { "wwwwwww.wweeeeeeeeeeww.wwwwwww", "wwwwwww.wwewwwwwwwweww.wwwwwww", "wwwwwww.wweweeeeeeweww.wwwwwww", - "eeeeeee.eeewe04e2eweee.eeeeeee", + "eeeeeee.eeewe0462eweee.eeeeeee", "wwwwwww.wwewe15e3eweww.wwwwwww", "wwwwwww.wweweeeeeeweww.wwwwwww", "wwwwwww.wwewwwwwwwweww.wwwwwww", From 8a8f39e7baf79fddbc5b933414555b5f87098988 Mon Sep 17 00:00:00 2001 From: fdai7753 Date: Wed, 7 Feb 2024 15:21:54 +0100 Subject: [PATCH 13/26] Added ghost spawn 7 on Map grid --- src/main/java/pacmanGame/Map.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/pacmanGame/Map.java b/src/main/java/pacmanGame/Map.java index bb361db..7b17a82 100644 --- a/src/main/java/pacmanGame/Map.java +++ b/src/main/java/pacmanGame/Map.java @@ -20,7 +20,7 @@ public class Map { "wwwwwww.wwewwwwwwwweww.wwwwwww", "wwwwwww.wweweeeeeeweww.wwwwwww", "eeeeeee.eeewe0462eweee.eeeeeee", - "wwwwwww.wwewe15e3eweww.wwwwwww", + "wwwwwww.wwewe1573eweww.wwwwwww", "wwwwwww.wweweeeeeeweww.wwwwwww", "wwwwwww.wwewwwwwwwweww.wwwwwww", "wwwwwww.wweeeeeeeeeeww.wwwwwww", From ac5eb7b30952ef51600a820667228ca96457aaf3 Mon Sep 17 00:00:00 2001 From: fdai7753 Date: Wed, 7 Feb 2024 15:26:01 +0100 Subject: [PATCH 14/26] Addition of ghost spawn 4 on map --- src/main/java/pacmanGame/Map.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/pacmanGame/Map.java b/src/main/java/pacmanGame/Map.java index 7b17a82..d4458da 100644 --- a/src/main/java/pacmanGame/Map.java +++ b/src/main/java/pacmanGame/Map.java @@ -56,6 +56,7 @@ public class Map { this.put("1", "empty"); this.put("2", "empty"); this.put("3", "empty"); + this.put("4", "empty"); }}; public GameManager gameManager; From c891a12599e24f8ceec61946ce0b594444c2915f Mon Sep 17 00:00:00 2001 From: fdai7753 Date: Wed, 7 Feb 2024 15:29:56 +0100 Subject: [PATCH 15/26] Addition of ghost spawn 5 on map --- src/main/java/pacmanGame/Map.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/pacmanGame/Map.java b/src/main/java/pacmanGame/Map.java index d4458da..9db7f23 100644 --- a/src/main/java/pacmanGame/Map.java +++ b/src/main/java/pacmanGame/Map.java @@ -57,6 +57,7 @@ public class Map { this.put("2", "empty"); this.put("3", "empty"); this.put("4", "empty"); + this.put("5", "empty"); }}; public GameManager gameManager; From 928bd6d8e441c0294d0a3aa2b4bec4c5df6a3373 Mon Sep 17 00:00:00 2001 From: fdai7753 Date: Wed, 7 Feb 2024 15:31:40 +0100 Subject: [PATCH 16/26] Added ghost spawn 8 on Map grid --- src/main/java/pacmanGame/Map.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/pacmanGame/Map.java b/src/main/java/pacmanGame/Map.java index 9db7f23..a9e9ffe 100644 --- a/src/main/java/pacmanGame/Map.java +++ b/src/main/java/pacmanGame/Map.java @@ -19,7 +19,7 @@ public class Map { "wwwwwww.wweeeeeeeeeeww.wwwwwww", "wwwwwww.wwewwwwwwwweww.wwwwwww", "wwwwwww.wweweeeeeeweww.wwwwwww", - "eeeeeee.eeewe0462eweee.eeeeeee", + "eeeeeee.eeew80462eweee.eeeeeee", "wwwwwww.wwewe1573eweww.wwwwwww", "wwwwwww.wweweeeeeeweww.wwwwwww", "wwwwwww.wwewwwwwwwweww.wwwwwww", From 782d3d35013098edfb229d401d5e7ef46764576c Mon Sep 17 00:00:00 2001 From: fdai7753 Date: Wed, 7 Feb 2024 15:32:41 +0100 Subject: [PATCH 17/26] Added ghost spawn 9 on Map grid --- src/main/java/pacmanGame/Map.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/pacmanGame/Map.java b/src/main/java/pacmanGame/Map.java index a9e9ffe..d78dd82 100644 --- a/src/main/java/pacmanGame/Map.java +++ b/src/main/java/pacmanGame/Map.java @@ -19,7 +19,7 @@ public class Map { "wwwwwww.wweeeeeeeeeeww.wwwwwww", "wwwwwww.wwewwwwwwwweww.wwwwwww", "wwwwwww.wweweeeeeeweww.wwwwwww", - "eeeeeee.eeew80462eweee.eeeeeee", + "eeeeeee.eeew804629weee.eeeeeee", "wwwwwww.wwewe1573eweww.wwwwwww", "wwwwwww.wweweeeeeeweww.wwwwwww", "wwwwwww.wwewwwwwwwweww.wwwwwww", From 89fe8d19a7c1735726450a41e122631f323fbf31 Mon Sep 17 00:00:00 2001 From: fdai7753 Date: Wed, 7 Feb 2024 15:34:26 +0100 Subject: [PATCH 18/26] Addition of ghost spawn 6 on map --- src/main/java/pacmanGame/Map.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/pacmanGame/Map.java b/src/main/java/pacmanGame/Map.java index d78dd82..4ddb151 100644 --- a/src/main/java/pacmanGame/Map.java +++ b/src/main/java/pacmanGame/Map.java @@ -58,6 +58,7 @@ public class Map { this.put("3", "empty"); this.put("4", "empty"); this.put("5", "empty"); + this.put("6", "empty"); }}; public GameManager gameManager; From bc6532d754ba073f0cece97c29c1cce406547a8e Mon Sep 17 00:00:00 2001 From: fdai7753 Date: Wed, 7 Feb 2024 15:36:31 +0100 Subject: [PATCH 19/26] Addition of ghost spawn 7 on map --- src/main/java/pacmanGame/Map.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/pacmanGame/Map.java b/src/main/java/pacmanGame/Map.java index 4ddb151..ffd7424 100644 --- a/src/main/java/pacmanGame/Map.java +++ b/src/main/java/pacmanGame/Map.java @@ -59,6 +59,7 @@ public class Map { this.put("4", "empty"); this.put("5", "empty"); this.put("6", "empty"); + this.put("7", "empty"); }}; public GameManager gameManager; From 7dc1e5f67894dc3801d912733237c8d2c08996e2 Mon Sep 17 00:00:00 2001 From: fdai7753 Date: Wed, 7 Feb 2024 15:38:00 +0100 Subject: [PATCH 20/26] Addition of ghost spawn 8 on map --- src/main/java/pacmanGame/Map.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/pacmanGame/Map.java b/src/main/java/pacmanGame/Map.java index ffd7424..0464d50 100644 --- a/src/main/java/pacmanGame/Map.java +++ b/src/main/java/pacmanGame/Map.java @@ -60,6 +60,7 @@ public class Map { this.put("5", "empty"); this.put("6", "empty"); this.put("7", "empty"); + this.put("8", "empty"); }}; public GameManager gameManager; From 4b0345751dbc0e849a0676d08c941aaece695d45 Mon Sep 17 00:00:00 2001 From: fdai7753 Date: Wed, 7 Feb 2024 15:39:12 +0100 Subject: [PATCH 21/26] Addition of ghost spawn 9 on map --- src/main/java/pacmanGame/Map.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/pacmanGame/Map.java b/src/main/java/pacmanGame/Map.java index 0464d50..f48c937 100644 --- a/src/main/java/pacmanGame/Map.java +++ b/src/main/java/pacmanGame/Map.java @@ -61,6 +61,7 @@ public class Map { this.put("6", "empty"); this.put("7", "empty"); this.put("8", "empty"); + this.put("9", "empty"); }}; public GameManager gameManager; From 62ffa07a64f6c8f3a0a5dbbc55bf41101d24982d Mon Sep 17 00:00:00 2001 From: fdai7753 Date: Wed, 7 Feb 2024 15:44:17 +0100 Subject: [PATCH 22/26] refactoring: Removed redundant code --- src/main/java/pacmanGame/Map.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/java/pacmanGame/Map.java b/src/main/java/pacmanGame/Map.java index f48c937..77ebc6d 100644 --- a/src/main/java/pacmanGame/Map.java +++ b/src/main/java/pacmanGame/Map.java @@ -48,10 +48,6 @@ public class Map { this.put("s", "empty"); this.put(".", "dot"); this.put("w", "wall"); - - for(int i = 0; i < 10; i++) { - this.put(i+"", "empty"); - } this.put("0", "empty"); this.put("1", "empty"); this.put("2", "empty"); From 4d2044374e00404c4007964a35c6453bf38596db Mon Sep 17 00:00:00 2001 From: Julian Date: Wed, 7 Feb 2024 15:58:18 +0100 Subject: [PATCH 23/26] Added FindPath Function to Map --- src/main/java/pacmanGame/Map.java | 100 ++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/src/main/java/pacmanGame/Map.java b/src/main/java/pacmanGame/Map.java index b018895..c610ea3 100644 --- a/src/main/java/pacmanGame/Map.java +++ b/src/main/java/pacmanGame/Map.java @@ -128,4 +128,104 @@ public class Map { } } } + + public String FindPath(Vector2 from, Vector2 to) + { + char[][] tempMap = new char[size.x][size.y]; + + for(int x = 0; x < size.x; x++) { + for(int y = 0; y < size.y; y++) { + Vector2 pos = new Vector2(x,y); + Cell cell = GetCell(pos); + if(cell.type.equals("wall")) { + tempMap[x][y] = 'w'; + } + else { + tempMap[x][y] = 'e'; + } + } + } + + tempMap[to.x][to.y] = 't'; + + String targetChars = "tudlr"; + + boolean done = false; + + while(!done) { + int changes = 0; + + for(int x = 0; x < size.x; x++) { + for(int y = 0; y < size.y; y++) { + + if(tempMap[x][y] == 'e') { + + Vector2 pos = new Vector2(x,y); + char newChar = 'x'; + + if(targetChars.indexOf(tempMap[x + 1][y]) >= 0) { + newChar = 'r'; + } + else if(targetChars.indexOf(tempMap[x - 1][y]) >= 0) { + newChar = 'l'; + } + else if(targetChars.indexOf(tempMap[x][y + 1]) >= 0) { + newChar = 'u'; + } + else if(targetChars.indexOf(tempMap[x][y - 1]) >= 0) { + newChar = 'd'; + } + + if(newChar != 'x') { + tempMap[x][y] = newChar; + changes++; + + if(pos.equals(from)) { + done = true; + } + } + } + } + } + + if(changes == 0) { + done = true; + } + } + + if(tempMap[from.x][from.y] != 'e') { + boolean reading = true; + String path = ""; + Vector2 currentReadPos = from.Clone(); + + while(reading) { + char currentChar = tempMap[currentReadPos.x][currentReadPos.y]; + + if(currentReadPos.equals(to)) { + reading = false; + } + else { + path += currentChar; + + if(currentChar == 'l') { + currentReadPos = currentReadPos.Add(new Vector2(-1, 0)); + } + else if(currentChar == 'r') { + currentReadPos = currentReadPos.Add(new Vector2(1, 0)); + } + else if(currentChar == 'u') { + currentReadPos = currentReadPos.Add(new Vector2(0, 1)); + } + else if(currentChar == 'd') { + currentReadPos = currentReadPos.Add(new Vector2(0, -1)); + } + } + } + return path; + } + else { + //no path was found + return ""; + } + } } From 4d86a65233726797a45bfc8978cbf99cde49989b Mon Sep 17 00:00:00 2001 From: Julian Date: Wed, 7 Feb 2024 15:58:39 +0100 Subject: [PATCH 24/26] Added tests for FindPath function --- src/test/java/pacmanTests/MapTest.java | 54 ++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/src/test/java/pacmanTests/MapTest.java b/src/test/java/pacmanTests/MapTest.java index 7fc442d..723fa63 100644 --- a/src/test/java/pacmanTests/MapTest.java +++ b/src/test/java/pacmanTests/MapTest.java @@ -57,4 +57,58 @@ class MapTest { assertThat(expectedMiddle).isEqualTo(middle); assertThat(expectedBottomRight).isEqualTo(bottomRight); } + + @Test + void Map_getPath_returnCorrectPathSimple() { + // arrange + String[] mapTest = { + "wwwww", + "w...w", + "w.w.w", + "w.w.w", + "wwwww" + }; + GameManager gameManager = new GameManager(); + gameManager.map = new Map(mapTest, gameManager); + + Vector2 from = new Vector2(1, 1); + Vector2 to = new Vector2(3, 1); + + String expectedPath = "uurrdd"; + + // act + + String path = gameManager.map.FindPath(from, to); + + // assert + assertThat(path).isEqualTo(expectedPath); + } + + @Test + void Map_getPath_returnCorrectPathComplex() { + // arrange + String[] mapTest = { + "wwwwwwwww", + "w.....w.w", + "w.www.w.w", + "w.w...w.w", + "w.w.www.w", + "w.w.....w", + "wwwwwwwww" + }; + GameManager gameManager = new GameManager(); + gameManager.map = new Map(mapTest, gameManager); + + Vector2 from = new Vector2(4, 3); + Vector2 to = new Vector2(1, 1); + + String expectedPath = "ruulllldddd"; + + // act + + String path = gameManager.map.FindPath(from, to); + + // assert + assertThat(path).isEqualTo(expectedPath); + } } From 5d46dd98513e3a1e258a7af9deadcf5395febd86 Mon Sep 17 00:00:00 2001 From: Julian Date: Wed, 7 Feb 2024 16:01:48 +0100 Subject: [PATCH 25/26] Added teams.md --- team.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 team.md diff --git a/team.md b/team.md new file mode 100644 index 0000000..ea57d50 --- /dev/null +++ b/team.md @@ -0,0 +1,4 @@ +- fdai2751, fdai2751 +- fdai7012, fdai7012 +- fdai7753, fdai7753 +- fdai7910, fdai7910 \ No newline at end of file From a34dcbd689cc212fc780621ff48ad9fb8bb8b4d9 Mon Sep 17 00:00:00 2001 From: fdai7012 Date: Wed, 7 Feb 2024 16:04:54 +0100 Subject: [PATCH 26/26] edited team.md --- team.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/team.md b/team.md index ea57d50..6346c38 100644 --- a/team.md +++ b/team.md @@ -1,4 +1,5 @@ - fdai2751, fdai2751 - fdai7012, fdai7012 - fdai7753, fdai7753 -- fdai7910, fdai7910 \ No newline at end of file +- fdai7910, fdai7910 +- Julian, fdai7012 \ No newline at end of file