Merge branch 'master' into story_64_sails
# Conflicts: # racevisionGame/src/main/java/mock/app/MockOutput.java # racevisionGame/src/main/java/mock/model/MockRace.java # racevisionGame/src/main/java/mock/model/commandFactory/CommandFactory.java # racevisionGame/src/main/java/network/MessageDecoders/BoatActionDecoder.java # racevisionGame/src/main/java/network/MessageDecoders/BoatLocationDecoder.java # racevisionGame/src/main/java/visualiser/app/VisualiserInput.java # racevisionGame/src/main/java/visualiser/gameController/ControllerServer.java # racevisionGame/src/main/java/visualiser/model/ResizableRaceCanvas.java # racevisionGame/src/main/java/visualiser/model/VisualiserRace.java # racevisionGame/src/main/resources/visualiser/scenes/connect.fxml # racevisionGame/src/main/resources/visualiser/scenes/lobby.fxml # racevisionGame/src/test/java/mock/model/MockRaceTest.java # racevisionGame/src/test/java/network/Utils/AC35UnitConverterTest.java # racevisionGame/src/test/java/network/XMLMessageEncoderTest.java
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
package mock.model.commandFactory;
|
||||
|
||||
import mock.exceptions.CommandConstructionException;
|
||||
import mock.model.MockBoat;
|
||||
import mock.model.MockRace;
|
||||
import network.Messages.Enums.BoatActionEnum;
|
||||
import network.Messages.BoatAction;
|
||||
import shared.exceptions.BoatNotFoundException;
|
||||
|
||||
/**
|
||||
* Factory class for Command objects
|
||||
@@ -11,19 +13,28 @@ public class CommandFactory {
|
||||
/**
|
||||
* Generates a command on a race and boat corresponding to the protocol action number.
|
||||
* @param race to receive command
|
||||
* @param boat to receive command in race
|
||||
* @param action number to select command
|
||||
* @return
|
||||
* @return The command to execute the given action.
|
||||
* @throws CommandConstructionException Thrown if the command cannot be constructed (e.g., unknown action type).
|
||||
*/
|
||||
public static Command createCommand(MockRace race, MockBoat boat, BoatActionEnum action) {
|
||||
switch(action) {
|
||||
public static Command createCommand(MockRace race, BoatAction action) throws CommandConstructionException {
|
||||
|
||||
MockBoat boat = null;
|
||||
try {
|
||||
boat = race.getBoat(action.getSourceID());
|
||||
|
||||
} catch (BoatNotFoundException e) {
|
||||
throw new CommandConstructionException("Could not create command for BoatAction: " + action + ". Boat with sourceID: " + action.getSourceID() + " not found.", e);
|
||||
|
||||
}
|
||||
|
||||
switch(action.getBoatAction()) {
|
||||
case AUTO_PILOT: return new VMGCommand(race, boat);
|
||||
case TACK_GYBE: return new TackGybeCommand(race, boat);
|
||||
case UPWIND: return new WindCommand(race, boat, true);
|
||||
case DOWNWIND: return new WindCommand(race, boat, false);
|
||||
case SAILS_OUT: return new SailsCommand(race, boat, true);
|
||||
case SAILS_IN: return new SailsCommand(race, boat, false);
|
||||
default: return null; // TODO - please please have discussion over what to default to
|
||||
|
||||
default: throw new CommandConstructionException("Could not create command for BoatAction: " + action + ". Unknown BoatAction.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,31 +2,30 @@ package mock.model.commandFactory;
|
||||
|
||||
import mock.model.MockBoat;
|
||||
import mock.model.MockRace;
|
||||
import mock.model.VMG;
|
||||
import shared.model.Bearing;
|
||||
|
||||
/**
|
||||
* Created by David on 2/08/2017.
|
||||
* Command class for tacking and gybing
|
||||
*/
|
||||
public class TackGybeCommand implements Command {
|
||||
private MockRace race;
|
||||
private MockBoat boat;
|
||||
|
||||
/**
|
||||
* Constructor for class
|
||||
* @param race mock race
|
||||
* @param boat mock boat to update
|
||||
*/
|
||||
public TackGybeCommand(MockRace race, MockBoat boat) {
|
||||
this.race = race;
|
||||
this.boat = boat;
|
||||
}
|
||||
|
||||
//The refactoring of MockRace will require changes to be made
|
||||
@Override
|
||||
public void execute() {
|
||||
/*if(boat.getBearing().degrees()>180){
|
||||
boat.setBearing(Bearing.fromDegrees(360 - race.getWindDirection().degrees()));
|
||||
} else {
|
||||
boat.setBearing(Bearing.fromDegrees(race.getWindDirection().degrees()));
|
||||
}*/
|
||||
/*double angle = Math.max(race.getWindDirection().degrees(), boat.getBearing().degrees()) - Math.min(race.getWindDirection().degrees(), boat.getBearing().degrees());
|
||||
boat.setBearing(Bearing.fromDegrees(angle));*/
|
||||
|
||||
boat.setAutoVMG(false);
|
||||
|
||||
double boatAngle = boat.getBearing().degrees();
|
||||
double windAngle =race.getWindDirection().degrees();
|
||||
double differenceAngle = calcDistance(boatAngle, windAngle);
|
||||
@@ -39,10 +38,15 @@ public class TackGybeCommand implements Command {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to calculate smallest angle between 2 angles
|
||||
* @param degreeA first angle degree
|
||||
* @param degreeB second angle degree
|
||||
* @return the calculated smallest angle
|
||||
*/
|
||||
public double calcDistance(double degreeA, double degreeB){
|
||||
double phi = Math.abs(degreeB - degreeA) % 360;
|
||||
double distance = phi > 180 ? 360 - phi : phi;
|
||||
return distance;
|
||||
return phi > 180 ? 360 - phi : phi;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,26 +4,28 @@ import mock.model.MockBoat;
|
||||
import mock.model.MockRace;
|
||||
|
||||
/**
|
||||
* Created by David on 2/08/2017.
|
||||
* Command class for autoVMG
|
||||
*/
|
||||
public class VMGCommand implements Command {
|
||||
private MockRace race;
|
||||
private MockBoat boat;
|
||||
|
||||
/**
|
||||
* Constructor for class
|
||||
* @param race mock race
|
||||
* @param boat mock boat to update
|
||||
*/
|
||||
public VMGCommand(MockRace race, MockBoat boat) {
|
||||
this.race = race;
|
||||
this.boat = boat;
|
||||
}
|
||||
|
||||
//The refactoring of MockRace will require changes to be made
|
||||
@Override
|
||||
public void execute() {
|
||||
if (boat.getAutoVMG()){
|
||||
boat.setAutoVMG(false);
|
||||
System.out.println("Auto VMG off!");
|
||||
} else {
|
||||
boat.setAutoVMG(true);
|
||||
System.out.println("Auto VMG on!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,13 +20,17 @@ public class WindCommand implements Command {
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
|
||||
boat.setAutoVMG(false);
|
||||
|
||||
double wind = race.getWindDirection().degrees();
|
||||
double heading = boat.getBearing().degrees();
|
||||
|
||||
double offset = 3.0;
|
||||
|
||||
offset *= direction;
|
||||
if(wind - heading < 0) offset *= -1;
|
||||
double headWindDelta = wind - heading;
|
||||
if ((headWindDelta < 0) || (headWindDelta > 180)) offset *= -1;
|
||||
|
||||
boat.setBearing(Bearing.fromDegrees(heading + offset));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user