diff --git a/src/main/java/com/mg105/interface_adapters/tutorial/TutorialTextController.java b/src/main/java/com/mg105/interface_adapters/tutorial/TutorialTextController.java index 54ec9583..4c4542ab 100644 --- a/src/main/java/com/mg105/interface_adapters/tutorial/TutorialTextController.java +++ b/src/main/java/com/mg105/interface_adapters/tutorial/TutorialTextController.java @@ -1,12 +1,13 @@ package com.mg105.interface_adapters.tutorial; -import com.mg105.entities.GiveTutorial; import com.mg105.use_cases.PlayerGetsTutorial; import com.mg105.utils.TutorialTexts; +import java.util.List; + public class TutorialTextController { - private final PlayerGetsTutorial tutorial = new PlayerGetsTutorial(TutorialTexts.PHASES, 0, new GiveTutorial(false, false, false)); + private final PlayerGetsTutorial tutorial = new PlayerGetsTutorial(TutorialTexts.PHASES, 0); private boolean changeText; private boolean showControls = false; @@ -42,7 +43,9 @@ public void setChangeText() { * * @return if text should start changing */ - public boolean changeText() { return this.changeText; } + public boolean changeText() { + return this.changeText; + } /** * Tell player the controls again @@ -58,7 +61,9 @@ public void setShowControls(boolean show) { * * @return whether player should be shown the control texts */ - public boolean getShowControls() { return this.showControls; } + public boolean getShowControls() { + return this.showControls; + } /** * Get an instance of the PlayerGetsTutorial use case @@ -69,5 +74,32 @@ public PlayerGetsTutorial getTutorial() { return this.tutorial; } + /** + * Get if the tutorial is complete, changes text if it is + * + * @return if the tutorial is complete + */ + public boolean isComplete() { + return tutorial.isComplete(); + } + + /** + * Returns if the action has been performed + * + * @return if the specified action has been performed + */ + public boolean getActionPerformed(String action) { + return !tutorial.getActionPerformed(action); + } + + /** + * Get names of all phases of tutorial + * + * @return the list of all tutorial phases + */ + public List allPhases() { + return tutorial.allPhases(); + } + } diff --git a/src/main/java/com/mg105/use_cases/PlayerGetsTutorial.java b/src/main/java/com/mg105/use_cases/PlayerGetsTutorial.java index e2484f1d..ecd053b0 100644 --- a/src/main/java/com/mg105/use_cases/PlayerGetsTutorial.java +++ b/src/main/java/com/mg105/use_cases/PlayerGetsTutorial.java @@ -5,23 +5,25 @@ import java.util.List; -/** Class for determining what phase of the tutorial the player is on, and changing the phase */ +/** + * Class for determining what phase of the tutorial the player is on, and changing the phase + */ public class PlayerGetsTutorial { private final List tutorialPhases; // Go through multiple phases of tutorial in order + private final GiveTutorial tutorial; private int currentPhase; - private final GiveTutorial tutorial; - /** Constructor for PlayerGetsTutorial use case + /** + * Constructor for PlayerGetsTutorial use case * * @param tutorialPhases a list of all possible phases in the tutorial - * @param currentPhase the integer representing what phase the player is on in the tutorial - * @param tutorial an instance of the GiveTutorial entity - * */ - public PlayerGetsTutorial(List tutorialPhases, int currentPhase, GiveTutorial tutorial) { + * @param currentPhase the integer representing what phase the player is on in the tutorial + */ + public PlayerGetsTutorial(List tutorialPhases, int currentPhase) { this.tutorialPhases = tutorialPhases; this.currentPhase = currentPhase; - this.tutorial = tutorial; + this.tutorial = new GiveTutorial(false, false, false); } /** @@ -73,11 +75,11 @@ public void setActionPerformed(String action) { * Check if specific action has been performed * * @param action get if it has been performed yet - * * @return if the action has been performed */ public boolean getActionPerformed(String action) { return this.tutorial.actionPerformedGetter(action); } + } diff --git a/src/main/java/com/mg105/user_interface/TutorialTextDisplay.java b/src/main/java/com/mg105/user_interface/TutorialTextDisplay.java index 4f7208b8..5f07367b 100644 --- a/src/main/java/com/mg105/user_interface/TutorialTextDisplay.java +++ b/src/main/java/com/mg105/user_interface/TutorialTextDisplay.java @@ -25,7 +25,7 @@ public TutorialTextDisplay() { */ public String showBottomText(String displayedText) { String tutorialText; - int phase_idx = tutorialControl.getTutorial().allPhases().indexOf(displayedText); + int phase_idx = tutorialControl.allPhases().indexOf(displayedText); tutorialText = TutorialTexts.PHASES_TEXT.get(phase_idx); return tutorialText; diff --git a/src/main/java/com/mg105/user_interface/TutorialTextWindow.java b/src/main/java/com/mg105/user_interface/TutorialTextWindow.java index 31c93235..b792a85b 100644 --- a/src/main/java/com/mg105/user_interface/TutorialTextWindow.java +++ b/src/main/java/com/mg105/user_interface/TutorialTextWindow.java @@ -14,7 +14,7 @@ import javafx.scene.text.Font; import org.jetbrains.annotations.NotNull; -public class TutorialTextWindow implements Toggleable{ +public class TutorialTextWindow implements Toggleable { TutorialTextDisplay tutorialDisplay; Pane tutorialPane = new Pane(); Label bottomText = new Label(); @@ -24,7 +24,8 @@ public class TutorialTextWindow implements Toggleable{ /** * Window for the tutorial - * @param textController the controller for the tutorial + * + * @param textController the controller for the tutorial * @param tutorialDisplay the ui that displays the tutorial */ public TutorialTextWindow(TutorialTextController textController, @NotNull TutorialTextDisplay tutorialDisplay) { @@ -52,7 +53,9 @@ public TutorialTextWindow(TutorialTextController textController, @NotNull Tutori * @return the scene to be displayed. */ @Override - public @NotNull Scene getScene() {return tutorialScene;} + public @NotNull Scene getScene() { + return tutorialScene; + } /** * Set the visibility of this component. @@ -88,25 +91,24 @@ public void handle(long now) { bottomText.setText(tutorialDisplay.showBottomText(tutorialText)); } - if (textController.getShowControls() & textController.getTutorial().isComplete()){ + if (textController.getShowControls() & textController.isComplete()) { helpText.setText(tutorialDisplay.showControlsText()); - helpTimer --; - if (helpTimer < 1){ + helpTimer--; + if (helpTimer < 1) { textController.setShowControls(false); helpTimer = TutorialTexts.HELP_TIME; } } else if (textController.getShowControls()) { - if (!textController.getTutorial().getActionPerformed(TutorialTexts.MOVED)){ - helpText.setText(TutorialTexts.DID_NOT_MOVE); - } else if (!textController.getTutorial().getActionPerformed(TutorialTexts.USED_ITEM)) { - helpText.setText(TutorialTexts.DID_NOT_OPEN_CHEST); - } - else { + if (textController.getActionPerformed(TutorialTexts.MOVED)) { + helpText.setText(TutorialTexts.DID_NOT_MOVE); + } else if (textController.getActionPerformed(TutorialTexts.USED_ITEM)) { + helpText.setText(TutorialTexts.DID_NOT_OPEN_CHEST); + } else { helpText.setText(TutorialTexts.DID_NOT_BATTLE); } - helpTimer --; - if (helpTimer < 1){ + helpTimer--; + if (helpTimer < 1) { textController.setShowControls(false); helpTimer = TutorialTexts.HELP_TIME; } diff --git a/src/main/java/com/mg105/user_interface/WinMenu.java b/src/main/java/com/mg105/user_interface/WinMenu.java index f6d4a157..cdf57678 100644 --- a/src/main/java/com/mg105/user_interface/WinMenu.java +++ b/src/main/java/com/mg105/user_interface/WinMenu.java @@ -1,9 +1,13 @@ package com.mg105.user_interface; +import com.mg105.utils.TutorialTexts; +import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; +import javafx.scene.control.Label; import javafx.scene.layout.Pane; import javafx.scene.layout.StackPane; +import javafx.scene.text.Font; import org.jetbrains.annotations.NotNull; /** @@ -11,23 +15,30 @@ */ public class WinMenu implements Toggleable { private final @NotNull Scene scene; - private final @NotNull Pane layout; /** * Shows a button that congratulates you and lets you replay the game + * * @param ReplayButton the button responsible for replaying the game */ public WinMenu(@NotNull ReplayGeneratorButton ReplayButton) { + Label winLbl = new Label(); + winLbl.setText("Congratulations on reaching the final room!!"); + winLbl.setFont(Font.font(TutorialTexts.TEXT_SIZE_LARGE)); + StackPane.setAlignment(winLbl, Pos.TOP_CENTER); + Button generateMapButton = new Button("You Won! Replay The Game"); - //Clean Inventory generateMapButton.setOnAction(ReplayButton); - layout = new StackPane(); + + @NotNull Pane layout = new StackPane(); layout.getChildren().add(generateMapButton); + layout.getChildren().add(winLbl); scene = new Scene(layout, 600, 600); } /** * Get scene of the WinMenu + * * @return the scene that WinMenu is in */ @Override @@ -37,6 +48,7 @@ public WinMenu(@NotNull ReplayGeneratorButton ReplayButton) { /** * Toggle the WinMenu + * * @param isVisible whether the menu is visible */ @Override diff --git a/src/main/java/com/mg105/utils/TutorialTexts.java b/src/main/java/com/mg105/utils/TutorialTexts.java index b6ff52a1..baffe5e3 100644 --- a/src/main/java/com/mg105/utils/TutorialTexts.java +++ b/src/main/java/com/mg105/utils/TutorialTexts.java @@ -7,83 +7,128 @@ * Constants for texts related to the tutorial */ public class TutorialTexts { - /** Constant string for move phase */ + /** + * Constant string for move phase + */ public static final String MOVED = "moved"; - /** Constant string for attack phase */ + /** + * Constant string for attack phase + */ public static final String ATTACKED = "attacked"; - /** Constant string for using item phase */ + /** + * Constant string for using item phase + */ public static final String USED_ITEM = "usedItem"; - /** Constant int for x size of helper pane */ + /** + * Constant int for x size of helper pane + */ public static final int HELPER_PANE_X = 420; - /** Constant int for y size of helper pane */ + /** + * Constant int for y size of helper pane + */ public static final int HELPER_PANE_Y = 100; - /** Constant int for text duration per phase */ + /** + * Constant int for text duration per phase + */ public static final int TEXT_DURATION1 = 3; - /** Constant int for size of the text */ + /** + * Constant int for size of the regular text + */ public static final int TEXT_SIZE = 14; - /** Constant int for text duration of helper text (not in seconds)*/ + /** + * Constant int for size of the larger text + */ + public static final int TEXT_SIZE_LARGE = 20; + + /** + * Constant int for text duration of helper text (not in seconds) + */ public static final int HELP_TIME = 250; - /** Constant array listing all the phases */ + /** + * Constant array listing all the phases + */ public static final List PHASES = Arrays.asList("...", "story", "tell move", "tell attack", "tell use item", "exit room", "hotkeys"); - /** Constant array containing the actual text shown to the player */ + /** + * Constant array containing the actual text shown to the player + */ public static final List PHASES_TEXT = Arrays.asList("", TutorialTexts.STORY, TutorialTexts.TELL_MOVE, TutorialTexts.TELL_ATTACK, TutorialTexts.TELL_USE_ITEM, TutorialTexts.EXIT_ROOM, TutorialTexts.HOTKEYS); - /** Constant string for story text */ + /** + * Constant string for story text + */ public static final String STORY = """ Welcome to mountain climber. You must battle your way to the top of the mountain. Inside various rooms you will encounter enemies and find treasures."""; - /** Constant string for move text */ + /** + * Constant string for move text + */ public static final String TELL_MOVE = "Move your character with the WASD keys."; - /** Constant string for attack text */ + /** + * Constant string for attack text + */ public static final String TELL_ATTACK = "Use the battle button [f] to attack the enemies."; - /** Constant string for open chest text */ + /** + * Constant string for open chest text + */ public static final String TELL_USE_ITEM = "Open treasure chests using the [e] key.."; - /** Constant string for good luck text */ + /** + * Constant string for good luck text + */ public static final String EXIT_ROOM = "Good luck on your journey!"; - /** Constant string for telling player the game controls */ + /** + * Constant string for telling player the game controls + */ public static final String CONTROLS = """ Hotkeys: Press K for help. Press WASD to return to game.\s Game Controls: Use WASD to move. Use battle key [f] to \s initiate battles. Open chests using [e]."""; - /** Constant string for telling the player the hotkeys */ + /** + * Constant string for telling the player the hotkeys + */ public static final String HOTKEYS = "Hint: Press [WASD] to return to the game. Press K for help!"; - /** Constant string reminding player how to move */ + /** + * Constant string reminding player how to move + */ public static final String DID_NOT_MOVE = """ - You haven't completed the tutorial yet ... + You haven't completed the tutorial yet ... - You should return to the game and move you character with [WASD]! - (Pressing WASD in this window will return you to the game.) - """; + You should return to the game and move you character with [WASD]! + (Pressing WASD in this window will return you to the game.) + """; - /** Constant string for reminding player to open chest */ + /** + * Constant string for reminding player to open chest + */ public static final String DID_NOT_OPEN_CHEST = """ - You haven't completed the tutorial yet ... + You haven't completed the tutorial yet ... - You should go open a chest! Do this using the [e] key. - (Pressing WASD in this window will return you to the game.) - """; + You should go open a chest! Do this using the [e] key. + (Pressing WASD in this window will return you to the game.) + """; - /** Constant string for reminding player to initiate a battle */ + /** + * Constant string for reminding player to initiate a battle + */ public static final String DID_NOT_BATTLE = """ - You haven't completed the tutorial yet ... + You haven't completed the tutorial yet ... - You should go fight a battle! Use [f] key to initiate a battle. - (Pressing WASD in this window will return you to the game.) - """; + You should go fight a battle! Use [f] key to initiate a battle. + (Pressing WASD in this window will return you to the game.) + """; } diff --git a/src/test/java/com/mg105/use_cases/Tutorial/TutorialInteractorTest.java b/src/test/java/com/mg105/use_cases/Tutorial/TutorialInteractorTest.java index ec37c3c7..a275fda6 100644 --- a/src/test/java/com/mg105/use_cases/Tutorial/TutorialInteractorTest.java +++ b/src/test/java/com/mg105/use_cases/Tutorial/TutorialInteractorTest.java @@ -1,6 +1,5 @@ package com.mg105.use_cases.Tutorial; -import com.mg105.entities.GiveTutorial; import com.mg105.use_cases.PlayerGetsTutorial; import com.mg105.user_interface.TutorialTextDisplay; import com.mg105.utils.TutorialTexts; @@ -12,7 +11,7 @@ public class TutorialInteractorTest { @Test void testAdvancePhase() { PlayerGetsTutorial tutorialPlayer - = new PlayerGetsTutorial(TutorialTexts.PHASES, 0, new GiveTutorial(false, false, false)); + = new PlayerGetsTutorial(TutorialTexts.PHASES, 0); assertEquals(tutorialPlayer.currentPhase(), 0); tutorialPlayer.nextPhase(); @@ -26,13 +25,12 @@ void testAdvancePhase() { @Test void testTutorialComplete() { PlayerGetsTutorial tutorialPlayer1 - = new PlayerGetsTutorial(TutorialTexts.PHASES, 0, - new GiveTutorial(false, false, false)); + = new PlayerGetsTutorial(TutorialTexts.PHASES, 0); PlayerGetsTutorial tutorialPlayer2 - = new PlayerGetsTutorial(TutorialTexts.PHASES, 0, - new GiveTutorial(false, false, true)); + = new PlayerGetsTutorial(TutorialTexts.PHASES, 0); tutorialPlayer2.setActionPerformed(TutorialTexts.MOVED); tutorialPlayer2.setActionPerformed(TutorialTexts.ATTACKED); + tutorialPlayer2.setActionPerformed(TutorialTexts.USED_ITEM); assertFalse(tutorialPlayer1.getActionPerformed(TutorialTexts.MOVED)); assertFalse(tutorialPlayer1.getActionPerformed(TutorialTexts.ATTACKED));