Merge branch 'master' into story68
-updated port and starboard boat checks -added gps method to check if on correct side of a line -updated pos check method to make boats round marks with the new tech # Conflicts: # racevisionGame/src/main/java/mock/app/ConnectionAcceptor.java # racevisionGame/src/main/java/mock/app/Event.java # racevisionGame/src/main/java/mock/model/commandFactory/TackGybeCommand.java # racevisionGame/src/main/java/mock/model/commandFactory/VMGCommand.java
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package visualiser.gameController;
|
||||
|
||||
import network.BinaryMessageEncoder;
|
||||
import network.Exceptions.InvalidMessageException;
|
||||
import network.MessageEncoders.RaceVisionByteEncoder;
|
||||
import network.Messages.BoatAction;
|
||||
import network.Messages.Enums.BoatActionEnum;
|
||||
@@ -12,6 +13,8 @@ import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Basic service for sending key presses to game server
|
||||
@@ -50,19 +53,24 @@ public class ControllerClient {
|
||||
BoatActionEnum protocolCode = key.getProtocolCode();
|
||||
if(protocolCode != BoatActionEnum.NOT_A_STATUS) {
|
||||
|
||||
byte[] bytes = new byte[4];
|
||||
ByteBuffer.wrap(bytes).putInt(protocolCode.getValue());
|
||||
BoatActionEnum boatActionEnum = BoatActionEnum.fromByte(bytes[3]);
|
||||
BoatAction boatAction = new BoatAction(protocolCode);
|
||||
|
||||
BoatAction boatAction = new BoatAction(boatActionEnum);
|
||||
//Encode BoatAction.
|
||||
try {
|
||||
byte[] encodedBoatAction = RaceVisionByteEncoder.encode(boatAction);
|
||||
|
||||
byte[] encodedBoatAction = RaceVisionByteEncoder.boatActionMessage(boatAction);
|
||||
BinaryMessageEncoder binaryMessage = new BinaryMessageEncoder(MessageType.BOATACTION, System.currentTimeMillis(), 0,
|
||||
(short) encodedBoatAction.length, encodedBoatAction);
|
||||
|
||||
System.out.println("Sending out key: " + protocolCode);
|
||||
outputStream.write(binaryMessage.getFullMessage());
|
||||
|
||||
} catch (InvalidMessageException e) {
|
||||
Logger.getGlobal().log(Level.WARNING, "Could not encode BoatAction: " + boatAction, e);
|
||||
|
||||
}
|
||||
|
||||
BinaryMessageEncoder binaryMessage = new BinaryMessageEncoder(MessageType.BOATACTION, System.currentTimeMillis(), 0,
|
||||
(short) encodedBoatAction.length, encodedBoatAction);
|
||||
|
||||
System.out.println("Sending out key: " + boatActionEnum);
|
||||
outputStream.write(binaryMessage.getFullMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,13 +4,17 @@ import mock.model.RaceLogic;
|
||||
import mock.model.commandFactory.Command;
|
||||
import mock.model.commandFactory.CommandFactory;
|
||||
import network.BinaryMessageDecoder;
|
||||
import network.Exceptions.InvalidMessageException;
|
||||
import network.MessageDecoders.BoatActionDecoder;
|
||||
import network.Messages.BoatAction;
|
||||
import network.Messages.Enums.BoatActionEnum;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
import java.util.logging.Level;
|
||||
import java.util.Observable;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Service for dispatching key press data to race from client
|
||||
@@ -61,14 +65,26 @@ public class ControllerServer extends Observable implements Runnable {
|
||||
byte[] message = new byte[20];
|
||||
try {
|
||||
if (inputStream.available() > 0) {
|
||||
inputStream.read(message);
|
||||
BinaryMessageDecoder encodedMessage = new BinaryMessageDecoder(message);
|
||||
BoatActionDecoder boatActionDecoder = new BoatActionDecoder(encodedMessage.getMessageBody());
|
||||
action = boatActionDecoder.getBoatAction();
|
||||
|
||||
// Notify observers of most recent action
|
||||
this.notifyObservers();
|
||||
this.setChanged();
|
||||
inputStream.read(message);
|
||||
|
||||
BinaryMessageDecoder encodedMessage = new BinaryMessageDecoder(message);
|
||||
BoatActionDecoder boatActionDecoder = new BoatActionDecoder();
|
||||
|
||||
try {
|
||||
boatActionDecoder.decode(encodedMessage.getMessageBody());
|
||||
BoatAction boatAction = boatActionDecoder.getMessage();
|
||||
action = boatAction.getBoatAction();
|
||||
|
||||
// Notify observers of most recent action
|
||||
this.notifyObservers();
|
||||
this.setChanged();
|
||||
|
||||
} catch (InvalidMessageException e) {
|
||||
Logger.getGlobal().log(Level.WARNING, "Could not decode BoatAction message.", e);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
Reference in New Issue
Block a user