Merge branch 'Development' into story_64_sails
# Conflicts: # racevisionGame/src/main/java/mock/model/commandFactory/CommandFactory.java # racevisionGame/src/main/java/visualiser/model/ResizableRaceCanvas.java # racevisionGame/src/test/java/mock/model/MockBoatTest.java
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package mock.model.commandFactory;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Queue;
|
||||
|
||||
/**
|
||||
* Wraps multiple commands into a composite to execute queued commands during a frame.
|
||||
*/
|
||||
public class CompositeCommand implements Command {
|
||||
private Queue<Command> commands;
|
||||
|
||||
public CompositeCommand() {
|
||||
this.commands = new ArrayDeque<>();
|
||||
}
|
||||
|
||||
public void addCommand(Command command) {
|
||||
commands.add(command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
while(!commands.isEmpty()) commands.remove().execute();
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@ 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.
|
||||
@@ -18,15 +20,30 @@ public class TackGybeCommand implements Command {
|
||||
//The refactoring of MockRace will require changes to be made
|
||||
@Override
|
||||
public void execute() {
|
||||
/*VMG newVMG = boat.getPolars().calculateVMG(
|
||||
race.getWindDirection(),
|
||||
race.getWindSpeed(),
|
||||
boat.calculateBearingToNextMarker(),
|
||||
Bearing.fromDegrees(0d),
|
||||
Bearing.fromDegrees(359.99999d));
|
||||
VMG boatVMG = new VMG(boat.getCurrentSpeed(), boat.getBearing());
|
||||
if(race.improvesVelocity(boatVMG, newVMG, boat.calculateBearingToNextMarker())){
|
||||
boat.setVMG(newVMG);
|
||||
/*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));*/
|
||||
double boatAngle = boat.getBearing().degrees();
|
||||
double windAngle =race.getWindDirection().degrees();
|
||||
double differenceAngle = calcDistance(boatAngle, windAngle);
|
||||
double angleA = windAngle + differenceAngle;
|
||||
double angleB = windAngle - differenceAngle;
|
||||
if(angleA % 360 == boatAngle){
|
||||
boat.setBearing(Bearing.fromDegrees(angleB));
|
||||
} else {
|
||||
boat.setBearing(Bearing.fromDegrees(angleA));
|
||||
}
|
||||
}
|
||||
|
||||
public double calcDistance(double degreeA, double degreeB){
|
||||
double phi = Math.abs(degreeB - degreeA) % 360;
|
||||
double distance = phi > 180 ? 360 - phi : phi;
|
||||
return distance;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -18,12 +18,12 @@ public class VMGCommand implements Command {
|
||||
//The refactoring of MockRace will require changes to be made
|
||||
@Override
|
||||
public void execute() {
|
||||
/*VMG newVMG = boat.getPolars().calculateVMG(
|
||||
race.getWindDirection(),
|
||||
race.getWindSpeed(),
|
||||
boat.calculateBearingToNextMarker(),
|
||||
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!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package mock.model.commandFactory;
|
||||
|
||||
import mock.model.MockBoat;
|
||||
import mock.model.MockRace;
|
||||
import shared.model.Bearing;
|
||||
|
||||
/**
|
||||
* Created by connortaylorbrown on 4/08/17.
|
||||
*/
|
||||
public class WindCommand implements Command {
|
||||
private MockRace race;
|
||||
private MockBoat boat;
|
||||
private int direction;
|
||||
|
||||
public WindCommand(MockRace race, MockBoat boat, boolean upwind) {
|
||||
this.race = race;
|
||||
this.boat = boat;
|
||||
this.direction = upwind? -1 : 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
double wind = race.getWindDirection().degrees();
|
||||
double heading = boat.getBearing().degrees();
|
||||
|
||||
double offset = 3.0;
|
||||
|
||||
offset *= direction;
|
||||
if(wind - heading < 0) offset *= -1;
|
||||
|
||||
boat.setBearing(Bearing.fromDegrees(heading + offset));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user