Tutorial text now displays on screen when in tutorial. #story[1189]

This commit is contained in:
David Wu
2017-09-10 19:31:56 +12:00
parent 9a96131a33
commit c6594a0e20
3 changed files with 50 additions and 17 deletions
@@ -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<String, ControlKey> 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;
}