Skip to content
This repository has been archived by the owner on Jan 7, 2023. It is now read-only.

Commit

Permalink
Merge pull request #99 from CSC207-2022F-UofT/features/tutorial_depen…
Browse files Browse the repository at this point in the history
…dencies

Features/tutorial dependencies
  • Loading branch information
zhaoan12 authored Dec 6, 2022
2 parents 75a7b8a + f4cc2a1 commit d454df5
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 69 deletions.
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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<String> allPhases() {
return tutorial.allPhases();
}

}

20 changes: 11 additions & 9 deletions src/main/java/com/mg105/use_cases/PlayerGetsTutorial.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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<String> tutorialPhases, int currentPhase, GiveTutorial tutorial) {
* @param currentPhase the integer representing what phase the player is on in the tutorial
*/
public PlayerGetsTutorial(List<String> tutorialPhases, int currentPhase) {
this.tutorialPhases = tutorialPhases;
this.currentPhase = currentPhase;
this.tutorial = tutorial;
this.tutorial = new GiveTutorial(false, false, false);
}

/**
Expand Down Expand Up @@ -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);
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
30 changes: 16 additions & 14 deletions src/main/java/com/mg105/user_interface/TutorialTextWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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) {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
Expand Down
18 changes: 15 additions & 3 deletions src/main/java/com/mg105/user_interface/WinMenu.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,44 @@
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;

/**
* A menu that is shown to the player after they have reached the final room
*/
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
Expand All @@ -37,6 +48,7 @@ public WinMenu(@NotNull ReplayGeneratorButton ReplayButton) {

/**
* Toggle the WinMenu
*
* @param isVisible whether the menu is visible
*/
@Override
Expand Down
Loading

0 comments on commit d454df5

Please sign in to comment.