Tutorial states implemented and working. Game currently prints to terminal the "tutorial text". Next step is to create display on application for these text. Game ends when tutorial ends. Fixed game not loading xml issue. #story[1189]

main
David Wu 8 years ago
parent 28ec4b9246
commit d2d5ae62eb

@ -94,6 +94,7 @@ public class Event {
}
if (gameType == 2){
System.out.println("In gametype 2");
raceXMLFile = "mock/mockXML/raceTutorial.xml";
boatsXMLFile = "mock/mockXML/boatTutorial.xml";
regattaXMLFile = "mock/mockXML/regattaTutorial.xml";

@ -159,4 +159,6 @@ public class HostController extends Controller {
this.gameType = gameType;
}
public int getGameType(){ return this.gameType; }
}

@ -98,6 +98,8 @@ public class MainController extends Controller {
hostController.setGameType(gameType);
}
public int getGameType(){ return hostController.getGameType(); }
/**
* Main Controller for the applications will house the menu and the displayed pane.
*

@ -24,6 +24,7 @@ import shared.dataInput.RaceDataSource;
import shared.model.Leg;
import shared.model.Mark;
import visualiser.app.App;
import visualiser.enums.TutorialState;
import visualiser.gameController.ControllerClient;
import visualiser.gameController.Keys.ControlKey;
import visualiser.gameController.Keys.KeyFactory;
@ -34,6 +35,8 @@ 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.logging.Level;
@ -58,6 +61,13 @@ public class RaceController extends Controller {
private boolean isHost;
private TutorialState currentState;
private ArrayList<TutorialState> tutorialStates;
private boolean isTutorial = false;
/**
* state of the info table
*/
@ -110,13 +120,25 @@ public class RaceController extends Controller {
if(controlKey != null) {
try {
controlKey.onAction(); // Change key state if applicable
if (isTutorial){
if (controlKey.getProtocolCode().equals(currentState.getAction())){
updateTutorialState();
}
}
controllerClient.sendKey(controlKey);
event.consume();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
Logger.getGlobal().log(Level.WARNING, "RaceController was interrupted on thread: " + Thread.currentThread() + "while sending: " + controlKey, e);
} catch (Exception e) {
e.printStackTrace();
}
}
if(event.getCode() == KeyCode.ESCAPE) {
try {
@ -246,6 +268,8 @@ public class RaceController extends Controller {
}
/**
* Initialises the frame rate functionality. This allows for toggling the frame rate, and connect the fps label to the race's fps property.
* @param visualiserRace The race to connect the fps label to.
@ -422,6 +446,18 @@ public class RaceController extends Controller {
this.controllerClient = controllerClient;
this.isHost = isHost;
//Check if the game is a tutorial
if (parent.getGameType()==2){
isTutorial = true;
tutorialStates = new ArrayList<>(Arrays.asList(TutorialState.values()));
currentState = tutorialStates.get(0);
tutorialStates.remove(0);
System.out.println(currentState);
System.out.println(tutorialStates);
}
initialiseRace();
//Display this controller.
@ -519,4 +555,53 @@ public class RaceController extends Controller {
infoTableShow = !infoTableShow;
}
private void updateTutorialState() throws Exception {
switch (currentState){
case UPWIND:
System.out.println("You turned upwind. Now go downwind.");
currentState = tutorialStates.get(0);
tutorialStates.remove(0);
break;
case DOWNWIND:
System.out.println("You turned downwind. Now go tack/gybe.");
currentState = tutorialStates.get(0);
tutorialStates.remove(0);
break;
case TACKGYBE:
System.out.println("You tack/gybe. Now go VMG.");
currentState = tutorialStates.get(0);
tutorialStates.remove(0);
break;
case VMG:
System.out.println("You VMG. Now sails-in.");
currentState = tutorialStates.get(0);
tutorialStates.remove(0);
break;
case SAILSIN:
System.out.println("You sails-in. Now sails-out.");
currentState = tutorialStates.get(0);
tutorialStates.remove(0);
break;
case SAILSOUT:
System.out.println("You sails-out. Tutorial finished. Well done!");
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle("Finished Tutorial");
alert.setHeaderText("You have finished the tutorial.");
alert.setContentText("Now you know the controls you are ready to race!");
Optional<ButtonType> result = alert.showAndWait();
if (result.get() == ButtonType.OK) {
parent.endEvent();
racePane.setVisible(false);
App.app.showMainStage(App.getStage());
}
break;
default:
System.out.println("Something went wrong.");
currentState = tutorialStates.get(0);
tutorialStates.remove(0);
break;
}
}
}

@ -86,9 +86,6 @@ public class StartController extends Controller {
/**
* Ctor.
*/

@ -0,0 +1,66 @@
package visualiser.enums;
import javafx.scene.input.KeyCode;
import network.Messages.BoatAction;
import network.Messages.Enums.BoatActionEnum;
import visualiser.gameController.Keys.ControlKey;
import static visualiser.app.App.keyFactory;
import java.util.ArrayList;
/**
* Created by zwu18 on 10/09/17.
*/
public enum TutorialState {
// keyState.put("Z", new ZoomInKey());
// keyState.put("X", new ZoomOutKey());
// keyState.put("SPACE", new VMGKey());
// keyState.put("SHIFT", new SailsToggleKey());
// keyState.put("ENTER", new TackGybeKey());
// keyState.put("UP", new UpWindKey());
// keyState.put("DOWN", new DownWindKey());
/**
* State for upwind in tutorial
*/
UPWIND(BoatActionEnum.UPWIND),
/**
* State for downwind in tutorial
*/
DOWNWIND(BoatActionEnum.DOWNWIND),
/**
* State for tacking/gybing in tutorial
*/
TACKGYBE(BoatActionEnum.TACK_GYBE),
/**
* State for vmg in tutorial
*/
VMG(BoatActionEnum.AUTO_PILOT),
/**
* State for sails-in in tutorial
*/
SAILSIN(BoatActionEnum.SAILS_IN),
/**
* State for sails-out in tutorial
*/
SAILSOUT(BoatActionEnum.SAILS_OUT);
private BoatActionEnum action;
TutorialState(BoatActionEnum action){
this.action = action;
}
public BoatActionEnum getAction(){
return action;
}
}

@ -5,7 +5,6 @@
<CreationTimeDate>RACE_CREATION_TIME</CreationTimeDate>
<RaceStartTime Postpone="false" Time="RACE_START_TIME"/>
<Participants>
<Yacht SourceID="126"/>
</Participants>
<CompoundMarkSequence>
<Corner SeqID="1" CompoundMarkID="1" Rounding="SP" ZoneSize="3" />

@ -5,9 +5,6 @@
<CreationTimeDate>RACE_CREATION_TIME</CreationTimeDate>
<RaceStartTime Postpone="false" Time="RACE_START_TIME"/>
<Participants>
<Yacht SourceID="124"/>
<Yacht SourceID="125"/>
<Yacht SourceID="126"/>
</Participants>
<CompoundMarkSequence>
<Corner SeqID="1" CompoundMarkID="1" Rounding="SP" ZoneSize="3" />

@ -5,7 +5,7 @@
<CreationTimeDate>RACE_CREATION_TIME</CreationTimeDate>
<RaceStartTime Postpone="false" Time="RACE_START_TIME"/>
<Participants>
<Yacht SourceID="121"/>
<!--<Yacht SourceID="121"/>-->
</Participants>
<CompoundMarkSequence>
<Corner SeqID="1" CompoundMarkID="1" Rounding="SP" ZoneSize="3" />

@ -1,5 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.chart.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.chart.LineChart?>
<?import javafx.scene.chart.NumberAxis?>
@ -22,7 +28,7 @@
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.text.Font?>
<SplitPane fx:id="racePane" dividerPositions="1.0" prefHeight="431.0" prefWidth="610.0" visible="false" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.RaceController">
<SplitPane fx:id="racePane" dividerPositions="1.0" prefHeight="431.0" prefWidth="610.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.RaceController">
<items>
<GridPane fx:id="canvasBase">
<columnConstraints>
@ -46,16 +52,16 @@
<CheckBox fx:id="showBoatPath" mnemonicParsing="false" selected="true" text="Show Boat Paths" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="75.0" />
<CheckBox fx:id="showTime" mnemonicParsing="false" selected="true" text="Show Boat Leg Time" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="100.0" />
<CheckBox fx:id="showEstTime" mnemonicParsing="false" selected="true" text="Show Est. Time to Next Mark" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="125.0" />
<CheckBox fx:id="showGuideline" mnemonicParsing="false" text="Show Guideline" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="150.0" />
<CheckBox fx:id="showGuideline" mnemonicParsing="false" text="Show Guideline" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="150.0" />
<Separator layoutX="19.6" layoutY="175.6" prefHeight="0.0" prefWidth="200.0" AnchorPane.leftAnchor="10.0" AnchorPane.topAnchor="175.0" />
<Label text="Annotations" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="175.0" />
<RadioButton fx:id="hideAnnoRBtn" mnemonicParsing="false" text="Hidden" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="200.0">
<toggleGroup>
<ToggleGroup fx:id="annoToggleGroup" />
</toggleGroup></RadioButton>
<RadioButton fx:id="showAnnoRBtn" mnemonicParsing="false" text="Visible" toggleGroup="$annoToggleGroup" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="225.0" />
<RadioButton fx:id="partialAnnoRBtn" mnemonicParsing="false" text="Partial" toggleGroup="$annoToggleGroup" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="250.0" />
<RadioButton fx:id="importantAnnoRBtn" mnemonicParsing="false" text="Important" toggleGroup="$annoToggleGroup" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="275.0" />
<Label text="Annotations" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="175.0" />
<RadioButton fx:id="hideAnnoRBtn" mnemonicParsing="false" text="Hidden" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="200.0">
<toggleGroup>
<ToggleGroup fx:id="annoToggleGroup" />
</toggleGroup></RadioButton>
<RadioButton fx:id="showAnnoRBtn" mnemonicParsing="false" text="Visible" toggleGroup="$annoToggleGroup" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="225.0" />
<RadioButton fx:id="partialAnnoRBtn" mnemonicParsing="false" text="Partial" toggleGroup="$annoToggleGroup" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="250.0" />
<RadioButton fx:id="importantAnnoRBtn" mnemonicParsing="false" text="Important" toggleGroup="$annoToggleGroup" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="275.0" />
<Button fx:id="saveAnno" layoutX="11.0" layoutY="126.0" mnemonicParsing="false" text="Save Important Annotations" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="300.0" />
</children>
</AnchorPane>

Loading…
Cancel
Save