From a35ddd5b5d5af407cc06481f400ea5d4c4db7187 Mon Sep 17 00:00:00 2001 From: B1G-SAM <54065426+B1G-SAM@users.noreply.github.com> Date: Fri, 22 Mar 2024 11:48:08 +0800 Subject: [PATCH] Fixes #21 --- .../java/command/fight/FightingCommand.java | 1 - .../java/command/fight/RunningCommand.java | 1 + .../command/mapmove/InteractingCommand.java | 4 +- ...culaChroniclesOfTheAlgorithmicKingdom.java | 8 ++-- src/main/java/textbox/TextBox.java | 48 +++++++++++++++++-- src/main/java/ui/Ui.java | 29 +++++++++-- 6 files changed, 77 insertions(+), 14 deletions(-) diff --git a/src/main/java/command/fight/FightingCommand.java b/src/main/java/command/fight/FightingCommand.java index dcba32e646..85f5d8504b 100644 --- a/src/main/java/command/fight/FightingCommand.java +++ b/src/main/java/command/fight/FightingCommand.java @@ -9,6 +9,5 @@ public FightingCommand() { @Override public void execute() { - } } diff --git a/src/main/java/command/fight/RunningCommand.java b/src/main/java/command/fight/RunningCommand.java index 83bcac6a87..a7ed17dbeb 100644 --- a/src/main/java/command/fight/RunningCommand.java +++ b/src/main/java/command/fight/RunningCommand.java @@ -11,6 +11,7 @@ public RunningCommand() { @Override public void execute(){ if(currentMap instanceof BattleInterface) { + textBox.setNextNarration("You decide to run and successfully got away"); AMap initMap = new FirstMap(); initMap.initMap(30, 10); initMap.initPlayerLocation(0, 0); diff --git a/src/main/java/command/mapmove/InteractingCommand.java b/src/main/java/command/mapmove/InteractingCommand.java index 707ed1f114..fa57f7e958 100644 --- a/src/main/java/command/mapmove/InteractingCommand.java +++ b/src/main/java/command/mapmove/InteractingCommand.java @@ -12,10 +12,12 @@ public InteractingCommand(){ @Override public void execute() { String entityInteractedWith = currentMap.handleInteract(); - System.out.println(entityInteractedWith); + textBox.setNextNarration(entityInteractedWith + " appears in your path. What will you do?"); + textBox.setNextInstruction("Will you [fight] or will you [run]?"); AMap battleMap; switch (entityInteractedWith) { case "@": + textBox.setNextDialogue("*the @ symbol stares at you menacingly*"); InteractableEntity monster = new Enemy(10, 10, 10); battleMap = new BattleInterface(playerStatus, textBox, monster); battleMap.initMap(30, 10); diff --git a/src/main/java/main/CalculaChroniclesOfTheAlgorithmicKingdom.java b/src/main/java/main/CalculaChroniclesOfTheAlgorithmicKingdom.java index 4804972df5..ecb40aeae9 100644 --- a/src/main/java/main/CalculaChroniclesOfTheAlgorithmicKingdom.java +++ b/src/main/java/main/CalculaChroniclesOfTheAlgorithmicKingdom.java @@ -8,8 +8,6 @@ import textbox.TextBox; import ui.Ui; -import java.util.Map; - public class CalculaChroniclesOfTheAlgorithmicKingdom { public static void main(String[] args) { @@ -30,7 +28,7 @@ public void startGame() { ui.printPlayerStatus(playerStatus); ui.printMap(map); - System.out.println("Type 'h' to get the help menu."); + ui.printTextBox(textBox); Command userCommand; while (true) { @@ -39,7 +37,8 @@ public void startGame() { setUserCommand(userCommand, map, playerStatus, textBox); if (!(map instanceof FirstMap) && userCommand instanceof MapMoveCommand) { - System.out.println("Invalid Command"); + textBox.setNextError("Invalid Command"); + } else { userCommand.execute(); } @@ -48,6 +47,7 @@ public void startGame() { if (!userCommand.getCommandDescription().equals("HelpMe!!")) { ui.printPlayerStatus(playerStatus); ui.printMap(map); + ui.printTextBox(textBox); } } } diff --git a/src/main/java/textbox/TextBox.java b/src/main/java/textbox/TextBox.java index a6d4fc2d18..3413ee87a0 100644 --- a/src/main/java/textbox/TextBox.java +++ b/src/main/java/textbox/TextBox.java @@ -4,15 +4,55 @@ import map.AMap; public class TextBox { - protected String nextMessage; + protected static String nextInstruction; + protected static String nextNarration; + protected static String nextDialogue; + protected static String nextError; public void initTextBox(){ - this.nextMessage = " "; + nextInstruction = "Type 'h' to get the help menu."; + nextDialogue = " "; + nextNarration = "Welcome to Calcula: Chronicles of the Algorithmic Kingdom"; + nextError = ""; } public void nextTextBoxBasedOnMapAndCommand(Command userCommand, AMap map){ } - public String getNextMessage(){ - return nextMessage; + + public void setNextInstruction(String message){ + nextInstruction = message; + } + public void setNextNarration(String message){ + nextNarration = message; + } + + public void setNextDialogue(String message) { + nextDialogue = message; + } + + public void setNextError(String message){ + nextError = message; + } + + public String getNextDialogue() { + return nextDialogue; } + public String getNextInstruction() { + return nextInstruction; + } + + public String getNextNarration() { + return nextNarration; + } + + public String getNextError() { + return nextError; + } + + public void clearAll(){ + nextNarration = ""; + nextInstruction = ""; + nextDialogue = ""; + nextError = ""; + } } diff --git a/src/main/java/ui/Ui.java b/src/main/java/ui/Ui.java index 02d0cd3795..c0025b230b 100644 --- a/src/main/java/ui/Ui.java +++ b/src/main/java/ui/Ui.java @@ -25,13 +25,34 @@ public void printPlayerStatus(PlayerStatus statusBar) { public void printTextBox(TextBox box) { + assert box.getNextDialogue() != null : "next dialogue is null"; + assert box.getNextError() != null : "next error is null"; + assert box.getNextInstruction() != null : "next instruction is null"; + assert box.getNextNarration() != null : "next narration is null"; + + printDividingLine(); - if (box.getNextMessage() != null) { - System.out.println(box.getNextMessage()); - } else { - System.out.println(" "); + if (!box.getNextNarration().isEmpty()) { + System.out.println(box.getNextNarration()); + System.out.println("\n"); + } + if (!box.getNextDialogue().isEmpty()) { + System.out.println(box.getNextDialogue()); + } + if (!box.getNextInstruction().isEmpty()) { + System.out.println(box.getNextInstruction()); + } + if (!box.getNextError().isEmpty()) { + System.out.println(box.getNextError()); } printDividingLine(); + box.clearAll(); + } + + public void printTextbox(String message){ //for custom messages + printDividingLine(); + System.out.println(message); + printDividingLine(); } public void printMap(AMap map) {