Merge remote-tracking branch 'origin/Development' into Development

main
hba56 8 years ago
commit 74f04a13f8

@ -1,23 +1,24 @@
package mock.model.commandFactory; 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. * Wraps multiple commands into a composite to execute queued commands during a frame.
*/ */
public class CompositeCommand implements Command { public class CompositeCommand implements Command {
private Stack<Command> commands; private Queue<Command> commands;
public CompositeCommand() { public CompositeCommand() {
this.commands = new Stack<>(); this.commands = new ArrayDeque<>();
} }
public void addCommand(Command command) { public void addCommand(Command command) {
commands.push(command); commands.add(command);
} }
@Override @Override
public void execute() { 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 * @throws IOException if socket write fails
*/ */
public void sendKey(ControlKey key) throws IOException { public void sendKey(ControlKey key) throws IOException {
int protocolCode = key.getProtocolCode(); BoatActionEnum protocolCode = key.getProtocolCode();
if(protocolCode > -1) { if(protocolCode != BoatActionEnum.NOT_A_STATUS) {
byte[] bytes = new byte[4]; byte[] bytes = new byte[4];
ByteBuffer.wrap(bytes).putInt(key.getProtocolCode()); ByteBuffer.wrap(bytes).putInt(protocolCode.getValue());
BoatActionEnum boatActionEnum = BoatActionEnum.fromByte(bytes[3]); BoatActionEnum boatActionEnum = BoatActionEnum.fromByte(bytes[3]);
BoatAction boatAction = new BoatAction(boatActionEnum); BoatAction boatAction = new BoatAction(boatActionEnum);

@ -66,6 +66,7 @@ public class ControllerServer extends Observable implements Runnable {
BoatActionDecoder boatActionDecoder = new BoatActionDecoder(encodedMessage.getMessageBody()); BoatActionDecoder boatActionDecoder = new BoatActionDecoder(encodedMessage.getMessageBody());
action = boatActionDecoder.getBoatAction(); action = boatActionDecoder.getBoatAction();
// Notify observers of most recent action
this.notifyObservers(); this.notifyObservers();
this.setChanged(); this.setChanged();
} }

@ -1,6 +1,7 @@
package visualiser.gameController.Keys; package visualiser.gameController.Keys;
import javafx.scene.input.KeyCode; import javafx.scene.input.KeyCode;
import network.Messages.Enums.BoatActionEnum;
/** /**
* Key for the controller, part of the abstract factory KeyFactory * Key for the controller, part of the abstract factory KeyFactory
@ -8,14 +9,14 @@ import javafx.scene.input.KeyCode;
public abstract class ControlKey { public abstract class ControlKey {
private String name; private String name;
protected int protocolCode; protected BoatActionEnum protocolCode;
/** /**
* Constructor for key state with specified protocol code * Constructor for key state with specified protocol code
* @param name of action * @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.name = name;
this.protocolCode = protocolCode; this.protocolCode = protocolCode;
} }
@ -26,10 +27,10 @@ public abstract class ControlKey {
*/ */
public ControlKey(String name){ public ControlKey(String name){
this.name = name; this.name = name;
this.protocolCode = -1; this.protocolCode = BoatActionEnum.NOT_A_STATUS;
} }
public int getProtocolCode() { public BoatActionEnum getProtocolCode() {
return protocolCode; return protocolCode;
} }

@ -1,5 +1,7 @@
package visualiser.gameController.Keys; package visualiser.gameController.Keys;
import network.Messages.Enums.BoatActionEnum;
/** /**
* Key to send downwind packet to server * Key to send downwind packet to server
*/ */
@ -11,7 +13,7 @@ public class DownWindKey extends ControlKey {
* *
*/ */
public DownWindKey(String name) { public DownWindKey(String name) {
super(name, 6); super(name, BoatActionEnum.DOWNWIND);
} }
@Override @Override

@ -1,5 +1,7 @@
package visualiser.gameController.Keys; package visualiser.gameController.Keys;
import network.Messages.Enums.BoatActionEnum;
/** /**
* Key to toggle the sails * Key to toggle the sails
*/ */
@ -11,7 +13,7 @@ public class SailsToggleKey extends ControlKey {
* *
*/ */
public SailsToggleKey(String name) { public SailsToggleKey(String name) {
super(name, 2); super(name, BoatActionEnum.SAILS_IN);
} }
/** /**
@ -19,7 +21,11 @@ public class SailsToggleKey extends ControlKey {
*/ */
@Override @Override
public void onAction() { public void onAction() {
protocolCode = protocolCode == 2? 3 : 2; if(protocolCode == BoatActionEnum.SAILS_IN) {
protocolCode = BoatActionEnum.SAILS_OUT;
} else {
protocolCode = BoatActionEnum.SAILS_IN;
}
} }
@Override @Override

@ -1,5 +1,7 @@
package visualiser.gameController.Keys; package visualiser.gameController.Keys;
import network.Messages.Enums.BoatActionEnum;
/** /**
* key to toggle between tacking and gybing * key to toggle between tacking and gybing
*/ */
@ -11,7 +13,7 @@ public class TackGybeKey extends ControlKey {
* *
*/ */
public TackGybeKey(String name) { public TackGybeKey(String name) {
super(name, 4); super(name, BoatActionEnum.TACK_GYBE);
} }
@Override @Override

@ -1,5 +1,7 @@
package visualiser.gameController.Keys; package visualiser.gameController.Keys;
import network.Messages.Enums.BoatActionEnum;
/** /**
* Key to go upwind * Key to go upwind
*/ */
@ -11,7 +13,7 @@ public class UpWindKey extends ControlKey {
* *
*/ */
public UpWindKey(String name) { public UpWindKey(String name) {
super(name, 5); super(name, BoatActionEnum.UPWIND);
} }
@Override @Override

@ -1,6 +1,7 @@
package visualiser.gameController.Keys; package visualiser.gameController.Keys;
import javafx.scene.input.KeyCode; import javafx.scene.input.KeyCode;
import network.Messages.Enums.BoatActionEnum;
/** /**
* Key to trigger auto VMG * Key to trigger auto VMG
@ -13,7 +14,7 @@ public class VMGKey extends ControlKey{
* @param name name of the key * @param name name of the key
*/ */
public VMGKey(String name) { public VMGKey(String name) {
super(name, 1); super(name, BoatActionEnum.AUTO_PILOT);
} }
@Override @Override

Loading…
Cancel
Save