Merge branch 'master' into story_61
Also got client-server handshake working. Multiple clients can connect and control their own boat. The client's boat has a larger black triangle drawn around it. Probably needs tidying up. Added isClientBoat boolean to VisualiserBoat. WindGenerator is now an interface, implemented by ConstantWindGenerator (useful for testing) and RandomWindGenerator. Added ConstantWindGeneratorTest. RandomWindGenerator was formerly WindGenerator. The WindGenerator is passed in to MockRace. CommandFactory throws a CommandConstructionException if it cannot create a command. MessageSerialiser and MessageDeserialiser correctly terminate on error. Readded VisualiserInput's switch statement in the main loop, pending a refactor. Removed the sleep statement from LobbyController - it was blocking javaFX thread. Lobby.fxml: moved buttons and text input into grid panes, so they don't break when you resize screen. Added some test object creation functions in several test classes (MockRaceTest.createMockRace(), BoatXMLReaderTest.createBoatDataSource(), etc...). #story[1095]
This commit is contained in:
@@ -19,6 +19,7 @@ import java.net.URL;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
//TODO it appears this view/controller was replaced by Lobby.fxml. Remove?
|
||||
/**
|
||||
* Controls the connection that the VIsualiser can connect to.
|
||||
*/
|
||||
@@ -82,11 +83,6 @@ public class ConnectionController extends Controller {
|
||||
private ObservableList<RaceConnection> connections;
|
||||
|
||||
|
||||
/**
|
||||
* Represents whether the client is currently hosting a game already - this is to ensure they don't launch multiple servers.
|
||||
*/
|
||||
private boolean currentlyHostingGame = false;
|
||||
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
|
||||
@@ -47,7 +47,7 @@ public class HostController extends Controller {
|
||||
*/
|
||||
public void hostGamePressed() throws IOException{
|
||||
try {
|
||||
Event game = new Event();
|
||||
Event game = new Event(true);
|
||||
game.start();
|
||||
connectSocket("localhost", 4942);
|
||||
} catch (EventConstructionException e) {
|
||||
@@ -78,7 +78,6 @@ public class HostController extends Controller {
|
||||
*/
|
||||
public void hostGame(){
|
||||
hostWrapper.setVisible(true);
|
||||
System.out.println("Reacted hostGame");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -58,7 +58,6 @@ public class LobbyController extends Controller {
|
||||
}
|
||||
else {
|
||||
joinGameBtn.setDisable(true);
|
||||
System.out.println(curr.statusProperty().getValue());
|
||||
}
|
||||
});
|
||||
joinGameBtn.setDisable(true);
|
||||
@@ -70,11 +69,6 @@ public class LobbyController extends Controller {
|
||||
public void refreshBtnPressed(){
|
||||
for(RaceConnection connection: connections) {
|
||||
connection.check();
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
try {
|
||||
if (lobbyTable.getSelectionModel().getSelectedItem().statusProperty().getValue().equals("Ready")) {
|
||||
|
||||
@@ -5,6 +5,7 @@ import javafx.fxml.FXML;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import visualiser.app.VisualiserInput;
|
||||
import visualiser.gameController.ControllerClient;
|
||||
import visualiser.model.ServerConnection;
|
||||
import visualiser.model.VisualiserBoat;
|
||||
import visualiser.model.VisualiserRace;
|
||||
|
||||
@@ -36,12 +37,12 @@ public class MainController extends Controller {
|
||||
|
||||
/**
|
||||
* Transitions from the StartController screen (displays pre-race information) to the RaceController (displays the actual race).
|
||||
* @param visualiserInput The object used to read packets from the race server.
|
||||
* @param visualiserRace The object modelling the race.
|
||||
* @param controllerClient Socket Client that manipulates the controller.
|
||||
* @param serverConnection The connection to the server.
|
||||
*/
|
||||
public void beginRace(VisualiserInput visualiserInput, VisualiserRace visualiserRace, ControllerClient controllerClient) {
|
||||
raceController.startRace(visualiserInput, visualiserRace, controllerClient);
|
||||
public void beginRace(VisualiserRace visualiserRace, ControllerClient controllerClient, ServerConnection serverConnection) {
|
||||
raceController.startRace(visualiserRace, controllerClient, serverConnection);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -103,10 +104,15 @@ public class MainController extends Controller {
|
||||
AnchorPane.setLeftAnchor(startController.startWrapper(), 0.0);
|
||||
AnchorPane.setRightAnchor(startController.startWrapper(), 0.0);
|
||||
|
||||
AnchorPane.setTopAnchor(connectionController.startWrapper(), 0.0);
|
||||
AnchorPane.setBottomAnchor(connectionController.startWrapper(), 0.0);
|
||||
AnchorPane.setLeftAnchor(connectionController.startWrapper(), 0.0);
|
||||
AnchorPane.setRightAnchor(connectionController.startWrapper(), 0.0);
|
||||
AnchorPane.setTopAnchor(lobbyController.startWrapper(), 0.0);
|
||||
AnchorPane.setBottomAnchor(lobbyController.startWrapper(), 0.0);
|
||||
AnchorPane.setLeftAnchor(lobbyController.startWrapper(), 0.0);
|
||||
AnchorPane.setRightAnchor(lobbyController.startWrapper(), 0.0);
|
||||
|
||||
AnchorPane.setTopAnchor(hostController.startWrapper(), 0.0);
|
||||
AnchorPane.setBottomAnchor(hostController.startWrapper(), 0.0);
|
||||
AnchorPane.setLeftAnchor(hostController.startWrapper(), 0.0);
|
||||
AnchorPane.setRightAnchor(hostController.startWrapper(), 0.0);
|
||||
|
||||
AnchorPane.setTopAnchor(finishController.finishWrapper, 0.0);
|
||||
AnchorPane.setBottomAnchor(finishController.finishWrapper, 0.0);
|
||||
|
||||
@@ -34,10 +34,6 @@ import java.util.logging.Logger;
|
||||
*/
|
||||
public class RaceController extends Controller {
|
||||
|
||||
/**
|
||||
* The object used to read packets from the connected server.
|
||||
*/
|
||||
private VisualiserInput visualiserInput;
|
||||
|
||||
/**
|
||||
* The race object which describes the currently occurring race.
|
||||
@@ -69,6 +65,11 @@ public class RaceController extends Controller {
|
||||
*/
|
||||
private ControllerClient controllerClient;
|
||||
|
||||
/**
|
||||
* The connection to the server.
|
||||
*/
|
||||
private ServerConnection serverConnection;
|
||||
|
||||
|
||||
@FXML private GridPane canvasBase;
|
||||
|
||||
@@ -351,15 +352,15 @@ public class RaceController extends Controller {
|
||||
|
||||
/**
|
||||
* Displays a specified race.
|
||||
* @param visualiserInput Object used to read packets from server.
|
||||
* @param visualiserRace Object modelling the race.
|
||||
* @param controllerClient Socket Client that manipulates the controller.
|
||||
* @param serverConnection The connection to the server.
|
||||
*/
|
||||
public void startRace(VisualiserInput visualiserInput, VisualiserRace visualiserRace, ControllerClient controllerClient) {
|
||||
public void startRace(VisualiserRace visualiserRace, ControllerClient controllerClient, ServerConnection serverConnection) {
|
||||
|
||||
this.visualiserInput = visualiserInput;
|
||||
this.visualiserRace = visualiserRace;
|
||||
this.controllerClient = controllerClient;
|
||||
this.serverConnection = serverConnection;
|
||||
|
||||
initialiseRace();
|
||||
|
||||
@@ -420,6 +421,15 @@ public class RaceController extends Controller {
|
||||
|
||||
}
|
||||
|
||||
//Return to main screen if we lose connection.
|
||||
if (!serverConnection.isAlive()) {
|
||||
race.setVisible(false);
|
||||
parent.enterTitle();
|
||||
//TODO currently this doesn't work correctly - the title screen remains visible after clicking join game
|
||||
//TODO we should display an error to the user
|
||||
//TODO also need to "reset" any state (race, connections, etc...).
|
||||
}
|
||||
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
@@ -74,6 +74,11 @@ public class StartController extends Controller implements Observer {
|
||||
*/
|
||||
private ServerConnection serverConnection;
|
||||
|
||||
/**
|
||||
* Writes BoatActions to outgoing message queue.
|
||||
*/
|
||||
private ControllerClient controllerClient;
|
||||
|
||||
|
||||
/**
|
||||
* The race object which describes the currently occurring race.
|
||||
@@ -85,7 +90,7 @@ public class StartController extends Controller implements Observer {
|
||||
/**
|
||||
* An array of colors used to assign colors to each boat - passed in to the VisualiserRace constructor.
|
||||
*/
|
||||
List<Color> colors = new ArrayList<>(Arrays.asList(
|
||||
private List<Color> colors = new ArrayList<>(Arrays.asList(
|
||||
Color.BLUEVIOLET,
|
||||
Color.BLACK,
|
||||
Color.RED,
|
||||
@@ -130,6 +135,14 @@ public class StartController extends Controller implements Observer {
|
||||
this.visualiserRace = new VisualiserRace(boatDataSource, raceDataSource, regattaDataSource, latestMessages, this.colors);
|
||||
new Thread(this.visualiserRace).start();
|
||||
|
||||
//Ugly. TODO refactor
|
||||
ObservableList<VisualiserBoat> boats = visualiserRace.getBoats();
|
||||
for (VisualiserBoat boat : boats) {
|
||||
if (boat.getSourceID() == serverConnection.getAllocatedSourceID()) {
|
||||
boat.setClientBoat(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Initialise the boat table.
|
||||
initialiseBoatTable(this.visualiserRace);
|
||||
@@ -264,7 +277,7 @@ public class StartController extends Controller implements Observer {
|
||||
startWrapper.setVisible(false);
|
||||
start.setVisible(false);
|
||||
|
||||
parent.beginRace(visualiserInput, visualiserRace, controllerClient);
|
||||
parent.beginRace(visualiserRace, controllerClient, serverConnection);
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
@@ -315,6 +328,7 @@ public class StartController extends Controller implements Observer {
|
||||
|
||||
LatestMessages latestMessages = new LatestMessages();
|
||||
this.serverConnection = new ServerConnection(socket, latestMessages);
|
||||
this.controllerClient = serverConnection.getControllerClient();
|
||||
|
||||
|
||||
//Store a reference to latestMessages so that we can observe it.
|
||||
|
||||
Reference in New Issue
Block a user