Ondřej Schlaichert пре 8 месеци
родитељ
комит
194174f685

+ 1 - 1
src/main/java/eu/oschl/cli/commands/UseItem.java

@@ -33,7 +33,7 @@ public class UseItem implements Command {
     @Override
     public void execute(String[] args) {
         if (args.length == 0) {
-            Console.print("What item?", ConsoleColor.RED);
+            Output.print("What item?", ConsoleColor.RED);
             return;
         }
 

+ 41 - 0
src/main/java/eu/oschl/gui/Output.java

@@ -0,0 +1,41 @@
+package eu.oschl.gui;
+
+import javafx.scene.paint.Color;
+import javafx.scene.text.Text;
+import javafx.scene.text.TextFlow;
+
+public class Output {
+    private static TextFlow outputElement;
+
+    public static void setOutputElement(TextFlow outputElement) {
+        Output.outputElement = outputElement;
+    }
+
+    /**
+     * Prints a message to the output with the specified JavaFX color.
+     *
+     * @param message the message to print
+     * @param color the color in which to print the message
+     */
+    public static void print(String message, Color color) {
+        var text = new Text(message);
+        text.setFill(color);
+        outputElement.getChildren().add(new Text(message));
+    }
+
+    /**
+     * Prints a message to the output in the default color.
+     *
+     * @param message the message to print
+     */
+    public static void print(String message) {
+        print(message, Color.BLACK);
+    }
+
+    /**
+     * Prints a line break to the console.
+     */
+    public static void printLine() {
+        print("\n");
+    }
+}

+ 29 - 0
src/main/java/eu/oschl/gui/actions/Action.java

@@ -0,0 +1,29 @@
+package eu.oschl.gui.actions;
+
+/***
+ * This interface defines the structure for commands in the console application.
+ *
+ * @author Ondřej Schlaichert
+ */
+public interface Action {
+    /**
+     * Returns ID of the action.
+     *
+     * @return a string ID/name
+     */
+    String getId();
+
+    /**
+     * Returns a description of what the action does.
+     *
+     * @return a string description of the action
+     */
+    String getDescription();
+
+    /**
+     * Executes the action with the provided arguments.
+     *
+     * @param args an array of strings representing the action arguments
+     */
+    void execute(String[] args);
+}

+ 101 - 0
src/main/java/eu/oschl/gui/actions/Explore.java

@@ -0,0 +1,101 @@
+package eu.oschl.gui.actions;
+
+import eu.oschl.gui.Output;
+import eu.oschl.textadventure.Game;
+import eu.oschl.textadventure.map.Passage;
+import javafx.scene.paint.Color;
+
+public class Explore implements Action {
+    private final Game game;
+
+    public Explore(Game game) {
+        this.game = game;
+    }
+
+    @Override
+    public String getId() {
+        return "explore";
+    }
+
+    @Override
+    public String getDescription() {
+        return "find out information about the current area";
+    }
+
+    public void execute(String[] args) {
+        var room = this.game.getCurrentRoom();
+        var objects = room.getObjects();
+        var passages = room.getPassages();
+
+        Output.print(room.getName(), Color.BLUEVIOLET);
+        Output.printLine();
+        Output.print(room.getDescription(), Color.BLUE);
+
+        if (room.getEnemy().isPresent()) {
+            if (room.getEnemy().get().isAlive()) {
+                Output.printLine();
+                Output.printLine();
+
+                Output.print(room.getEnemy().get().getName(), Color.ORANGERED);
+                Output.print(" blocks the way.", Color.RED);
+                Output.printLine();
+                Output.print(room.getEnemy().get().getDescription(), Color.RED);
+                Output.printLine();
+                Output.printLine();
+                Output.print(room.getEnemy().get().getName(), Color.RED);
+                Output.print(" must be defeated to continue further.");
+
+                return;
+            } else {
+                Output.printLine();
+                Output.printLine();
+                Output.print("The corpse of ");
+                Output.print(room.getEnemy().get().getName(), Color.ORANGERED);
+                Output.print(" lies on the ground.");
+            }
+        }
+
+        if (!objects.isEmpty()) {
+            Output.printLine();
+            Output.printLine();
+
+            if (objects.size() == 1) {
+                Output.print("there is something in this room: ", Color.MAGENTA);
+            } else {
+                Output.print("there are " + objects.size() + " things in this room: ", Color.MAGENTA);
+            }
+            for (var object : objects) {
+                Output.printLine();
+                Output.print(" * " + object.getName(), Color.MAGENTA);
+                Output.print(", " + object.getDescription(), Color.WHITE);
+            }
+        }
+
+        if (!passages.isEmpty()) {
+            Output.printLine();
+            Output.printLine();
+
+            if (passages.size() == 1) {
+                Output.print("there is a passage leading out of here: ", Color.YELLOW);
+            } else {
+                Output.print("there are " + passages.size() + " passages leading out of here: ", Color.YELLOW);
+            }
+
+            for (Passage passage : passages) {
+                Output.printLine();
+                Output.print(" * " + passage.getName(), Color.YELLOW);
+
+                if (passage.getDescription().isPresent()) {
+                    Output.print(", " + passage.getDescription().get(), Color.WHITE);
+                }
+
+                if (passage.isSeeThrough() || passage.getOtherRoom(room).wasEntered()) {
+                    Output.print(" - leading to ");
+                    Output.print(passage.getOtherRoom(room).getName(), Color.BLUE);
+                } else {
+                    Output.print(" - it's impossible to see what's on the other side", Color.RED);
+                }
+            }
+        }
+    }
+}

+ 1 - 0
src/main/java/module-info.java

@@ -1,6 +1,7 @@
 module eu.oschl.gui {
     requires javafx.controls;
     requires javafx.fxml;
+    requires eu.oschl.gui;
 
 
     opens eu.oschl.gui to javafx.fxml;