Merging main features into story 6. App now sends and receives key strokes. #story[1007, 1089]
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package visualiser.gameController;
|
||||
|
||||
import network.BinaryMessageEncoder;
|
||||
import network.MessageEncoders.RaceVisionByteEncoder;
|
||||
import network.Messages.BoatAction;
|
||||
import network.Messages.Enums.BoatActionEnum;
|
||||
import network.Messages.Enums.MessageType;
|
||||
import visualiser.gameController.Keys.ControlKey;
|
||||
|
||||
@@ -46,12 +49,18 @@ public class ControllerClient {
|
||||
public void sendKey(ControlKey key) throws IOException {
|
||||
int protocolCode = key.getProtocolCode();
|
||||
if(protocolCode > -1) {
|
||||
ByteBuffer buffer = ByteBuffer.allocate(4);
|
||||
buffer.putInt(protocolCode);
|
||||
byte[] message = new byte[]{buffer.get(3)};
|
||||
BinaryMessageEncoder binaryMessage = new BinaryMessageEncoder(MessageType.BOATACTION, message);
|
||||
//outputStream.write(binaryMessage.getFullMessage());
|
||||
System.out.println("Binary message constructed");
|
||||
|
||||
byte[] bytes = new byte[4];
|
||||
ByteBuffer.wrap(bytes).putInt(key.getProtocolCode());
|
||||
|
||||
BoatAction boatAction = new BoatAction(BoatActionEnum.fromByte(bytes[3]));
|
||||
|
||||
byte[] encodedBoatAction = RaceVisionByteEncoder.boatActionMessage(boatAction);
|
||||
|
||||
BinaryMessageEncoder binaryMessage = new BinaryMessageEncoder(MessageType.BOATACTION, System.currentTimeMillis(), 0,
|
||||
(short) encodedBoatAction.length, encodedBoatAction);
|
||||
|
||||
outputStream.write(binaryMessage.getFullMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package visualiser.gameController;
|
||||
|
||||
import network.BinaryMessageDecoder;
|
||||
import network.MessageDecoders.BoatActionDecoder;
|
||||
import network.Messages.Enums.BoatActionEnum;
|
||||
import visualiser.gameController.Keys.ControlKey;
|
||||
import visualiser.gameController.Keys.KeyFactory;
|
||||
|
||||
@@ -39,10 +42,15 @@ public class ControllerServer implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
while(true) {
|
||||
byte[] key = new byte[16];
|
||||
byte[] message = new byte[20];
|
||||
try {
|
||||
inputStream.read(key);
|
||||
// TODO - handle messages received
|
||||
if (inputStream.available() > 0) {
|
||||
inputStream.read(message);
|
||||
BinaryMessageDecoder encodedMessage = new BinaryMessageDecoder(message);
|
||||
BoatActionDecoder boatActionDecoder = new BoatActionDecoder(encodedMessage.getMessageBody());
|
||||
BoatActionEnum decodedMessage = boatActionDecoder.getBoatAction();
|
||||
int key = decodedMessage.getValue();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user