Jelajahi Sumber

Made exploration necessary for progression

Ondřej Schlaichert 8 bulan lalu
induk
melakukan
e7370e6b0c

+ 2 - 0
src/main/java/eu/oschl/cli/commands/Explore.java

@@ -46,6 +46,8 @@ public class Explore implements Command {
         var objects = room.getObjects();
         var passages = room.getPassages();
 
+        room.setExplored(true);
+
         Console.print(room.getName(), ConsoleColor.BG_BLUE);
         Console.printLine();
         Console.print(room.getDescription(), ConsoleColor.BLUE);

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

@@ -62,6 +62,12 @@ public class GameController implements Observer {
                     var passages = room.getPassages();
 
                     for (var passage : passages) {
+                        var lastPassage = Session.getGame().getLastPassage();
+
+                        if (!Session.getGame().getCurrentRoom().isExplored() && (lastPassage.isEmpty() || passage != lastPassage.get())) {
+                            continue;
+                        }
+
                         var label = passage.isSeeThrough() || passage.getOtherRoom(room).wasEntered()
                                 ? enter.getName() + " " + passage.getName() + " (>> " + passage.getOtherRoom(Session.getGame().getCurrentRoom()).getName() + ")"
                                 : enter.getName() + " " + passage.getName() + " (>> ???)";
@@ -75,6 +81,10 @@ public class GameController implements Observer {
                     }
                 }
                 case PressButton pressButton -> {
+                    if (!Session.getGame().getCurrentRoom().isExplored()) {
+                        continue;
+                    }
+
                     if (Session.getGame().getCurrentRoom().isBlockedByEnemy()) {
                         continue;
                     }
@@ -95,6 +105,10 @@ public class GameController implements Observer {
                     }
                 }
                 case Slay slay -> {
+                    if (!Session.getGame().getCurrentRoom().isExplored()) {
+                        continue;
+                    }
+
                     var enemy = Session.getGame().getCurrentRoom().getEnemy();
 
                     if (enemy.isPresent() && enemy.get().isAlive()) {
@@ -109,6 +123,10 @@ public class GameController implements Observer {
                     }
                 }
                 case TakeItem takeItem -> {
+                    if (!Session.getGame().getCurrentRoom().isExplored()) {
+                        continue;
+                    }
+
                     if (Session.getGame().getCurrentRoom().isBlockedByEnemy()) {
                         continue;
                     }

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

@@ -32,6 +32,8 @@ public class Explore implements Action {
         var objects = room.getObjects();
         var passages = room.getPassages();
 
+        room.setExplored(true);
+
         Output.print(room.getName(), Color.ALICEBLUE);
         Output.printLine();
         Output.print(room.getDescription(), Color.LIGHTBLUE);

+ 9 - 0
src/main/java/eu/oschl/textadventure/map/Room.java

@@ -24,6 +24,7 @@ public class Room {
     private final ArrayList<GameObject> objects;
     private Enemy enemy;
 
+    private boolean explored;
     private boolean entered;
 
     public Room(String name, String description, String enterText) {
@@ -92,6 +93,14 @@ public class Room {
         return entered;
     }
 
+    public boolean isExplored() {
+        return explored;
+    }
+
+    public void setExplored(boolean explored) {
+        this.explored = explored;
+    }
+
     /**
      * Checks if the room is blocked by an enemy.
      * An enemy is considered to block the room if it is present and alive.