From ba30d774e2862f8afb71840b25e37e5e9d34b256 Mon Sep 17 00:00:00 2001 From: vanderken <98792743+vanderken@users.noreply.github.com> Date: Sat, 4 Oct 2025 14:04:17 +0800 Subject: [PATCH] Create Dialogue.java pang handle sa each line --- Main/Dialogue.java | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Main/Dialogue.java diff --git a/Main/Dialogue.java b/Main/Dialogue.java new file mode 100644 index 0000000..7da86b7 --- /dev/null +++ b/Main/Dialogue.java @@ -0,0 +1,24 @@ + +public class Dialogue { + private String speaker; + private String text; + + public Dialogue(String speaker, String text) { + this.speaker = speaker; + this.text = text; + } + + public void display(String playerName) { + String out = text; + if (playerName != null && !playerName.isEmpty()) { + out = out.replace("(name)", playerName).replace("(Name)", playerName); + } + if ("ANNOUNCER".equalsIgnoreCase(speaker)) { + System.out.println("\n[" + speaker.toUpperCase() + "]: " + out); + } else if ("NARRATION".equalsIgnoreCase(speaker)) { + System.out.println("\n" + out); + } else { + System.out.println("\n" + speaker + ": " + out); + } + } +}