Updated the HostGame now has images for the maps and the map can be picked

#story[1193]
This commit is contained in:
hba56
2017-09-06 13:49:18 +12:00
parent 9560486248
commit 4eac3ea8b5
3 changed files with 49 additions and 15 deletions
@@ -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";
@@ -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<Image> 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());
}
}