From 4eac3ea8b584b7d5a0c34ce703dc2b5f03e57566 Mon Sep 17 00:00:00 2001 From: hba56 Date: Wed, 6 Sep 2017 13:49:18 +1200 Subject: [PATCH] Updated the HostGame now has images for the maps and the map can be picked #story[1193] --- .../src/main/java/mock/app/Event.java | 16 ++++++++-- .../Controllers/HostController.java | 32 +++++++++++++++++-- .../resources/visualiser/scenes/hostgame.fxml | 16 ++++------ 3 files changed, 49 insertions(+), 15 deletions(-) diff --git a/racevisionGame/src/main/java/mock/app/Event.java b/racevisionGame/src/main/java/mock/app/Event.java index 08ef14f0..a1fc5072 100644 --- a/racevisionGame/src/main/java/mock/app/Event.java +++ b/racevisionGame/src/main/java/mock/app/Event.java @@ -78,12 +78,22 @@ public class Event { * @param singlePlayer Whether or not to create a single player event. * @throws EventConstructionException Thrown if we cannot create an Event for any reason. */ - public Event(boolean singlePlayer) throws EventConstructionException { + public Event(boolean singlePlayer, int mapIndex) throws EventConstructionException { System.out.println(XMLUtilities.validateXML(this.getClass().getClassLoader().getResource("mock/mockXML/iMapLayout.xml").toString() , this.getClass().getClassLoader().getResource("mock/mockXML/schema/raceSchema.xsd"))); - //String raceXMLFile = "mock/mockXML/raceTest.xml"; - String raceXMLFile = "mock/mockXML/iMapLayout.xml"; + + String raceXMLFile; + switch (mapIndex){ + case 0:raceXMLFile = "mock/mockXML/raceTest.xml"; + break; + case 1:raceXMLFile = "mock/mockXML/oMapLayout.xml"; + break; + case 2: raceXMLFile = "mock/mockXML/iMapLayout.xml"; + break; + default:raceXMLFile = "mock/mockXML/raceTest.xml"; + + } String boatsXMLFile = "mock/mockXML/boatTest.xml"; String regattaXMLFile = "mock/mockXML/regattaTest.xml"; diff --git a/racevisionGame/src/main/java/visualiser/Controllers/HostController.java b/racevisionGame/src/main/java/visualiser/Controllers/HostController.java index 993847cb..9ea5bce6 100644 --- a/racevisionGame/src/main/java/visualiser/Controllers/HostController.java +++ b/racevisionGame/src/main/java/visualiser/Controllers/HostController.java @@ -3,6 +3,7 @@ package visualiser.Controllers; import javafx.fxml.FXML; import javafx.scene.control.Button; import javafx.scene.control.TextField; +import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.layout.AnchorPane; import mock.app.Event; @@ -18,6 +19,8 @@ import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; import java.net.Socket; import java.net.URL; +import java.util.ArrayList; +import java.util.Arrays; import java.util.ResourceBundle; import java.util.logging.Level; import java.util.logging.Logger; @@ -48,9 +51,17 @@ public class HostController extends Controller { private Event game; + private ArrayList listOfMaps; + private int currentMapIndex = 0; + @Override - public void initialize(URL location, ResourceBundle resources) { + public void initialize(URL location, ResourceBundle resources){ + Image ac35Map = new Image(getClass().getClassLoader().getResourceAsStream("images/AC35_Racecourse_MAP.png")); + Image oMap = new Image(getClass().getClassLoader().getResourceAsStream("images/oMapLayout.png")); + + listOfMaps = new ArrayList(Arrays.asList(ac35Map, oMap)); + mapImage.setImage(listOfMaps.get(currentMapIndex)); } /** @@ -59,7 +70,7 @@ public class HostController extends Controller { */ public void hostGamePressed() throws IOException{ try { - this.game = new Event(false); + this.game = new Event(false, currentMapIndex); connectSocket("localhost", 4942); } catch (EventConstructionException e) { Logger.getGlobal().log(Level.SEVERE, "Could not create Event.", e); @@ -100,4 +111,21 @@ public class HostController extends Controller { parent.enterTitle(); } + public void nextImage(){ + increaseIndex(); + mapImage.setImage(listOfMaps.get(currentMapIndex)); + } + + public void previousImage(){ + decreaseIndex(); + mapImage.setImage(listOfMaps.get(currentMapIndex)); + } + private void increaseIndex(){ + currentMapIndex = (currentMapIndex + 1)%listOfMaps.size(); + } + + private void decreaseIndex(){ + currentMapIndex = ((((currentMapIndex - 1)%listOfMaps.size())+listOfMaps.size())%listOfMaps.size()); + } + } diff --git a/racevisionGame/src/main/resources/visualiser/scenes/hostgame.fxml b/racevisionGame/src/main/resources/visualiser/scenes/hostgame.fxml index cb830237..92308af3 100644 --- a/racevisionGame/src/main/resources/visualiser/scenes/hostgame.fxml +++ b/racevisionGame/src/main/resources/visualiser/scenes/hostgame.fxml @@ -19,9 +19,9 @@ - - - + + + - - - - - -