Merge branch 'master' into story_64_sails
# Conflicts: # racevisionGame/src/main/java/visualiser/gameController/Keys/ControlKey.java # racevisionGame/src/main/java/visualiser/gameController/Keys/SailsToggleKey.java # racevisionGame/src/main/java/visualiser/gameController/Keys/VMGKey.java # racevisionGame/src/main/java/visualiser/model/ResizableRaceCanvas.java
This commit is contained in:
@@ -46,11 +46,11 @@ public class ControllerClient {
|
||||
* @throws IOException if socket write fails
|
||||
*/
|
||||
public void sendKey(ControlKey key) throws IOException {
|
||||
int protocolCode = key.getProtocolCode();
|
||||
if(protocolCode > -1) {
|
||||
BoatActionEnum protocolCode = key.getProtocolCode();
|
||||
if(protocolCode != BoatActionEnum.NOT_A_STATUS) {
|
||||
|
||||
byte[] bytes = new byte[4];
|
||||
ByteBuffer.wrap(bytes).putInt(key.getProtocolCode());
|
||||
ByteBuffer.wrap(bytes).putInt(protocolCode.getValue());
|
||||
BoatActionEnum boatActionEnum = BoatActionEnum.fromByte(bytes[3]);
|
||||
|
||||
BoatAction boatAction = new BoatAction(boatActionEnum);
|
||||
|
||||
@@ -1,19 +1,22 @@
|
||||
package visualiser.gameController.Keys;
|
||||
|
||||
import javafx.scene.input.KeyCode;
|
||||
import network.Messages.Enums.BoatActionEnum;
|
||||
|
||||
/**
|
||||
* Key for the controller, part of the abstract factory KeyFactory
|
||||
*/
|
||||
public abstract class ControlKey {
|
||||
|
||||
private String name;
|
||||
protected int protocolCode;
|
||||
protected BoatActionEnum protocolCode;
|
||||
|
||||
/**
|
||||
* Constructor for key state with specified protocol code
|
||||
* @param name of action
|
||||
* @param protocolCode -1 if not sent
|
||||
* @param protocolCode NOT_A_STATUS if not sent
|
||||
*/
|
||||
public ControlKey(String name, int protocolCode) {
|
||||
public ControlKey(String name, BoatActionEnum protocolCode) {
|
||||
this.name = name;
|
||||
this.protocolCode = protocolCode;
|
||||
}
|
||||
@@ -24,10 +27,10 @@ public abstract class ControlKey {
|
||||
*/
|
||||
public ControlKey(String name){
|
||||
this.name = name;
|
||||
this.protocolCode = -1;
|
||||
this.protocolCode = BoatActionEnum.NOT_A_STATUS;
|
||||
}
|
||||
|
||||
public int getProtocolCode() {
|
||||
public BoatActionEnum getProtocolCode() {
|
||||
return protocolCode;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package visualiser.gameController.Keys;
|
||||
|
||||
import network.Messages.Enums.BoatActionEnum;
|
||||
|
||||
/**
|
||||
* Key to send downwind packet to server
|
||||
*/
|
||||
@@ -11,7 +13,7 @@ public class DownWindKey extends ControlKey {
|
||||
*
|
||||
*/
|
||||
public DownWindKey(String name) {
|
||||
super(name, 6);
|
||||
super(name, BoatActionEnum.DOWNWIND);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package visualiser.gameController.Keys;
|
||||
|
||||
import network.Messages.Enums.BoatActionEnum;
|
||||
import visualiser.model.ThisBoat;
|
||||
|
||||
/**
|
||||
@@ -13,7 +14,7 @@ public class SailsToggleKey extends ControlKey {
|
||||
*
|
||||
*/
|
||||
public SailsToggleKey(String name) {
|
||||
super(name, 2);
|
||||
super(name, BoatActionEnum.SAILS_IN);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -21,16 +22,13 @@ public class SailsToggleKey extends ControlKey {
|
||||
*/
|
||||
@Override
|
||||
public void onAction() {
|
||||
// 2 = Sails in
|
||||
// 3 = Sails out
|
||||
if (ThisBoat.getInstance().isSailsOut()) {
|
||||
protocolCode = 3;
|
||||
if(ThisBoat.getInstance().isSailsOut()) {
|
||||
protocolCode = BoatActionEnum.SAILS_IN;
|
||||
ThisBoat.getInstance().setSailsOut(false);
|
||||
} else {
|
||||
protocolCode = 2;
|
||||
protocolCode = BoatActionEnum.SAILS_OUT;
|
||||
ThisBoat.getInstance().setSailsOut(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package visualiser.gameController.Keys;
|
||||
|
||||
import network.Messages.Enums.BoatActionEnum;
|
||||
|
||||
/**
|
||||
* key to toggle between tacking and gybing
|
||||
*/
|
||||
@@ -11,7 +13,7 @@ public class TackGybeKey extends ControlKey {
|
||||
*
|
||||
*/
|
||||
public TackGybeKey(String name) {
|
||||
super(name, 4);
|
||||
super(name, BoatActionEnum.TACK_GYBE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package visualiser.gameController.Keys;
|
||||
|
||||
import network.Messages.Enums.BoatActionEnum;
|
||||
|
||||
/**
|
||||
* Key to go upwind
|
||||
*/
|
||||
@@ -11,7 +13,7 @@ public class UpWindKey extends ControlKey {
|
||||
*
|
||||
*/
|
||||
public UpWindKey(String name) {
|
||||
super(name, 5);
|
||||
super(name, BoatActionEnum.UPWIND);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package visualiser.gameController.Keys;
|
||||
|
||||
import javafx.scene.input.KeyCode;
|
||||
import network.Messages.Enums.BoatActionEnum;
|
||||
|
||||
/**
|
||||
* Key to trigger auto VMG
|
||||
*/
|
||||
@@ -11,7 +14,7 @@ public class VMGKey extends ControlKey{
|
||||
* @param name name of the key
|
||||
*/
|
||||
public VMGKey(String name) {
|
||||
super(name, 1);
|
||||
super(name, BoatActionEnum.AUTO_PILOT);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -416,8 +416,9 @@ public class ResizableRaceCanvas extends ResizableCanvas {
|
||||
this.map.setWidth((int) getWidth());
|
||||
this.map.setHeight((int) getHeight());
|
||||
|
||||
redrawBoundaryImage();
|
||||
//Draw the race.
|
||||
drawRace();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -428,14 +429,14 @@ public class ResizableRaceCanvas extends ResizableCanvas {
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the race boundary, and saves the image to {@link #background}.
|
||||
* You should call {@link #clear()} before calling this.
|
||||
* Draws the race boundary.
|
||||
*/
|
||||
private void redrawBoundaryImage() {
|
||||
private void drawBoundary() {
|
||||
|
||||
//Prepare to draw.
|
||||
gc.setLineWidth(1);
|
||||
gc.setFill(Color.AQUA);
|
||||
gc.drawImage(new Image(getClass().getClassLoader().getResourceAsStream("images/WaterBackground.png")), 0, 0);
|
||||
|
||||
|
||||
//Calculate the screen coordinates of the boundary.
|
||||
List<GPSCoordinate> boundary = this.visualiserRace.getBoundary();
|
||||
@@ -454,8 +455,6 @@ public class ResizableRaceCanvas extends ResizableCanvas {
|
||||
//Draw the boundary.
|
||||
gc.fillPolygon(xpoints, ypoints, xpoints.length);
|
||||
|
||||
//Render boundary to image.
|
||||
this.background = snapshot(null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -471,13 +470,8 @@ public class ResizableRaceCanvas extends ResizableCanvas {
|
||||
drawMarks();
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the race boundary image onto the canvas.
|
||||
* See {@link #background}.
|
||||
*/
|
||||
private void drawBoundary() {
|
||||
gc.drawImage(this.background, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Draws all track points for a given boat. Colour is set by boat, opacity
|
||||
|
||||
@@ -26,7 +26,7 @@ import java.util.Map;
|
||||
* Has a course, boats, boundaries, etc...
|
||||
* Observes LatestMessages and updates its state based on new messages.
|
||||
*/
|
||||
public class VisualiserRace extends Race {
|
||||
public class VisualiserRace extends Race implements Runnable {
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user