Ondřej Schlaichert 8 месяцев назад
Родитель
Сommit
ca58dc17d4

+ 21 - 1
src/main/java/eu/oschl/gui/GameController.java

@@ -5,10 +5,13 @@ import eu.oschl.gui.exceptions.InvalidActionId;
 import javafx.event.ActionEvent;
 import javafx.event.ActionEvent;
 import javafx.fxml.FXML;
 import javafx.fxml.FXML;
 import javafx.scene.control.Button;
 import javafx.scene.control.Button;
+import javafx.scene.image.Image;
+import javafx.scene.image.ImageView;
 import javafx.scene.layout.VBox;
 import javafx.scene.layout.VBox;
 import javafx.scene.text.TextFlow;
 import javafx.scene.text.TextFlow;
 
 
 import java.util.ArrayList;
 import java.util.ArrayList;
+import java.util.Objects;
 
 
 public class GameController implements Observer {
 public class GameController implements Observer {
     @FXML
     @FXML
@@ -20,6 +23,9 @@ public class GameController implements Observer {
     @FXML
     @FXML
     private VBox inventoryContainer;
     private VBox inventoryContainer;
 
 
+    @FXML
+    private ImageView mapContainer;
+
     @FXML
     @FXML
     public void initialize() {
     public void initialize() {
         Output.setOutputElement(output);
         Output.setOutputElement(output);
@@ -48,6 +54,7 @@ public class GameController implements Observer {
 
 
         renderActionButtons();
         renderActionButtons();
         renderInventoryItems();
         renderInventoryItems();
+        renderMapImage();
     }
     }
 
 
     private void renderActionButtons() {
     private void renderActionButtons() {
@@ -184,7 +191,20 @@ public class GameController implements Observer {
         inventoryContainer.getChildren().addAll(newItems);
         inventoryContainer.getChildren().addAll(newItems);
     }
     }
 
 
-    private Button createActionButton(String label, ButtonData buttonData) {
+        private void renderMapImage() {
+            var room = Session.getGame().getCurrentRoom();
+
+            if (room.getMapImagePath().isEmpty()) {
+                return;
+            }
+
+            var imageResource = Objects.requireNonNull(getClass().getResource(room.getMapImagePath().get())).toExternalForm();
+            var image = new Image(imageResource);
+
+            mapContainer.setImage(image);
+        }
+
+        private Button createActionButton(String label, ButtonData buttonData) {
         Button actionButton = new Button(label);
         Button actionButton = new Button(label);
 
 
         actionButton.setUserData(buttonData);
         actionButton.setUserData(buttonData);

+ 48 - 17
src/main/java/eu/oschl/schmorn/Setup.java

@@ -67,84 +67,114 @@ class Setup {
         // Rooms
         // Rooms
         var royalWell = new Room(
         var royalWell = new Room(
                 "Royal Well",
                 "Royal Well",
-                "The bottom of the deepest well of the Grey Princedom. Fortunately for the prince, there is no water in it."
+                "The bottom of the deepest well of the Grey Princedom. Fortunately for the prince, there is no water in it.",
+                null,
+                "images/map/royal_well.png"
         );
         );
 
 
         var crossroads = new Room(
         var crossroads = new Room(
                 "Crossroads",
                 "Crossroads",
-                "A damp chamber in the Royal Dungeon, full of unnerving, dark tunnels and entrances to other locations."
+                "A damp chamber in the Royal Dungeon, full of unnerving, dark tunnels and entrances to other locations.",
+                null,
+                "images/map/crossroads.png"
         );
         );
 
 
         var sewerEntrance = new Room(
         var sewerEntrance = new Room(
                 "Sewer Entrance",
                 "Sewer Entrance",
-                "An entrance room of the Royal Sewer."
+                "An entrance room of the Royal Sewer.",
+                null,
+                "images/map/sewer_entrance.png"
         );
         );
 
 
         var swordsmithRatsLair = new Room(
         var swordsmithRatsLair = new Room(
                 "Swordsmith Rat's Lair",
                 "Swordsmith Rat's Lair",
                 "The lair of the Rat Swordsmith. He is a master of his craft, but he is also a rat.",
                 "The lair of the Rat Swordsmith. He is a master of his craft, but he is also a rat.",
-                "Schmorn enters the chamber and is greeted by an unnerving sight. The Swordsmith Rat is lying on the floor, surrounded by his tools and weapons. He looks up at Schmorn with a mixture of fear and confusion - somehow, he seems to recognise Schmorn despite his new worm-like appearance. Once a swordsmith of the greatest reputation, he has been broken down by his imprisonment and has produced no remarkable weapons to speak of."
+                "Schmorn enters the chamber and is greeted by an unnerving sight. The Swordsmith Rat is lying on the floor, surrounded by his tools and weapons. He looks up at Schmorn with a mixture of fear and confusion - somehow, he seems to recognise Schmorn despite his new worm-like appearance. Once a swordsmith of the greatest reputation, he has been broken down by his imprisonment and has produced no remarkable weapons to speak of.",
+                "images/map/swordsmith_rats_lair.png"
         );
         );
 
 
         var prisonEntrance = new Room(
         var prisonEntrance = new Room(
                 "Prison Entrance",
                 "Prison Entrance",
-                "An entrance room to Schmorn's Royal Prison."
+                "An entrance room to Schmorn's Royal Prison.",
+                null,
+                "images/map/prison_entrance.png"
         );
         );
 
 
         var cellA = new Room(
         var cellA = new Room(
                 "Cell A",
                 "Cell A",
-                "The first cell of the Royal Prison."
+                "The first cell of the Royal Prison.",
+                null,
+                "images/map/cell_a.png"
         );
         );
 
 
         var cellB = new Room(
         var cellB = new Room(
                 "Cell B",
                 "Cell B",
-                "The second cell of the Royal Prison."
+                "The second cell of the Royal Prison.",
+                null,
+                "images/map/cell_b.png"
         );
         );
 
 
         var guardRoom = new Room(
         var guardRoom = new Room(
                 "Guard Room",
                 "Guard Room",
-                "In days long gone, when the Grey Princedom wasn't in disarray, this room was occuppied by a guard who took care of the prisoners."
+                "In days long gone, when the Grey Princedom wasn't in disarray, this room was occuppied by a guard who took care of the prisoners.",
+                null,
+                "images/map/guard_room.png"
         );
         );
 
 
         var prisonsEnd = new Room(
         var prisonsEnd = new Room(
                 "Prison's End",
                 "Prison's End",
-                "The prison does not continue beyond this point."
+                "The prison does not continue beyond this point.",
+                null,
+                "images/map/prisons_end.png"
         );
         );
 
 
         var darkEntrance = new Room(
         var darkEntrance = new Room(
                 "Dark Entrance",
                 "Dark Entrance",
-                "An entrance to the deepest and darkest parts of the Royal Dungeon."
+                "An entrance to the deepest and darkest parts of the Royal Dungeon.",
+                null,
+                "images/map/dark_entrance.png"
         );
         );
 
 
         var blackAltar = new Room(
         var blackAltar = new Room(
                 "Black Altar",
                 "Black Altar",
                 "An enormous, menacing room, full of bones and dead bodies. The centerpiece is a large, black altar made of stone, surrounded by a circle of candles. On the surface are strange runes and symbols, which appear to be bleeding.",
                 "An enormous, menacing room, full of bones and dead bodies. The centerpiece is a large, black altar made of stone, surrounded by a circle of candles. On the surface are strange runes and symbols, which appear to be bleeding.",
-                "As Schmorn enters, fear and nausea overcomes him. The air is putrid, the room stinks of death. In the middle stands a stone altar, surrounded by candles. On the surface are strange runes and symbols, which appear to be bleeding. Schmorn knows he is not alone. There is a being here, one not of this world."
+                "As Schmorn enters, fear and nausea overcomes him. The air is putrid, the room stinks of death. In the middle stands a stone altar, surrounded by candles. On the surface are strange runes and symbols, which appear to be bleeding. Schmorn knows he is not alone. There is a being here, one not of this world.",
+                "images/map/black_altar.png"
         );
         );
 
 
         var shadowChamber = new Room(
         var shadowChamber = new Room(
                 "Shadow Chamber",
                 "Shadow Chamber",
-                "A dark chamber in the Royal Dungeon, where lanterns don't work and shadows reign."
+                "A dark chamber in the Royal Dungeon, where lanterns don't work and shadows reign.",
+                null,
+                "images/map/shadow_chamber.png"
         );
         );
 
 
         var pathwaysEnd = new Room(
         var pathwaysEnd = new Room(
                 "Pathway's End",
                 "Pathway's End",
-                "The Pathway of Darkness, the darkest part of the Royal Dungeon, does not continue beyond this point."
+                "The Pathway of Darkness, the darkest part of the Royal Dungeon, does not continue beyond this point.",
+                null,
+                "images/map/pathways_end.png"
         );
         );
 
 
         var royalKitchensEntrance = new Room(
         var royalKitchensEntrance = new Room(
                 "Royal Kitchens Entrance",
                 "Royal Kitchens Entrance",
-                "An entrance to the Royal Kitchens."
+                "An entrance to the Royal Kitchens.",
+                null,
+                "images/map/royal_kitchens_entrance.png"
         );
         );
 
 
         var pantry = new Room(
         var pantry = new Room(
                 "Pantry",
                 "Pantry",
-                "A room with food and supplies for the Royal Kitchens."
+                "A room with food and supplies for the Royal Kitchens.",
+                null,
+                "images/map/pantry.png"
         );
         );
 
 
         var kitchensEnd = new Room(
         var kitchensEnd = new Room(
                 "Kitchen's End",
                 "Kitchen's End",
-                "The Royal Kitchens end here."
+                "The Royal Kitchens end here.",
+                null,
+                "images/map/kitchens_end.png"
         );
         );
 
 
         var dungeonExit = new Room(
         var dungeonExit = new Room(
@@ -156,7 +186,8 @@ 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."
                         "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 mighty 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.
-                        """
+                        """,
+                "images/map/dungeon_exit.png"
         );
         );
 
 
         var royalWellCrossroadsPassage = new Passage("crack in the wall", true);
         var royalWellCrossroadsPassage = new Passage("crack in the wall", true);

+ 12 - 2
src/main/java/eu/oschl/textadventure/map/Room.java

@@ -19,6 +19,7 @@ public class Room {
     private final String name;
     private final String name;
     private final String description;
     private final String description;
     private final String enterText;
     private final String enterText;
+    private final String mapImagePath;
 
 
     private final HashSet<Passage> passages;
     private final HashSet<Passage> passages;
     private final ArrayList<GameObject> objects;
     private final ArrayList<GameObject> objects;
@@ -27,17 +28,22 @@ public class Room {
     private boolean explored;
     private boolean explored;
     private boolean entered;
     private boolean entered;
 
 
-    public Room(String name, String description, String enterText) {
+    public Room(String name, String description, String enterText, String mapImagePath) {
         this.name = name;
         this.name = name;
         this.description = description;
         this.description = description;
         this.enterText = enterText;
         this.enterText = enterText;
         this.passages = new HashSet<>();
         this.passages = new HashSet<>();
         this.objects = new ArrayList<>();
         this.objects = new ArrayList<>();
         this.entered = false;
         this.entered = false;
+        this.mapImagePath = mapImagePath;
+    }
+
+    public Room(String name, String description, String enterText) {
+        this(name, description, enterText, null);
     }
     }
 
 
     public Room(String name, String description) {
     public Room(String name, String description) {
-        this(name, description, null);
+        this(name, description, null, null);
     }
     }
 
 
     /**
     /**
@@ -101,6 +107,10 @@ public class Room {
         this.explored = explored;
         this.explored = explored;
     }
     }
 
 
+    public Optional<String> getMapImagePath() {
+        return Optional.ofNullable(mapImagePath);
+    }
+
     /**
     /**
      * Checks if the room is blocked by an enemy.
      * Checks if the room is blocked by an enemy.
      * An enemy is considered to block the room if it is present and alive.
      * An enemy is considered to block the room if it is present and alive.

+ 1 - 1
src/main/resources/eu/oschl/gui/game.fxml

@@ -56,7 +56,7 @@
                 <clip>
                 <clip>
                     <Rectangle width="${cell.width}" height="${cell.height}"/>
                     <Rectangle width="${cell.width}" height="${cell.height}"/>
                 </clip>
                 </clip>
-                <ImageView preserveRatio="true" fitWidth="${cell.width}">
+                <ImageView fx:id="mapContainer" preserveRatio="true" fitWidth="${cell.width}">
                     <Image url="@images/map/royal_well.png"/>
                     <Image url="@images/map/royal_well.png"/>
                 </ImageView>
                 </ImageView>
             </StackPane>
             </StackPane>