From c6594a0e20f2efaca30f87c71d25b8fcff3745fa Mon Sep 17 00:00:00 2001 From: David Wu Date: Sun, 10 Sep 2017 19:31:56 +1200 Subject: [PATCH] Tutorial text now displays on screen when in tutorial. #story[1189] --- .../Controllers/RaceController.java | 64 ++++++++++++++----- .../resources/visualiser/scenes/race.fxml | 1 + .../visualiser/scenes/titleScreen.fxml | 2 +- 3 files changed, 50 insertions(+), 17 deletions(-) diff --git a/racevisionGame/src/main/java/visualiser/Controllers/RaceController.java b/racevisionGame/src/main/java/visualiser/Controllers/RaceController.java index bb3e0fec..fe519224 100644 --- a/racevisionGame/src/main/java/visualiser/Controllers/RaceController.java +++ b/racevisionGame/src/main/java/visualiser/Controllers/RaceController.java @@ -34,10 +34,7 @@ import visualiser.utils.GPSConverter; import java.io.IOException; import java.net.URL; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Optional; -import java.util.ResourceBundle; +import java.util.*; import java.util.logging.Level; import java.util.logging.Logger; @@ -66,6 +63,8 @@ public class RaceController extends Controller { private boolean isTutorial = false; + private String keyToPress; + /** * state of the info table @@ -84,6 +83,8 @@ public class RaceController extends Controller { @FXML private SplitPane racePane; + @FXML private Label tutorialText; + /** * This is the pane we place the actual arrow control inside of. @@ -469,12 +470,19 @@ public class RaceController extends Controller { //Check if the game is a tutorial if (parent.getGameType()==2){ isTutorial = true; + tutorialText.setVisible(true); tutorialStates = new ArrayList<>(Arrays.asList(TutorialState.values())); - System.out.println(tutorialStates); + currentState = tutorialStates.get(0); tutorialStates.remove(0); - System.out.println("Welcome to tutorial. Exit at anytime with ESC. Turn upwind."); + searchMapForKey("Upwind"); + + tutorialText.setText("Welcome to the tutorial! Exit at anytime with ESC. \nWe will first learn how to turn upwind. Press " + keyToPress + " to turn upwind."); + + } else { + isTutorial = false; + tutorialText.setVisible(false); } initialiseRace(); @@ -574,43 +582,69 @@ public class RaceController extends Controller { infoTableShow = !infoTableShow; } + /** + * Get the next tutorial state + */ private void updateTutorialState(){ currentState = tutorialStates.get(0); tutorialStates.remove(0); } + /** + * Search key map for key given string of command + * @param command the command of the key + */ + private void searchMapForKey(String command){ + for (Map.Entry entry: keyFactory.getKeyState().entrySet()){ + if(entry.getValue().toString().equals(command)){ + keyToPress = entry.getKey(); + } + } + } + + /** + * Updates tutorial state and gui display for tutorial text + * @throws Exception Exception thrown + */ private void checkTutorialState() throws Exception { switch (currentState){ case UPWIND: - System.out.println("You turned upwind. Now go downwind."); + searchMapForKey("Downwind"); + tutorialText.setText("Nice! To turn downwind press " + keyToPress + "."); updateTutorialState(); break; case DOWNWIND: - System.out.println("You turned downwind. Now go tack/gybe."); + searchMapForKey("Tack/Gybe"); + tutorialText.setText("Nice! To tack or gybe press " + keyToPress + "."); updateTutorialState(); break; case TACKGYBE: - System.out.println("You tack/gybe. Now go VMG."); + searchMapForKey("VMG"); + tutorialText.setText("Nice! To use VMG press " + keyToPress + "."); updateTutorialState(); break; case VMG: - System.out.println("You VMG. Now sails-in."); + searchMapForKey("Toggle Sails"); + tutorialText.setText("Nice! To sails in press " + keyToPress + "."); updateTutorialState(); break; case SAILSIN: - System.out.println("You sails-in. Now sails-out."); + searchMapForKey("Toggle Sails"); + tutorialText.setText("Nice! To sails out press " + keyToPress + " again."); updateTutorialState(); break; case SAILSOUT: - System.out.println("You sails-out. Now zoom in."); + searchMapForKey("Zoom In"); + tutorialText.setText("Nice! To zoom in press " + keyToPress + "."); updateTutorialState(); break; case ZOOMIN: - System.out.println("You zoomed in. Now zoom out."); + searchMapForKey("Zoom Out"); + tutorialText.setText("Nice! To zoom out press " + keyToPress + "."); updateTutorialState(); break; case ZOOMOUT: - System.out.println("You zoomed out. Tutorial finished. Well done!"); + tutorialText.setText("Congratulations! You're done!"); Alert alert = new Alert(Alert.AlertType.INFORMATION); alert.setTitle("Finished Tutorial"); alert.setHeaderText("You have finished the tutorial."); @@ -624,8 +658,6 @@ public class RaceController extends Controller { break; default: System.out.println("Something went wrong."); - currentState = tutorialStates.get(0); - tutorialStates.remove(0); break; } diff --git a/racevisionGame/src/main/resources/visualiser/scenes/race.fxml b/racevisionGame/src/main/resources/visualiser/scenes/race.fxml index 215d12a3..7b45641b 100644 --- a/racevisionGame/src/main/resources/visualiser/scenes/race.fxml +++ b/racevisionGame/src/main/resources/visualiser/scenes/race.fxml @@ -108,6 +108,7 @@ +