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() { boat.setAutoVMG(false); double wind = race.getWindDirection().degrees(); double heading = boat.getBearing().degrees(); double offset = 3.0; offset *= direction; double headWindDelta = wind - heading; if ((headWindDelta < 0) || (headWindDelta > 180)) offset *= -1; boat.setBearing(Bearing.fromDegrees(heading + offset)); } }