VMGCommand now toggles autoVMG on and off. Linked up observer and observable so the current boat can now be controlled.
#Story[1097]
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package mock.app;
|
||||
|
||||
import mock.model.RaceLogic;
|
||||
import network.Messages.Enums.XMLMessageType;
|
||||
import network.Messages.LatestMessages;
|
||||
import network.Messages.XMLMessage;
|
||||
@@ -43,6 +44,10 @@ public class ConnectionAcceptor implements Runnable {
|
||||
private short boatXMLSequenceNumber;
|
||||
//regatta xml sequence number
|
||||
private short regattaXMLSequenceNumber;
|
||||
//controller server
|
||||
private ControllerServer controllerServer;
|
||||
//
|
||||
private RaceLogic rl = null;
|
||||
|
||||
/**
|
||||
* Connection Acceptor Constructor
|
||||
@@ -65,6 +70,11 @@ public class ConnectionAcceptor implements Runnable {
|
||||
return serverPort;
|
||||
}
|
||||
|
||||
|
||||
public void setRace(RaceLogic rl){
|
||||
this.rl = rl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the Acceptor
|
||||
*/
|
||||
@@ -76,9 +86,10 @@ public class ConnectionAcceptor implements Runnable {
|
||||
Socket mockSocket = serverSocket.accept();
|
||||
DataOutputStream outToVisualiser = new DataOutputStream(mockSocket.getOutputStream());
|
||||
MockOutput mockOutput = new MockOutput(latestMessages, outToVisualiser);
|
||||
ControllerServer controllerServer = new ControllerServer(mockSocket);
|
||||
this.controllerServer = new ControllerServer(mockSocket, rl);
|
||||
new Thread(mockOutput).start();
|
||||
new Thread(controllerServer).start();
|
||||
System.out.println("I'm in connectionAcceptor");
|
||||
mockOutputList.add(mockOutput);
|
||||
System.out.println(String.format("%d number of Visualisers Connected.", mockOutputList.size()));
|
||||
} catch (IOException e) {
|
||||
|
||||
@@ -82,6 +82,7 @@ public class Event {
|
||||
* @throws InvalidRegattaDataException Thrown if the regatta xml file cannot be parsed.
|
||||
*/
|
||||
public void start() throws InvalidRaceDataException, XMLReaderException, InvalidBoatDataException, InvalidRegattaDataException {
|
||||
|
||||
new Thread(mockOutput).start();
|
||||
|
||||
sendXMLs();
|
||||
@@ -94,7 +95,11 @@ public class Event {
|
||||
//Create and start race.
|
||||
RaceLogic newRace = new RaceLogic(new MockRace(boatDataSource, raceDataSource, regattaDataSource, this.latestMessages, this.boatPolars, Constants.RaceTimeScale), this.latestMessages);
|
||||
|
||||
mockOutput.setRace(newRace);
|
||||
|
||||
new Thread(newRace).start();
|
||||
|
||||
System.out.println("I'm in event");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -203,4 +203,8 @@ public class MockBoat extends Boat {
|
||||
public void setAutoVMG(boolean autoVMG) {
|
||||
this.autoVMG = autoVMG;
|
||||
}
|
||||
|
||||
public boolean getAutoVMG(){
|
||||
return autoVMG;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package mock.model.commandFactory;
|
||||
|
||||
import mock.model.MockBoat;
|
||||
import mock.model.MockRace;
|
||||
import shared.model.Bearing;
|
||||
|
||||
/**
|
||||
* Created by David on 2/08/2017.
|
||||
@@ -28,5 +29,6 @@ public class TackGybeCommand implements Command {
|
||||
if(race.improvesVelocity(boatVMG, newVMG, boat.calculateBearingToNextMarker())){
|
||||
boat.setVMG(newVMG);
|
||||
}*/
|
||||
this.boat.setBearing(Bearing.fromDegrees(360 - boat.getBearing().degrees()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,5 +25,12 @@ public class VMGCommand implements Command {
|
||||
Bearing.fromDegrees(0d),
|
||||
Bearing.fromDegrees(359.99999d));
|
||||
boat.setVMG(newVMG);*/
|
||||
if (boat.getAutoVMG()){
|
||||
boat.setAutoVMG(false);
|
||||
System.out.println("Auto VMG off!");
|
||||
} else {
|
||||
boat.setAutoVMG(true);
|
||||
System.out.println("Auto VMG on!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package visualiser.gameController;
|
||||
|
||||
import mock.model.RaceLogic;
|
||||
import mock.model.commandFactory.Command;
|
||||
import mock.model.commandFactory.CommandFactory;
|
||||
import network.BinaryMessageDecoder;
|
||||
@@ -29,13 +30,19 @@ public class ControllerServer extends Observable implements Runnable {
|
||||
* Last received boat action
|
||||
*/
|
||||
private BoatActionEnum action;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private RaceLogic rc;
|
||||
|
||||
/**
|
||||
* Initialise server-side controller with live client socket
|
||||
* @param socket to client
|
||||
*/
|
||||
public ControllerServer(Socket socket) {
|
||||
public ControllerServer(Socket socket, RaceLogic rc) {
|
||||
this.socket = socket;
|
||||
this.rc = rc;
|
||||
this.addObserver(rc);
|
||||
try {
|
||||
this.inputStream = new DataInputStream(this.socket.getInputStream());
|
||||
} catch (IOException e) {
|
||||
|
||||
Reference in New Issue
Block a user