|
|
|
|
@ -1,10 +1,13 @@
|
|
|
|
|
package visualiser.gameController;
|
|
|
|
|
|
|
|
|
|
import network.BinaryMessageEncoder;
|
|
|
|
|
import network.Messages.Enums.MessageType;
|
|
|
|
|
import visualiser.gameController.Keys.ControlKey;
|
|
|
|
|
|
|
|
|
|
import java.io.DataOutputStream;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.net.Socket;
|
|
|
|
|
import java.net.SocketException;
|
|
|
|
|
import java.nio.ByteBuffer;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -27,6 +30,7 @@ public class ControllerClient {
|
|
|
|
|
*/
|
|
|
|
|
public ControllerClient(Socket socket) {
|
|
|
|
|
this.socket = socket;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
this.outputStream = new DataOutputStream(socket.getOutputStream());
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
@ -40,7 +44,14 @@ public class ControllerClient {
|
|
|
|
|
* @throws IOException if socket write fails
|
|
|
|
|
*/
|
|
|
|
|
public void sendKey(ControlKey key) throws IOException {
|
|
|
|
|
// TODO - get and send action number currently corresponding to key (context dependent)
|
|
|
|
|
System.out.println(key.toString() + ": " + key.getProtocolCode());
|
|
|
|
|
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");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|