From 93b755580bd965f180a020284d0f9df35b6195f4 Mon Sep 17 00:00:00 2001 From: fdai7012 Date: Wed, 7 Feb 2024 23:03:58 +0100 Subject: [PATCH 01/17] Added VisualizerPlainTextUltra --- .../pacmanGame/VisualizerPlainTextUltra.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/main/java/pacmanGame/VisualizerPlainTextUltra.java diff --git a/src/main/java/pacmanGame/VisualizerPlainTextUltra.java b/src/main/java/pacmanGame/VisualizerPlainTextUltra.java new file mode 100644 index 0000000..dd4584b --- /dev/null +++ b/src/main/java/pacmanGame/VisualizerPlainTextUltra.java @@ -0,0 +1,17 @@ +package pacmanGame; + +public class VisualizerPlainTextUltra implements Visualizer { + + @Override + public Object GetOutput() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void Update() { + // TODO Auto-generated method stub + + } + +} From 93c67b5149fdc2d2d101413ff54a515783ad0958 Mon Sep 17 00:00:00 2001 From: fdai7012 Date: Wed, 7 Feb 2024 23:16:18 +0100 Subject: [PATCH 02/17] Added sprites to visualizer --- .../pacmanGame/VisualizerPlainTextUltra.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/java/pacmanGame/VisualizerPlainTextUltra.java b/src/main/java/pacmanGame/VisualizerPlainTextUltra.java index dd4584b..8b6806e 100644 --- a/src/main/java/pacmanGame/VisualizerPlainTextUltra.java +++ b/src/main/java/pacmanGame/VisualizerPlainTextUltra.java @@ -1,7 +1,25 @@ package pacmanGame; +import java.util.HashMap; + public class VisualizerPlainTextUltra implements Visualizer { +public HashMap sprites = new HashMap(){{ + + this.put("empty", new String[] { + " ", + " " + }); + this.put("dot", new String[] { + " . ", + " " + }); + this.put("wall", new String[] { + "|''|", + "|__|" + }); + }}; + @Override public Object GetOutput() { // TODO Auto-generated method stub From a7f8a3a98eca4d95ae97a0a417f380053f5f0b21 Mon Sep 17 00:00:00 2001 From: fdai7012 Date: Wed, 7 Feb 2024 23:19:37 +0100 Subject: [PATCH 03/17] Added ghost sprites to visualizer --- .../pacmanGame/VisualizerPlainTextUltra.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/main/java/pacmanGame/VisualizerPlainTextUltra.java b/src/main/java/pacmanGame/VisualizerPlainTextUltra.java index 8b6806e..ec28f38 100644 --- a/src/main/java/pacmanGame/VisualizerPlainTextUltra.java +++ b/src/main/java/pacmanGame/VisualizerPlainTextUltra.java @@ -18,8 +18,54 @@ public HashMap sprites = new HashMap(){{ "|''|", "|__|" }); + this.put("cherry", new String[] { + " /\\ ", + " 0O " + }); }}; + public final String[][] ghostSprites = { + { + "/--\\", + "~~~~" + }, + { + "/°°\\", + "~~~~" + }, + { + "/^^\\", + "~~~~" + }, + { + "/oo\\", + "~~~~" + }, + { + "/''\\", + "~~~~" + }, + { + "/**\\", + "~~~~" + }, + { + "/00\\", + "~~~~" + }, + { + "/++\\", + "~~~~" + }, + { + "/..\\", + "~~~~" + }, + { + "/§§\\", + "~~~~" } + }; + @Override public Object GetOutput() { // TODO Auto-generated method stub From 19c5ccdd18f0e27f6e0402e047363b4e46e063a7 Mon Sep 17 00:00:00 2001 From: fdai7012 Date: Wed, 7 Feb 2024 23:20:06 +0100 Subject: [PATCH 04/17] Added player sprite to visualizer --- src/main/java/pacmanGame/VisualizerPlainTextUltra.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/pacmanGame/VisualizerPlainTextUltra.java b/src/main/java/pacmanGame/VisualizerPlainTextUltra.java index ec28f38..72ad73b 100644 --- a/src/main/java/pacmanGame/VisualizerPlainTextUltra.java +++ b/src/main/java/pacmanGame/VisualizerPlainTextUltra.java @@ -66,6 +66,12 @@ public HashMap sprites = new HashMap(){{ "~~~~" } }; + + public final String[] playerSprite = { + "▄██▄", + "▀██▀" + }; + @Override public Object GetOutput() { // TODO Auto-generated method stub From 1500c6ac150480863f264716a5a8ff7d86250e59 Mon Sep 17 00:00:00 2001 From: fdai7012 Date: Wed, 7 Feb 2024 23:21:55 +0100 Subject: [PATCH 05/17] Added GameManager to visualizer --- src/main/java/pacmanGame/VisualizerPlainTextUltra.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/pacmanGame/VisualizerPlainTextUltra.java b/src/main/java/pacmanGame/VisualizerPlainTextUltra.java index 72ad73b..ce2c5b2 100644 --- a/src/main/java/pacmanGame/VisualizerPlainTextUltra.java +++ b/src/main/java/pacmanGame/VisualizerPlainTextUltra.java @@ -4,7 +4,9 @@ import java.util.HashMap; public class VisualizerPlainTextUltra implements Visualizer { -public HashMap sprites = new HashMap(){{ + GameManager gameManager = new GameManager(); + + public HashMap sprites = new HashMap(){{ this.put("empty", new String[] { " ", @@ -23,7 +25,7 @@ public HashMap sprites = new HashMap(){{ " 0O " }); }}; - + public final String[][] ghostSprites = { { "/--\\", @@ -71,7 +73,7 @@ public HashMap sprites = new HashMap(){{ "▄██▄", "▀██▀" }; - + @Override public Object GetOutput() { // TODO Auto-generated method stub From 3d866a18956c0f927af43f774c8688e7647f0bf0 Mon Sep 17 00:00:00 2001 From: fdai7012 Date: Wed, 7 Feb 2024 23:25:12 +0100 Subject: [PATCH 06/17] Actually added Constructor to visualizer --- src/main/java/pacmanGame/VisualizerPlainTextUltra.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/pacmanGame/VisualizerPlainTextUltra.java b/src/main/java/pacmanGame/VisualizerPlainTextUltra.java index ce2c5b2..5fead97 100644 --- a/src/main/java/pacmanGame/VisualizerPlainTextUltra.java +++ b/src/main/java/pacmanGame/VisualizerPlainTextUltra.java @@ -74,6 +74,10 @@ public class VisualizerPlainTextUltra implements Visualizer { "▀██▀" }; + public VisualizerPlainTextUltra(GameManager gameManager) { + this.gameManager = gameManager; + } + @Override public Object GetOutput() { // TODO Auto-generated method stub From 30956a1ed1d0a598de52af8407c481de3f74e8a5 Mon Sep 17 00:00:00 2001 From: fdai7012 Date: Wed, 7 Feb 2024 23:29:04 +0100 Subject: [PATCH 07/17] Added output to visualizer --- src/main/java/pacmanGame/VisualizerPlainTextUltra.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/pacmanGame/VisualizerPlainTextUltra.java b/src/main/java/pacmanGame/VisualizerPlainTextUltra.java index 5fead97..8dfa955 100644 --- a/src/main/java/pacmanGame/VisualizerPlainTextUltra.java +++ b/src/main/java/pacmanGame/VisualizerPlainTextUltra.java @@ -4,6 +4,8 @@ import java.util.HashMap; public class VisualizerPlainTextUltra implements Visualizer { + private String output; + GameManager gameManager = new GameManager(); public HashMap sprites = new HashMap(){{ From 2c547c82b158b5163783997be03ff4fdc98df9fb Mon Sep 17 00:00:00 2001 From: fdai7012 Date: Wed, 7 Feb 2024 23:29:46 +0100 Subject: [PATCH 08/17] Implemented GetOutput in visualizer --- src/main/java/pacmanGame/VisualizerPlainTextUltra.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/pacmanGame/VisualizerPlainTextUltra.java b/src/main/java/pacmanGame/VisualizerPlainTextUltra.java index 8dfa955..765b98e 100644 --- a/src/main/java/pacmanGame/VisualizerPlainTextUltra.java +++ b/src/main/java/pacmanGame/VisualizerPlainTextUltra.java @@ -82,8 +82,7 @@ public class VisualizerPlainTextUltra implements Visualizer { @Override public Object GetOutput() { - // TODO Auto-generated method stub - return null; + return output; } @Override From 5b5ff359ed9ded2ee0f5df5fed99b4245b7270b1 Mon Sep 17 00:00:00 2001 From: fdai7012 Date: Wed, 7 Feb 2024 23:30:50 +0100 Subject: [PATCH 09/17] refactoring: made gameManager public in vtpu --- src/main/java/pacmanGame/VisualizerPlainTextUltra.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/pacmanGame/VisualizerPlainTextUltra.java b/src/main/java/pacmanGame/VisualizerPlainTextUltra.java index 765b98e..eefc0a1 100644 --- a/src/main/java/pacmanGame/VisualizerPlainTextUltra.java +++ b/src/main/java/pacmanGame/VisualizerPlainTextUltra.java @@ -6,7 +6,7 @@ public class VisualizerPlainTextUltra implements Visualizer { private String output; - GameManager gameManager = new GameManager(); + public GameManager gameManager = new GameManager(); public HashMap sprites = new HashMap(){{ From a75d0fecf0929aa327a68e881857546cff374192 Mon Sep 17 00:00:00 2001 From: fdai7012 Date: Wed, 7 Feb 2024 23:31:52 +0100 Subject: [PATCH 10/17] Added alternative player sprites to visualizer --- src/main/java/pacmanGame/VisualizerPlainTextUltra.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/pacmanGame/VisualizerPlainTextUltra.java b/src/main/java/pacmanGame/VisualizerPlainTextUltra.java index eefc0a1..a687d4a 100644 --- a/src/main/java/pacmanGame/VisualizerPlainTextUltra.java +++ b/src/main/java/pacmanGame/VisualizerPlainTextUltra.java @@ -4,6 +4,8 @@ import java.util.HashMap; public class VisualizerPlainTextUltra implements Visualizer { + public boolean showScore = true; + private String output; public GameManager gameManager = new GameManager(); From 18e68eaa8f5068140397ab1fbddb336535eba151 Mon Sep 17 00:00:00 2001 From: fdai7012 Date: Wed, 7 Feb 2024 23:33:50 +0100 Subject: [PATCH 11/17] Implemented basic rendering to vptu --- .../pacmanGame/VisualizerPlainTextUltra.java | 96 ++++++++++++++++++- 1 file changed, 93 insertions(+), 3 deletions(-) diff --git a/src/main/java/pacmanGame/VisualizerPlainTextUltra.java b/src/main/java/pacmanGame/VisualizerPlainTextUltra.java index a687d4a..2db5054 100644 --- a/src/main/java/pacmanGame/VisualizerPlainTextUltra.java +++ b/src/main/java/pacmanGame/VisualizerPlainTextUltra.java @@ -72,12 +72,30 @@ public class VisualizerPlainTextUltra implements Visualizer { "~~~~" } }; - public final String[] playerSprite = { "▄██▄", "▀██▀" }; + public final String[][] playerAltSprites = { + { + "▄ ▄", + "▀██▀" + }, + { + "▄██▄", + "▀ ▀" + }, + { + " ▀█▄", + " ▄█▀" + }, + { + "▄█▀ ", + "▀█▄ " + } + }; + public VisualizerPlainTextUltra(GameManager gameManager) { this.gameManager = gameManager; } @@ -87,10 +105,82 @@ public class VisualizerPlainTextUltra implements Visualizer { return output; } - @Override public void Update() { - // TODO Auto-generated method stub + output = ""; + + if(showScore) { + output = "\nSCORE: " + gameManager.score + "\n\n"; + } + + int lineBufferSize = 2; + String[] lineBuffer = new String[lineBufferSize]; + + Map map = gameManager.map; + + for(int y = 0; y < map.size.y; y++) { + + if(gameManager.isPaused && y > 10 && y < 20) { + + + for(int i = 0; i < lineBufferSize; i++) { + if(y == 15 && i == 0) { + output += " Paused! \n"; + } + else{ + output += "\n"; + } + } + } + else { + for(int i = 0; i < lineBufferSize; i++) { + lineBuffer[i] = ""; + } + + 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 containsPlayer = false; + int ghostIndex = -1; + + for( int i = 0; i < gameManager.ghosts.length; i++) { + if(gameManager.ghosts[i].position.equals(cell.pos)) { + containsGhosts = true; + ghostIndex = i; + } + } + if(gameManager.player.position.equals(cell.pos)) { + containsPlayer = true; + } + + if(containsPlayer) { + lineBuffer = AttachToBuffer(lineBuffer, playerSprite); + } + else if(containsGhosts) { + lineBuffer = AttachToBuffer(lineBuffer, ghostSprites[ghostIndex]); + } + else if (sprites.containsKey(cell.type)) { + + lineBuffer = AttachToBuffer(lineBuffer, sprites.get(cell.type)); + } + else { + System.out.println("unknown type" + cell.type); + } + } + + for(int i = 0; i < lineBufferSize; i++) { + output += lineBuffer[i] + "\n"; + } + } + } + } + + public String[] AttachToBuffer(String[] buffer, String[] sprite) { + for(int i = 0; i < buffer.length; i++) { + buffer[i] += sprite[i]; + } + return buffer; } } From a2fdc351e591bf339edb62fd73700b1fe015c5e1 Mon Sep 17 00:00:00 2001 From: fdai7012 Date: Wed, 7 Feb 2024 23:56:45 +0100 Subject: [PATCH 12/17] Implemented player animation to vptu --- .../pacmanGame/VisualizerPlainTextUltra.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/main/java/pacmanGame/VisualizerPlainTextUltra.java b/src/main/java/pacmanGame/VisualizerPlainTextUltra.java index 2db5054..b28f00d 100644 --- a/src/main/java/pacmanGame/VisualizerPlainTextUltra.java +++ b/src/main/java/pacmanGame/VisualizerPlainTextUltra.java @@ -5,6 +5,8 @@ import java.util.HashMap; public class VisualizerPlainTextUltra implements Visualizer { public boolean showScore = true; + + public final int playerAnimationTime = 2; private String output; @@ -155,8 +157,28 @@ public class VisualizerPlainTextUltra implements Visualizer { } if(containsPlayer) { + if((gameManager.time / playerAnimationTime) % 2 == 0) { + int directionIndex = 0; + + if(gameManager.player.direction.equals(new Vector2(0, 1))) { + directionIndex = 0; + } + else if(gameManager.player.direction.equals(new Vector2(0, -1))) { + directionIndex = 1; + } + else if(gameManager.player.direction.equals(new Vector2(-1, 0))) { + directionIndex = 2; + } + else if(gameManager.player.direction.equals(new Vector2(1, 0))) { + directionIndex = 3; + } + + lineBuffer = AttachToBuffer(lineBuffer, playerAltSprites[directionIndex]); + } + else { lineBuffer = AttachToBuffer(lineBuffer, playerSprite); } + } else if(containsGhosts) { lineBuffer = AttachToBuffer(lineBuffer, ghostSprites[ghostIndex]); } From a126e760a5ffa29ac2ff8e99b4a90e46fec53314 Mon Sep 17 00:00:00 2001 From: fdai7012 Date: Thu, 8 Feb 2024 00:04:00 +0100 Subject: [PATCH 13/17] refactoring: removed initialization of gameManager in vptu --- src/main/java/pacmanGame/VisualizerPlainTextUltra.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/pacmanGame/VisualizerPlainTextUltra.java b/src/main/java/pacmanGame/VisualizerPlainTextUltra.java index b28f00d..5ad17d4 100644 --- a/src/main/java/pacmanGame/VisualizerPlainTextUltra.java +++ b/src/main/java/pacmanGame/VisualizerPlainTextUltra.java @@ -10,7 +10,7 @@ public class VisualizerPlainTextUltra implements Visualizer { private String output; - public GameManager gameManager = new GameManager(); + public GameManager gameManager; public HashMap sprites = new HashMap(){{ From acc76734dc25e00141df3794846f17bb25ce49d0 Mon Sep 17 00:00:00 2001 From: fdai7012 Date: Thu, 8 Feb 2024 00:04:45 +0100 Subject: [PATCH 14/17] implemented vptu in gameManager --- src/main/java/pacmanGame/GameManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/pacmanGame/GameManager.java b/src/main/java/pacmanGame/GameManager.java index 5607b62..729700d 100644 --- a/src/main/java/pacmanGame/GameManager.java +++ b/src/main/java/pacmanGame/GameManager.java @@ -20,7 +20,7 @@ public class GameManager { public void setupGame(){ map = new Map(Map.mapClassic,this); - visualizer = new VisualizerPlainText(this); + visualizer = new VisualizerPlainTextUltra(this); player = new Player(this); player.Spawn(); ghosts = new Ghost[4]; From e9aebb43b858f744faee92b801acd433a21fb416 Mon Sep 17 00:00:00 2001 From: fdai7012 Date: Thu, 8 Feb 2024 00:06:10 +0100 Subject: [PATCH 15/17] adjusted window size --- src/main/java/pacmanGame/Program.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/pacmanGame/Program.java b/src/main/java/pacmanGame/Program.java index da7b37c..1fce1a6 100644 --- a/src/main/java/pacmanGame/Program.java +++ b/src/main/java/pacmanGame/Program.java @@ -54,7 +54,7 @@ public class Program { frame = new JFrame("PacmaaaAAAYYYHAAAaaam"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - frame.setSize(500, 685); + frame.setSize(750, 950); textArea = new JTextArea("..."); textArea.setEditable(false); @@ -62,7 +62,7 @@ public class Program { textArea.setBackground(Color.black); textArea.setForeground(Color.blue); - Font font = new Font("Consolas", Font.PLAIN, 15); + Font font = new Font("Consolas", Font.PLAIN, 10); textArea.setFont(font); frame.add(textArea, BorderLayout.CENTER); From 725618e12815523320ec5573ed302c96455841ae Mon Sep 17 00:00:00 2001 From: fdai7012 Date: Thu, 8 Feb 2024 00:09:47 +0100 Subject: [PATCH 16/17] added ecplipse setting to make vptu class file utf 8 --- .settings/org.eclipse.core.resources.prefs | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .settings/org.eclipse.core.resources.prefs diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..21359ba --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding//src/main/java/pacmanGame/VisualizerPlainTextUltra.java=UTF-8 From 60c636c33a9c9914dccbf0d2e0c7b3bcc7607b20 Mon Sep 17 00:00:00 2001 From: fdai7012 Date: Thu, 8 Feb 2024 00:18:17 +0100 Subject: [PATCH 17/17] fixed error in GameManagerTest --- src/test/java/pacmanTests/GameManagerTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/pacmanTests/GameManagerTest.java b/src/test/java/pacmanTests/GameManagerTest.java index 175852b..28e4932 100644 --- a/src/test/java/pacmanTests/GameManagerTest.java +++ b/src/test/java/pacmanTests/GameManagerTest.java @@ -34,6 +34,7 @@ class GameManagerTest { // arrange GameManager gameManager = new GameManager(); + gameManager.visualizer = new VisualizerPlainText(gameManager); VisualizerPlainText vpt = (VisualizerPlainText) gameManager.visualizer; // act