Переглянути джерело

Added epilogue and finishing the game

Ondřej Schlaichert 8 місяців тому
батько
коміт
97e002ecec

+ 2 - 1
src/main/java/eu/oschl/gui/ActionProcessor.java

@@ -30,7 +30,8 @@ public class ActionProcessor extends Observable {
             new Slay(game),
             new PressButton(game),
             new TakeItem(game),
-            new Enter(game)
+            new Enter(game),
+            new UseItem(game)
         ));
 
         return new ActionProcessor(actions);

+ 16 - 0
src/main/java/eu/oschl/gui/GameController.java

@@ -41,6 +41,11 @@ public class GameController implements Observer {
 
     @Override
     public void update() {
+        if (!Session.getGame().isRunning()) {
+            finishGame();
+            return;
+        }
+
         renderActionButtons();
         renderInventoryItems();
     }
@@ -123,6 +128,8 @@ public class GameController implements Observer {
                         }
                     }
                 }
+                case UseItem _ -> {
+                }
                 default -> newButtons.add(createActionButton(action.getName(), new ButtonData(action.getId())));
             }
         }
@@ -168,4 +175,13 @@ public class GameController implements Observer {
 
         return actionButton;
     }
+
+    private void finishGame() {
+        inputButtonContainer.getChildren().clear();
+        inventoryContainer.getChildren().clear();
+
+        Output.printLine();
+        Output.printLine();
+        Output.print(Session.getGame().getEpilogue());
+    }
 }

+ 56 - 0
src/main/java/eu/oschl/gui/actions/UseItem.java

@@ -0,0 +1,56 @@
+package eu.oschl.gui.actions;
+
+import eu.oschl.gui.Output;
+import eu.oschl.textadventure.Game;
+import javafx.scene.paint.Color;
+
+public class UseItem implements Action {
+    private final Game game;
+
+    public UseItem(Game game) {
+        this.game = game;
+    }
+
+    @Override
+    public String getId() {
+        return "useitem";
+    }
+
+    @Override
+    public String getName() {
+        return "Use item";
+    }
+
+    @Override
+    public String getDescription() {
+        return "use an item";
+    }
+
+    @Override
+    public void execute(String[] args) {
+        if (args.length == 0) {
+            Output.print("What item?", Color.RED);
+            return;
+        }
+
+        var item = this.game.getInventory().getItems().stream()
+                .filter(inventoryItem -> inventoryItem.getName().equalsIgnoreCase(String.join(" ", args)))
+                .findFirst()
+                .orElse(null);
+
+        if (item == null) {
+            Output.print("That item does not exist.", Color.RED);
+            return;
+        }
+
+        var result = item.use();
+
+        if (result) {
+            Output.print(item.getUseText(), Color.MAGENTA);
+        } else {
+            Output.print("It's impossible to use ", Color.RED);
+            Output.print(item.getName(), Color.MAGENTA);
+            Output.print(" here.", Color.RED);
+        }
+    }
+}

+ 1 - 1
src/main/java/eu/oschl/schmorn/Setup.java

@@ -155,7 +155,7 @@ class Setup {
                     
                         "And so, here you are, you determined failure of a man. You have made it this far, but you will not leave this place. Not as a worm, not as a prince, not as anything. I stand in your path, and I will not let you pass. You have made your choice, and now you must live with the consequences."
                     
-                        Schmorn stares at her, fearful yet defiant. In his worm mouth, he holds the might Unbreakable Ladle, the most powerful weapon in his kingdom. He is ready to fight. Oglunda does not know what's coming.
+                        Schmorn stares at her, fearful yet defiant. In his worm mouth, he holds the mighty Unbreakable Ladle, the most powerful weapon in his kingdom. He is ready to fight. Oglunda does not know what's coming.
                         """
         );