Merge remote-tracking branch 'origin/Development' into Development
This commit is contained in:
@@ -1,23 +1,24 @@
|
||||
package mock.model.commandFactory;
|
||||
|
||||
import java.util.Stack;
|
||||
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 Stack<Command> commands;
|
||||
private Queue<Command> commands;
|
||||
|
||||
public CompositeCommand() {
|
||||
this.commands = new Stack<>();
|
||||
this.commands = new ArrayDeque<>();
|
||||
}
|
||||
|
||||
public void addCommand(Command command) {
|
||||
commands.push(command);
|
||||
commands.add(command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
while(!commands.isEmpty()) commands.pop().execute();
|
||||
while(!commands.isEmpty()) commands.remove().execute();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,11 +47,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);
|
||||
|
||||
@@ -66,6 +66,7 @@ public class ControllerServer extends Observable implements Runnable {
|
||||
BoatActionDecoder boatActionDecoder = new BoatActionDecoder(encodedMessage.getMessageBody());
|
||||
action = boatActionDecoder.getBoatAction();
|
||||
|
||||
// Notify observers of most recent action
|
||||
this.notifyObservers();
|
||||
this.setChanged();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package visualiser.gameController.Keys;
|
||||
|
||||
import javafx.scene.input.KeyCode;
|
||||
import network.Messages.Enums.BoatActionEnum;
|
||||
|
||||
/**
|
||||
* Key for the controller, part of the abstract factory KeyFactory
|
||||
@@ -8,14 +9,14 @@ import javafx.scene.input.KeyCode;
|
||||
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;
|
||||
}
|
||||
@@ -26,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,7 @@
|
||||
package visualiser.gameController.Keys;
|
||||
|
||||
import network.Messages.Enums.BoatActionEnum;
|
||||
|
||||
/**
|
||||
* Key to toggle the sails
|
||||
*/
|
||||
@@ -11,7 +13,7 @@ public class SailsToggleKey extends ControlKey {
|
||||
*
|
||||
*/
|
||||
public SailsToggleKey(String name) {
|
||||
super(name, 2);
|
||||
super(name, BoatActionEnum.SAILS_IN);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -19,7 +21,11 @@ public class SailsToggleKey extends ControlKey {
|
||||
*/
|
||||
@Override
|
||||
public void onAction() {
|
||||
protocolCode = protocolCode == 2? 3 : 2;
|
||||
if(protocolCode == BoatActionEnum.SAILS_IN) {
|
||||
protocolCode = BoatActionEnum.SAILS_OUT;
|
||||
} else {
|
||||
protocolCode = BoatActionEnum.SAILS_IN;
|
||||
}
|
||||
}
|
||||
|
||||
@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,6 +1,7 @@
|
||||
package visualiser.gameController.Keys;
|
||||
|
||||
import javafx.scene.input.KeyCode;
|
||||
import network.Messages.Enums.BoatActionEnum;
|
||||
|
||||
/**
|
||||
* Key to trigger auto VMG
|
||||
@@ -13,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
|
||||
|
||||
Reference in New Issue
Block a user