Quellcode durchsuchen

Added button to quit game once it is completed

Ondřej Schlaichert vor 8 Monaten
Ursprung
Commit
7213247f9b

+ 5 - 0
pom.xml

@@ -25,6 +25,11 @@
             <artifactId>javafx-fxml</artifactId>
             <version>21.0.6</version>
         </dependency>
+        <dependency>
+            <groupId>org.openjfx</groupId>
+            <artifactId>javafx-web</artifactId>
+            <version>21.0.6</version>
+        </dependency>
 
         <dependency>
             <groupId>org.junit.jupiter</groupId>

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

@@ -37,7 +37,8 @@ public class ActionProcessor extends Observable {
                 new PressButton(game),
                 new TakeItem(game),
                 new Enter(game),
-                new UseItem(game)
+                new UseItem(game),
+                new Quit()
         ));
     }
 

+ 9 - 4
src/main/java/eu/oschl/gui/GameController.java

@@ -62,6 +62,12 @@ public class GameController implements Observer {
 
         var newButtons = new ArrayList<Button>();
 
+        if (!Session.getGame().isRunning()) {
+            newButtons.add(createActionButton("Quit game", new ButtonData("quit")));
+            inputButtonContainer.getChildren().addAll(newButtons);
+            return;
+        }
+
         for (Action action : Session.getActionProcessor().getActions()) {
             switch (action) {
                 case Enter enter -> {
@@ -153,7 +159,7 @@ public class GameController implements Observer {
                         }
                     }
                 }
-                case UseItem _ -> {
+                case UseItem _, Quit _ -> {
                 }
                 default -> newButtons.add(createActionButton(action.getName(), new ButtonData(action.getId())));
             }
@@ -192,12 +198,11 @@ public class GameController implements Observer {
     }
 
     private void finishGame() {
-        inputButtonContainer.getChildren().clear();
-        inventoryContainer.getChildren().clear();
-
         Output.printLine();
         Output.printLine();
         Output.print(Session.getGame().getEpilogue());
+
+        renderActionButtons();
     }
 
     private void renderMapImage() {

+ 22 - 0
src/main/java/eu/oschl/gui/Session.java

@@ -12,6 +12,7 @@ import javafx.scene.control.ButtonType;
 import javafx.scene.input.KeyCode;
 import javafx.scene.input.KeyCodeCombination;
 import javafx.scene.input.KeyCombination;
+import javafx.scene.web.WebView;
 import javafx.stage.Stage;
 
 import java.io.IOException;
@@ -67,6 +68,9 @@ public class Session extends Application {
         KeyCombination restartKeyCombination = new KeyCodeCombination(KeyCode.R, KeyCombination.CONTROL_DOWN);
         scene.getAccelerators().put(restartKeyCombination, () -> handleRestartRequest(stage));
 
+        KeyCombination helpKeyCombination = new KeyCodeCombination(KeyCode.F1);
+        scene.getAccelerators().put(helpKeyCombination, this::handleHelpRequest);
+
         stage.show();
     }
 
@@ -102,4 +106,22 @@ public class Session extends Application {
             Output.print(game.getPrologue());
         }
     }
+
+    private void handleHelpRequest() {
+        var helpStage = new Stage();
+        WebView webView = new WebView();
+
+        Scene helpScene = new Scene(webView);
+
+        helpStage.setScene(helpScene);
+        helpStage.setTitle("Schmorn Help");
+        helpStage.show();
+
+        var helpPath = Objects.requireNonNull(Session.class.getResource("help.html")).toExternalForm();
+
+        webView.getEngine().load(helpPath);
+
+        helpStage.setWidth(1280);
+        helpStage.setHeight(720);
+    }
 }

+ 25 - 0
src/main/java/eu/oschl/gui/actions/Quit.java

@@ -0,0 +1,25 @@
+package eu.oschl.gui.actions;
+
+import javafx.application.Platform;
+
+public class Quit implements Action {
+    @Override
+    public String getId() {
+        return "quit";
+    }
+
+    @Override
+    public String getName() {
+        return "Quit game";
+    }
+
+    @Override
+    public String getDescription() {
+        return "quit the game";
+    }
+
+    @Override
+    public void execute(String[] args) {
+        Platform.exit();
+    }
+}

+ 5 - 0
src/main/java/eu/oschl/schmorn/Launcher.java

@@ -2,6 +2,11 @@ package eu.oschl.schmorn;
 
 import eu.oschl.textadventure.Game;
 
+/**
+ * Handles starting either CLI or GUI version of the game
+ *
+ * @author Ondřej Schlaichert
+ */
 public class Launcher {
     private static String[] args;
 

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

@@ -1,7 +1,7 @@
 package eu.oschl.schmorn;
 
 /**
- * Serves as an entry point, handles starting either CLI or GUI version of the game.
+ * Serves as an entry point.
  *
  * @author Ondřej Schlaichert
  */

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

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

+ 95 - 0
src/main/resources/eu/oschl/gui/help.html

@@ -0,0 +1,95 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Schmorn Help & Information</title>
+    <link rel="preconnect" href="https://fonts.googleapis.com">
+    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
+    <link href="https://fonts.googleapis.com/css2?family=Iosevka+Slab:wght@400;700&display=swap" rel="stylesheet">
+    <style>
+		body {
+			font-family: 'Iosevka Slab', monospace;
+            font-size: 1.3rem;
+			line-height: 1.6;
+			padding: 20px;
+			background-color: #000000;
+			color: #ffffff;
+			max-width: 800px;
+			margin: 0 auto;
+		}
+		h1 {
+			color: #ffffff;
+			border-bottom: 1px solid #ffffff;
+			padding-bottom: 10px;
+			margin-top: 0;
+			font-weight: 700;
+		}
+		h2 {
+			color: #ffffff;
+			margin-top: 25px;
+			font-weight: 700;
+		}
+		p {
+			margin-bottom: 15px;
+		}
+		ul {
+			list-style-type: none;
+			margin-left: 0;
+			padding-left: 0;
+		}
+		li {
+			margin-bottom: 8px;
+			padding-left: 1.2em;
+			position: relative;
+		}
+		li:before {
+			content: '-';
+			position: absolute;
+			left: 0;
+			color: #ffffff;
+		}
+		code {
+			background-color: #333333;
+			padding: 2px 4px;
+			border-radius: 2px;
+			font-family: 'Iosevka Slab', monospace;
+			color: #ffffff;
+		}
+		strong {
+			color: #ffffff;
+		}
+		hr {
+			border: none;
+			border-top: 1px solid #555555;
+			margin: 30px 0;
+		}
+    </style>
+</head>
+<body>
+
+<h1>Schmorn Help</h1>
+<p><strong>Schmorn</strong> is a simple text adventure game made in Java as part of the <strong>4IT115</strong> course at the <strong>Prague University of Economics and Business (VŠE)</strong>.</p>
+<p>The game tells a story of Schmorn, a weak, inept and power-hungry prince, who gets turned into a worm as a punishment for seeking unlimited power from Oglunda, a powerful witch. The witch casts Schmorn into his Royal Well, forcing him to crawl through the Royal Underground to reach the surface and get his revenge.</p>
+
+<hr>
+
+<h2>How to play?</h2>
+<ul>
+    <li>All gameplay is handled by pressing appropriate buttons. Press buttons to explore, fight enemies, etc.</li>
+    <li>The inventory is also interactable: click on a collected item to use it.</li>
+    <li>Press <strong>Ctrl+R</strong> to restart the game at any time.</li>
+    <li>Press <strong>F1</strong> to show this help screen.</li>
+</ul>
+
+<hr>
+
+<h2>Additional information</h2>
+<ul>
+    <li>Author: <strong>Ondřej Schlaichert</strong></li>
+    <li>Semester: <strong>ZS 2025/2026</strong></li>
+    <li>Version: <strong>1.0.0</strong></li>
+</ul>
+
+</body>
+</html>