Merge branch 'Development' into story_64_sails

# Conflicts:
#	racevisionGame/src/main/java/mock/model/commandFactory/CommandFactory.java
#	racevisionGame/src/main/java/visualiser/model/ResizableRaceCanvas.java
#	racevisionGame/src/test/java/mock/model/MockBoatTest.java
This commit is contained in:
Joseph Gardner
2017-08-10 11:56:09 +12:00
24 changed files with 1593 additions and 44 deletions
@@ -1,5 +1,8 @@
package visualiser.gameController;
import mock.model.RaceLogic;
import mock.model.commandFactory.Command;
import mock.model.commandFactory.CommandFactory;
import network.BinaryMessageDecoder;
import network.MessageDecoders.BoatActionDecoder;
import network.Messages.Enums.BoatActionEnum;
@@ -7,11 +10,12 @@ import network.Messages.Enums.BoatActionEnum;
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
*/
@@ -20,13 +24,23 @@ public class ControllerServer implements Runnable {
* Wrapper for input from client
*/
private DataInputStream inputStream;
/**
* Last received boat action
*/
private BoatActionEnum action;
/**
*
*/
private RaceLogic rc;
/**
* Initialise server-side controller with live client socket
* @param socket to client
*/
public ControllerServer(Socket socket) {
public ControllerServer(Socket socket, RaceLogic rc) {
this.socket = socket;
this.rc = rc;
this.addObserver(rc);
try {
this.inputStream = new DataInputStream(this.socket.getInputStream());
} catch (IOException e) {
@@ -34,6 +48,10 @@ public class ControllerServer implements Runnable {
}
}
public BoatActionEnum getAction() {
return action;
}
/**
* Wait for controller key input from client and loop.
*/
@@ -46,8 +64,11 @@ 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();
// Notify observers of most recent action
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"));
}
/**