Added WindCommand and multiple command execution to RaceLogic

- Dispatch commands with CompositeCommand
- Single WindCommand handles upwind and downwind logic
- Changed key bindings as Mac lacks PgUp PgDn
- ControllerServer is observable, RaceLogic updates CompositeCommand as observer
This commit is contained in:
Connor Taylor-Brown
2017-08-04 23:08:07 +12:00
parent 851bbb4fde
commit 554f8a2a0f
7 changed files with 127 additions and 8 deletions
@@ -1,5 +1,7 @@
package visualiser.gameController;
import mock.model.commandFactory.Command;
import mock.model.commandFactory.CommandFactory;
import network.BinaryMessageDecoder;
import network.MessageDecoders.BoatActionDecoder;
import network.Messages.Enums.BoatActionEnum;
@@ -9,11 +11,12 @@ import visualiser.gameController.Keys.KeyFactory;
import java.io.DataInputStream;
import java.io.IOException;
import java.net.Socket;
import java.util.Observable;
/**
* Service for dispatching key press data to race from client
*/
public class ControllerServer implements Runnable {
public class ControllerServer extends Observable implements Runnable {
/**
* Socket to client
*/
@@ -22,6 +25,10 @@ public class ControllerServer implements Runnable {
* Wrapper for input from client
*/
private DataInputStream inputStream;
/**
* Last received boat action
*/
private BoatActionEnum action;
/**
* Initialise server-side controller with live client socket
@@ -36,6 +43,10 @@ public class ControllerServer implements Runnable {
}
}
public BoatActionEnum getAction() {
return action;
}
/**
* Wait for controller key input from client and loop.
*/
@@ -48,8 +59,10 @@ public class ControllerServer implements Runnable {
inputStream.read(message);
BinaryMessageDecoder encodedMessage = new BinaryMessageDecoder(message);
BoatActionDecoder boatActionDecoder = new BoatActionDecoder(encodedMessage.getMessageBody());
BoatActionEnum decodedMessage = boatActionDecoder.getBoatAction();
System.out.println("Received key: " + decodedMessage);
action = boatActionDecoder.getBoatAction();
this.notifyObservers();
this.setChanged();
}
} catch (IOException e) {
e.printStackTrace();
@@ -27,8 +27,8 @@ public class KeyFactory {
keyState.put("SPACE", new VMGKey("VMG"));
keyState.put("SHIFT", new SailsToggleKey("Toggle Sails"));
keyState.put("ENTER", new TackGybeKey("Tack/Gybe"));
keyState.put("PAGE_UP", new UpWindKey("Upwind"));
keyState.put("PAGE_DOWN", new DownWindKey("Downwind"));
keyState.put("UP", new UpWindKey("Upwind"));
keyState.put("DOWN", new DownWindKey("Downwind"));
}
/**