mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Merge branch 'develop' into Story64_SailsAnimations
# Conflicts: # src/main/java/seng302/visualiser/GameClient.java
This commit is contained in:
@@ -69,8 +69,8 @@
|
|||||||
<artifactId>commons-cli</artifactId>
|
<artifactId>commons-cli</artifactId>
|
||||||
<version>1.4</version>
|
<version>1.4</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
|||||||
@@ -67,8 +67,6 @@ public class App extends Application {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage primaryStage) throws Exception {
|
public void start(Stage primaryStage) throws Exception {
|
||||||
PolarTable.parsePolarFile(getClass().getResourceAsStream("/config/acc_polars.csv"));
|
|
||||||
|
|
||||||
Parent root = FXMLLoader.load(getClass().getResource("/views/StartScreenView.fxml"));
|
Parent root = FXMLLoader.load(getClass().getResource("/views/StartScreenView.fxml"));
|
||||||
primaryStage.setTitle("RaceVision");
|
primaryStage.setTitle("RaceVision");
|
||||||
Scene scene = new Scene(root, 1530, 960);
|
Scene scene = new Scene(root, 1530, 960);
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import seng302.gameServer.server.messages.BoatAction;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import seng302.gameServer.server.messages.BoatActionType;
|
|
||||||
import seng302.model.Player;
|
import seng302.model.Player;
|
||||||
import seng302.model.Yacht;
|
import seng302.model.Yacht;
|
||||||
import seng302.model.mark.MarkOrder;
|
import seng302.model.mark.MarkOrder;
|
||||||
@@ -56,7 +56,6 @@ public class GameState implements Runnable {
|
|||||||
players = new ArrayList<>();
|
players = new ArrayList<>();
|
||||||
currentStage = GameStages.LOBBYING;
|
currentStage = GameStages.LOBBYING;
|
||||||
isRaceStarted = false;
|
isRaceStarted = false;
|
||||||
yachts = new HashMap<>();
|
|
||||||
//set this when game stage changes to prerace
|
//set this when game stage changes to prerace
|
||||||
previousUpdateTime = System.currentTimeMillis();
|
previousUpdateTime = System.currentTimeMillis();
|
||||||
yachts = new HashMap<>();
|
yachts = new HashMap<>();
|
||||||
@@ -75,7 +74,8 @@ public class GameState implements Runnable {
|
|||||||
|
|
||||||
public static void addPlayer(Player player) {
|
public static void addPlayer(Player player) {
|
||||||
players.add(player);
|
players.add(player);
|
||||||
String playerText = player.getYacht().getSourceId() + " " + player.getYacht().getBoatName() + " " + player.getYacht().getCountry();
|
String playerText = player.getYacht().getSourceId() + " " + player.getYacht().getBoatName()
|
||||||
|
+ " " + player.getYacht().getCountry();
|
||||||
playerStringMap.put(player, playerText);
|
playerStringMap.put(player, playerText);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,7 +132,7 @@ public class GameState implements Runnable {
|
|||||||
return yachts;
|
return yachts;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void updateBoat(Integer sourceId, BoatActionType actionType) {
|
public static void updateBoat(Integer sourceId, BoatAction actionType) {
|
||||||
Yacht playerYacht = yachts.get(sourceId);
|
Yacht playerYacht = yachts.get(sourceId);
|
||||||
// System.out.println("-----------------------");
|
// System.out.println("-----------------------");
|
||||||
switch (actionType) {
|
switch (actionType) {
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ public class HeartbeatThread extends Thread{
|
|||||||
*/
|
*/
|
||||||
private void sendHeartbeatToAllPlayers(){
|
private void sendHeartbeatToAllPlayers(){
|
||||||
Message heartbeat = new Heartbeat(seqNum);
|
Message heartbeat = new Heartbeat(seqNum);
|
||||||
|
|
||||||
for (Player player : GameState.getPlayers()){
|
for (Player player : GameState.getPlayers()){
|
||||||
if (!player.getSocket().isConnected()) {
|
if (!player.getSocket().isConnected()) {
|
||||||
playerLostConnection(player);
|
playerLostConnection(player);
|
||||||
@@ -54,7 +53,6 @@ public class HeartbeatThread extends Thread{
|
|||||||
playerLostConnection(player);
|
playerLostConnection(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateDelegate();
|
updateDelegate();
|
||||||
seqNum++;
|
seqNum++;
|
||||||
}
|
}
|
||||||
@@ -71,7 +69,6 @@ public class HeartbeatThread extends Thread{
|
|||||||
|
|
||||||
public void run(){
|
public void run(){
|
||||||
Timer t = new Timer();
|
Timer t = new Timer();
|
||||||
|
|
||||||
t.schedule(new TimerTask() {
|
t.schedule(new TimerTask() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import java.util.Observable;
|
|||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
import seng302.model.Player;
|
import seng302.model.Player;
|
||||||
|
import seng302.model.PolarTable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class describing the overall server, which creates and collects server threads for each client
|
* A class describing the overall server, which creates and collects server threads for each client
|
||||||
@@ -32,7 +33,7 @@ public class MainServerThread extends Observable implements Runnable, ClientConn
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
serverLog("IO error in server thread handler upon trying to make new server socket", 0);
|
serverLog("IO error in server thread handler upon trying to make new server socket", 0);
|
||||||
}
|
}
|
||||||
|
PolarTable.parsePolarFile(getClass().getResourceAsStream("/config/acc_polars.csv"));
|
||||||
terminated = false;
|
terminated = false;
|
||||||
thread = new Thread(this);
|
thread = new Thread(this);
|
||||||
thread.start();
|
thread.start();
|
||||||
@@ -44,6 +45,7 @@ public class MainServerThread extends Observable implements Runnable, ClientConn
|
|||||||
HeartbeatThread heartbeatThread;
|
HeartbeatThread heartbeatThread;
|
||||||
|
|
||||||
serverListenThread = new ServerListenThread(serverSocket, this);
|
serverListenThread = new ServerListenThread(serverSocket, this);
|
||||||
|
|
||||||
heartbeatThread = new HeartbeatThread(this);
|
heartbeatThread = new HeartbeatThread(this);
|
||||||
|
|
||||||
heartbeatThread.start();
|
heartbeatThread.start();
|
||||||
@@ -102,9 +104,11 @@ public class MainServerThread extends Observable implements Runnable, ClientConn
|
|||||||
public void clientConnected(ServerToClientThread serverToClientThread) {
|
public void clientConnected(ServerToClientThread serverToClientThread) {
|
||||||
serverLog("Player Connected From " + serverToClientThread.getThread().getName(), 0);
|
serverLog("Player Connected From " + serverToClientThread.getThread().getName(), 0);
|
||||||
serverToClientThreads.add(serverToClientThread);
|
serverToClientThreads.add(serverToClientThread);
|
||||||
this.addObserver(serverToClientThread);
|
serverToClientThread.addConnectionListener(() -> {
|
||||||
setChanged();
|
for (ServerToClientThread thread : serverToClientThreads) {
|
||||||
notifyObservers();
|
thread.sendSetupMessages();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -121,11 +125,15 @@ public class MainServerThread extends Observable implements Runnable, ClientConn
|
|||||||
serverLog("Player " + player.getYacht().getSourceId() + "'s socket disconnected", 0);
|
serverLog("Player " + player.getYacht().getSourceId() + "'s socket disconnected", 0);
|
||||||
GameState.removeYacht(player.getYacht().getSourceId());
|
GameState.removeYacht(player.getYacht().getSourceId());
|
||||||
GameState.removePlayer(player);
|
GameState.removePlayer(player);
|
||||||
|
ServerToClientThread closedConnection = null;
|
||||||
for (ServerToClientThread serverToClientThread : serverToClientThreads) {
|
for (ServerToClientThread serverToClientThread : serverToClientThreads) {
|
||||||
if (serverToClientThread.getSocket() == player.getSocket()) {
|
if (serverToClientThread.getSocket() == player.getSocket()) {
|
||||||
this.deleteObserver(serverToClientThread);
|
closedConnection = serverToClientThread;
|
||||||
|
} else {
|
||||||
|
serverToClientThread.sendSetupMessages();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
serverToClientThreads.remove(closedConnection);
|
||||||
setChanged();
|
setChanged();
|
||||||
notifyObservers();
|
notifyObservers();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,16 +5,16 @@ import java.util.Arrays;
|
|||||||
import seng302.gameServer.server.messages.ClientType;
|
import seng302.gameServer.server.messages.ClientType;
|
||||||
import seng302.gameServer.server.messages.Message;
|
import seng302.gameServer.server.messages.Message;
|
||||||
import seng302.model.stream.packets.StreamPacket;
|
import seng302.model.stream.packets.StreamPacket;
|
||||||
import seng302.gameServer.server.messages.BoatActionType;
|
import seng302.gameServer.server.messages.BoatAction;
|
||||||
|
|
||||||
|
|
||||||
public class ServerPacketParser {
|
public class ServerPacketParser {
|
||||||
|
|
||||||
public static BoatActionType extractBoatAction(StreamPacket packet) {
|
public static BoatAction extractBoatAction(StreamPacket packet) {
|
||||||
byte[] payload = packet.getPayload();
|
byte[] payload = packet.getPayload();
|
||||||
int messageVersionNo = payload[0];
|
int messageVersionNo = payload[0];
|
||||||
long actionTypeValue = Message.bytesToLong(Arrays.copyOfRange(payload, 0, 1));
|
long actionTypeValue = Message.bytesToLong(Arrays.copyOfRange(payload, 0, 1));
|
||||||
return BoatActionType.getType((int) actionTypeValue);
|
return BoatAction.getType((int) actionTypeValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ClientType extractClientType(StreamPacket packet){
|
public static ClientType extractClientType(StreamPacket packet){
|
||||||
|
|||||||
@@ -1,7 +1,34 @@
|
|||||||
package seng302.gameServer;
|
package seng302.gameServer;
|
||||||
|
|
||||||
|
|
||||||
import seng302.gameServer.server.messages.*;
|
import java.io.BufferedReader;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.net.Socket;
|
||||||
|
import java.net.SocketException;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.zip.CRC32;
|
||||||
|
import java.util.zip.Checksum;
|
||||||
|
import seng302.gameServer.server.messages.BoatAction;
|
||||||
|
import seng302.gameServer.server.messages.BoatLocationMessage;
|
||||||
|
import seng302.gameServer.server.messages.BoatStatus;
|
||||||
|
import seng302.gameServer.server.messages.BoatSubMessage;
|
||||||
|
import seng302.gameServer.server.messages.ClientType;
|
||||||
|
import seng302.gameServer.server.messages.Message;
|
||||||
|
import seng302.gameServer.server.messages.RaceStatus;
|
||||||
|
import seng302.gameServer.server.messages.RaceStatusMessage;
|
||||||
|
import seng302.gameServer.server.messages.RaceType;
|
||||||
|
import seng302.gameServer.server.messages.RegistrationResponseMessage;
|
||||||
|
import seng302.gameServer.server.messages.RegistrationResponseStatus;
|
||||||
|
import seng302.gameServer.server.messages.XMLMessage;
|
||||||
|
import seng302.gameServer.server.messages.XMLMessageSubType;
|
||||||
import seng302.model.Player;
|
import seng302.model.Player;
|
||||||
import seng302.model.Yacht;
|
import seng302.model.Yacht;
|
||||||
import seng302.model.stream.packets.PacketType;
|
import seng302.model.stream.packets.PacketType;
|
||||||
@@ -10,25 +37,20 @@ import seng302.model.stream.xml.generator.Race;
|
|||||||
import seng302.model.stream.xml.generator.Regatta;
|
import seng302.model.stream.xml.generator.Regatta;
|
||||||
import seng302.utilities.XMLGenerator;
|
import seng302.utilities.XMLGenerator;
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.net.Socket;
|
|
||||||
import java.net.SocketException;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Observable;
|
|
||||||
import java.util.Observer;
|
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.zip.CRC32;
|
|
||||||
import java.util.zip.Checksum;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class describing a single connection to a Client for the purposes of sending and receiving on
|
* A class describing a single connection to a Client for the purposes of sending and receiving on
|
||||||
* its own thread. All server threads created and owned by the server thread handler which can
|
* its own thread. All server threads created and owned by the server thread handler which can
|
||||||
* trigger client updates on its threads Created by wmu16 on 13/07/17.
|
* trigger client updates on its threads Created by wmu16 on 13/07/17.
|
||||||
*/
|
*/
|
||||||
public class ServerToClientThread implements Runnable, Observer {
|
public class ServerToClientThread implements Runnable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called to notify listeners when this thread receives a connection correctly.
|
||||||
|
*/
|
||||||
|
@FunctionalInterface
|
||||||
|
interface ConnectionListener {
|
||||||
|
void notifyConnection ();
|
||||||
|
}
|
||||||
|
|
||||||
private static final Integer LOG_LEVEL = 1;
|
private static final Integer LOG_LEVEL = 1;
|
||||||
private static final Integer MAX_ID_ATTEMPTS = 10;
|
private static final Integer MAX_ID_ATTEMPTS = 10;
|
||||||
@@ -41,9 +63,6 @@ public class ServerToClientThread implements Runnable, Observer {
|
|||||||
|
|
||||||
private ByteArrayOutputStream crcBuffer;
|
private ByteArrayOutputStream crcBuffer;
|
||||||
|
|
||||||
private Boolean userIdentified = false;
|
|
||||||
private Boolean connected = true;
|
|
||||||
private Boolean updateClient = true;
|
|
||||||
// private Boolean initialisedRace = true;
|
// private Boolean initialisedRace = true;
|
||||||
|
|
||||||
private Integer seqNo;
|
private Integer seqNo;
|
||||||
@@ -54,6 +73,8 @@ public class ServerToClientThread implements Runnable, Observer {
|
|||||||
|
|
||||||
private XMLGenerator xml;
|
private XMLGenerator xml;
|
||||||
|
|
||||||
|
private List<ConnectionListener> connectionListeners = new ArrayList<>();
|
||||||
|
|
||||||
public ServerToClientThread(Socket socket) {
|
public ServerToClientThread(Socket socket) {
|
||||||
this.socket = socket;
|
this.socket = socket;
|
||||||
seqNo = 0;
|
seqNo = 0;
|
||||||
@@ -69,7 +90,7 @@ public class ServerToClientThread implements Runnable, Observer {
|
|||||||
thread.start();
|
thread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setUpYacht(){
|
private void setUpPlayer(){
|
||||||
BufferedReader fn;
|
BufferedReader fn;
|
||||||
String fName = "";
|
String fName = "";
|
||||||
BufferedReader ln;
|
BufferedReader ln;
|
||||||
@@ -98,7 +119,6 @@ public class ServerToClientThread implements Runnable, Observer {
|
|||||||
Yacht yacht = new Yacht(
|
Yacht yacht = new Yacht(
|
||||||
"Yacht", sourceId, sourceId.toString(), fName, fName + " " + lName, "NZ"
|
"Yacht", sourceId, sourceId.toString(), fName, fName + " " + lName, "NZ"
|
||||||
);
|
);
|
||||||
|
|
||||||
GameState.addYacht(sourceId, yacht);
|
GameState.addYacht(sourceId, yacht);
|
||||||
GameState.addPlayer(new Player(socket, yacht));
|
GameState.addPlayer(new Player(socket, yacht));
|
||||||
}
|
}
|
||||||
@@ -110,11 +130,6 @@ public class ServerToClientThread implements Runnable, Observer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void update(Observable o, Object arg) {
|
|
||||||
sendSetupMessages();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void completeRegistration(ClientType clientType) throws IOException {
|
private void completeRegistration(ClientType clientType) throws IOException {
|
||||||
// Fail if not a player
|
// Fail if not a player
|
||||||
if (!clientType.equals(ClientType.PLAYER)){
|
if (!clientType.equals(ClientType.PLAYER)){
|
||||||
@@ -134,12 +149,14 @@ public class ServerToClientThread implements Runnable, Observer {
|
|||||||
|
|
||||||
this.clientType = clientType;
|
this.clientType = clientType;
|
||||||
this.sourceId = sourceId;
|
this.sourceId = sourceId;
|
||||||
setUpYacht();
|
|
||||||
|
|
||||||
isRegistered = true;
|
isRegistered = true;
|
||||||
os.write(responseMessage.getBuffer());
|
os.write(responseMessage.getBuffer());
|
||||||
sendSetupMessages();
|
|
||||||
|
|
||||||
|
setUpPlayer();
|
||||||
|
|
||||||
|
for (ConnectionListener listener : connectionListeners) {
|
||||||
|
listener.notifyConnection();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
@@ -151,20 +168,6 @@ public class ServerToClientThread implements Runnable, Observer {
|
|||||||
while (socket.isConnected()) {
|
while (socket.isConnected()) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
//Perform a write if it is time to as delegated by the MainServerThread
|
|
||||||
if (updateClient) {
|
|
||||||
// TODO: 13/07/17 wmu16 - Write out game state - some function that would write all appropriate messages to this output stream
|
|
||||||
// ChatterMessage chatterMessage = new ChatterMessage(4, 14, "Hello, it's me");
|
|
||||||
// sendMessage(chatterMessage);
|
|
||||||
// try {
|
|
||||||
// GameState.outputState(os);
|
|
||||||
// } catch (IOException e) {
|
|
||||||
// System.out.println("IO error in server thread upon writing to output stream");
|
|
||||||
// }
|
|
||||||
// sendBoatLocationPackets();
|
|
||||||
updateClient = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
crcBuffer = new ByteArrayOutputStream();
|
crcBuffer = new ByteArrayOutputStream();
|
||||||
sync1 = readByte();
|
sync1 = readByte();
|
||||||
sync2 = readByte();
|
sync2 = readByte();
|
||||||
@@ -184,7 +187,7 @@ public class ServerToClientThread implements Runnable, Observer {
|
|||||||
//System.out.println("RECEIVED A PACKET");
|
//System.out.println("RECEIVED A PACKET");
|
||||||
switch (PacketType.assignPacketType(type, payload)) {
|
switch (PacketType.assignPacketType(type, payload)) {
|
||||||
case BOAT_ACTION:
|
case BOAT_ACTION:
|
||||||
BoatActionType actionType = ServerPacketParser
|
BoatAction actionType = ServerPacketParser
|
||||||
.extractBoatAction(
|
.extractBoatAction(
|
||||||
new StreamPacket(type, payloadLength, timeStamp, payload));
|
new StreamPacket(type, payloadLength, timeStamp, payload));
|
||||||
GameState.updateBoat(sourceId, actionType);
|
GameState.updateBoat(sourceId, actionType);
|
||||||
@@ -210,7 +213,7 @@ public class ServerToClientThread implements Runnable, Observer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendSetupMessages() {
|
public void sendSetupMessages() {
|
||||||
xml = new XMLGenerator();
|
xml = new XMLGenerator();
|
||||||
Race race = new Race();
|
Race race = new Race();
|
||||||
|
|
||||||
@@ -238,23 +241,6 @@ public class ServerToClientThread implements Runnable, Observer {
|
|||||||
|
|
||||||
public void updateClient() {
|
public void updateClient() {
|
||||||
sendBoatLocationPackets();
|
sendBoatLocationPackets();
|
||||||
updateClient = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tries to confirm the connection just accepted.
|
|
||||||
* Sends ID, expects that ID echoed for confirmation,
|
|
||||||
* if so, sends a confirmation packet back to that connection
|
|
||||||
* Creates a player instance with that ID and this thread and adds it to the GameState
|
|
||||||
* If not, close the socket and end the threads execution
|
|
||||||
*
|
|
||||||
* @param id the id to try and assign to the connection
|
|
||||||
* @return A boolean indicating if it was a successful handshake
|
|
||||||
*/
|
|
||||||
private Boolean threeWayHandshake(Integer id) {
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void closeSocket() {
|
private void closeSocket() {
|
||||||
@@ -265,7 +251,6 @@ public class ServerToClientThread implements Runnable, Observer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private int readByte() throws Exception {
|
private int readByte() throws Exception {
|
||||||
int currentByte = -1;
|
int currentByte = -1;
|
||||||
try {
|
try {
|
||||||
@@ -316,7 +301,6 @@ public class ServerToClientThread implements Runnable, Observer {
|
|||||||
private void sendBoatLocationPackets() {
|
private void sendBoatLocationPackets() {
|
||||||
ArrayList<Yacht> yachts = new ArrayList<>(GameState.getYachts().values());
|
ArrayList<Yacht> yachts = new ArrayList<>(GameState.getYachts().values());
|
||||||
for (Yacht yacht : yachts) {
|
for (Yacht yacht : yachts) {
|
||||||
// System.out.println("[SERVER] Lat: " + yacht.getLocation().getLat() + " Lon: " + yacht.getLocation().getLng());
|
|
||||||
BoatLocationMessage boatLocationMessage =
|
BoatLocationMessage boatLocationMessage =
|
||||||
new BoatLocationMessage(
|
new BoatLocationMessage(
|
||||||
yacht.getSourceId(),
|
yacht.getSourceId(),
|
||||||
@@ -337,7 +321,6 @@ public class ServerToClientThread implements Runnable, Observer {
|
|||||||
public void sendRaceStatusMessage() {
|
public void sendRaceStatusMessage() {
|
||||||
// variables taken from GameServerThread
|
// variables taken from GameServerThread
|
||||||
|
|
||||||
|
|
||||||
List<BoatSubMessage> boatSubMessages = new ArrayList<>();
|
List<BoatSubMessage> boatSubMessages = new ArrayList<>();
|
||||||
BoatStatus boatStatus;
|
BoatStatus boatStatus;
|
||||||
RaceStatus raceStatus;
|
RaceStatus raceStatus;
|
||||||
@@ -372,4 +355,12 @@ public class ServerToClientThread implements Runnable, Observer {
|
|||||||
public Socket getSocket() {
|
public Socket getSocket() {
|
||||||
return socket;
|
return socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addConnectionListener(ConnectionListener listener) {
|
||||||
|
connectionListeners.add(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeConnectionListener(ConnectionListener listener) {
|
||||||
|
connectionListeners.remove(listener);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-6
@@ -6,29 +6,30 @@ import java.util.Map;
|
|||||||
/**
|
/**
|
||||||
* Created by kre39 on 12/07/17.
|
* Created by kre39 on 12/07/17.
|
||||||
*/
|
*/
|
||||||
public enum BoatActionType {
|
public enum BoatAction {
|
||||||
|
|
||||||
VMG(1),
|
VMG(1),
|
||||||
SAILS_IN(2),
|
SAILS_IN(2),
|
||||||
SAILS_OUT(3),
|
SAILS_OUT(3),
|
||||||
TACK_GYBE(4),
|
TACK_GYBE(4),
|
||||||
UPWIND(5),
|
UPWIND(5),
|
||||||
DOWNWIND(6);
|
DOWNWIND(6),
|
||||||
|
MAINTAIN_HEADING(7);
|
||||||
|
|
||||||
private final int type;
|
private final int type;
|
||||||
private static final Map<Integer, BoatActionType> intToTypeMap = new HashMap<>();
|
private static final Map<Integer, BoatAction> intToTypeMap = new HashMap<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
for (BoatActionType type : BoatActionType.values()) {
|
for (BoatAction type : BoatAction.values()) {
|
||||||
intToTypeMap.put(type.getValue(), type);
|
intToTypeMap.put(type.getValue(), type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BoatActionType(int type){
|
BoatAction(int type){
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BoatActionType getType(int value) {
|
public static BoatAction getType(int value) {
|
||||||
return intToTypeMap.get(value);
|
return intToTypeMap.get(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6,9 +6,9 @@ package seng302.gameServer.server.messages;
|
|||||||
public class BoatActionMessage extends Message{
|
public class BoatActionMessage extends Message{
|
||||||
private final MessageType MESSAGE_TYPE = MessageType.BOAT_ACTION;
|
private final MessageType MESSAGE_TYPE = MessageType.BOAT_ACTION;
|
||||||
private final int MESSAGE_SIZE = 1;
|
private final int MESSAGE_SIZE = 1;
|
||||||
private BoatActionType actionType;
|
private BoatAction actionType;
|
||||||
|
|
||||||
public BoatActionMessage(BoatActionType actionType) {
|
public BoatActionMessage(BoatAction actionType) {
|
||||||
this.actionType = actionType;
|
this.actionType = actionType;
|
||||||
setHeader(new Header(MessageType.BOAT_ACTION, 0, (short) 1)); // the second variable is the source id
|
setHeader(new Header(MessageType.BOAT_ACTION, 0, (short) 1)); // the second variable is the source id
|
||||||
allocateBuffer();
|
allocateBuffer();
|
||||||
|
|||||||
@@ -71,8 +71,6 @@ public final class PolarTable {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println("[PolarTable] IO exception");
|
System.out.println("[PolarTable] IO exception");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -155,7 +153,6 @@ public final class PolarTable {
|
|||||||
public static Double getClosestWindSpeedInPolar(Double thisWindSpeed) {
|
public static Double getClosestWindSpeedInPolar(Double thisWindSpeed) {
|
||||||
Double smallestDif = Double.POSITIVE_INFINITY;
|
Double smallestDif = Double.POSITIVE_INFINITY;
|
||||||
Double closestWind = 0d;
|
Double closestWind = 0d;
|
||||||
|
|
||||||
for (Double polarWindSpeed : polarTable.keySet()) {
|
for (Double polarWindSpeed : polarTable.keySet()) {
|
||||||
Double difference = Math.abs(polarWindSpeed - thisWindSpeed);
|
Double difference = Math.abs(polarWindSpeed - thisWindSpeed);
|
||||||
if (difference < smallestDif) {
|
if (difference < smallestDif) {
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ public class Yacht {
|
|||||||
private Integer legNumber = 0;
|
private Integer legNumber = 0;
|
||||||
|
|
||||||
//SERVER SIDE
|
//SERVER SIDE
|
||||||
private final Double TURN_STEP = 5.0;
|
public static final Double TURN_STEP = 5.0; //This should be in some utils class somewhere 2bh. Public for tests sake.
|
||||||
private Double lastHeading;
|
private Double lastHeading;
|
||||||
private Boolean sailIn = false;
|
private Boolean sailIn = false;
|
||||||
private GeoPoint location;
|
private GeoPoint location;
|
||||||
@@ -452,9 +452,9 @@ public class Yacht {
|
|||||||
private void turnTowardsHeading(Double newHeading) {
|
private void turnTowardsHeading(Double newHeading) {
|
||||||
Double newVal = heading - newHeading;
|
Double newVal = heading - newHeading;
|
||||||
if (Math.floorMod(newVal.longValue(), 360L) > 180) {
|
if (Math.floorMod(newVal.longValue(), 360L) > 180) {
|
||||||
adjustHeading(TURN_STEP);
|
adjustHeading(TURN_STEP / 5);
|
||||||
} else {
|
} else {
|
||||||
adjustHeading(-TURN_STEP);
|
adjustHeading(-TURN_STEP / 5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
import java.util.Timer;
|
||||||
|
import java.util.TimerTask;
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
import java.util.zip.CRC32;
|
import java.util.zip.CRC32;
|
||||||
import java.util.zip.Checksum;
|
import java.util.zip.Checksum;
|
||||||
@@ -19,7 +21,12 @@ import javafx.scene.control.Alert.AlertType;
|
|||||||
import javafx.scene.control.ButtonType;
|
import javafx.scene.control.ButtonType;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import seng302.gameServer.server.messages.*;
|
import seng302.gameServer.server.messages.BoatAction;
|
||||||
|
import seng302.gameServer.server.messages.BoatActionMessage;
|
||||||
|
import seng302.gameServer.server.messages.ClientType;
|
||||||
|
import seng302.gameServer.server.messages.Message;
|
||||||
|
import seng302.gameServer.server.messages.RegistrationRequestMessage;
|
||||||
|
import seng302.gameServer.server.messages.RegistrationResponseStatus;
|
||||||
import seng302.model.stream.packets.PacketType;
|
import seng302.model.stream.packets.PacketType;
|
||||||
import seng302.model.stream.packets.StreamPacket;
|
import seng302.model.stream.packets.StreamPacket;
|
||||||
|
|
||||||
@@ -53,9 +60,16 @@ public class ClientToServerThread implements Runnable {
|
|||||||
|
|
||||||
private Socket socket;
|
private Socket socket;
|
||||||
private InputStream is;
|
private InputStream is;
|
||||||
private OutputStream os;
|
|
||||||
private Logger logger = LoggerFactory.getLogger(ClientToServerThread.class);
|
private Logger logger = LoggerFactory.getLogger(ClientToServerThread.class);
|
||||||
|
|
||||||
|
//Output stream
|
||||||
|
private OutputStream os;
|
||||||
|
private Timer upWindPacketTimer = new Timer();
|
||||||
|
private Timer downWindPacketTimer = new Timer();
|
||||||
|
private boolean upwindTimerFlag = false, downwindTimerFlag = false;
|
||||||
|
static public final int PACKET_SENDING_INTERVAL_MS = 100;
|
||||||
|
|
||||||
private int clientId = -1;
|
private int clientId = -1;
|
||||||
|
|
||||||
// private Boolean updateClient = true;
|
// private Boolean updateClient = true;
|
||||||
@@ -143,6 +157,7 @@ public class ClientToServerThread implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (ByteReadException e) {
|
} catch (ByteReadException e) {
|
||||||
|
e.printStackTrace();
|
||||||
closeSocket();
|
closeSocket();
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
Alert alert = new Alert(AlertType.ERROR);
|
Alert alert = new Alert(AlertType.ERROR);
|
||||||
@@ -153,7 +168,6 @@ public class ClientToServerThread implements Runnable {
|
|||||||
clientLog(e.getMessage(), 1);
|
clientLog(e.getMessage(), 1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// System.out.println("streamPackets = " + streamPackets.size());
|
|
||||||
}
|
}
|
||||||
closeSocket();
|
closeSocket();
|
||||||
clientLog("Closed connection to Server", 0);
|
clientLog("Closed connection to Server", 0);
|
||||||
@@ -207,21 +221,81 @@ public class ClientToServerThread implements Runnable {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends packets for the given boat action. Special cases are: \n
|
||||||
|
* - DOWNWIND = Packets are sent every ClientToServerThread.PACKET_SENDING_INTERVAL_MS
|
||||||
|
* - UPWIND = Packets are sent every ClientToServerThread.PACKET_SENDING_INTERVAL_MS
|
||||||
|
* - MAINTAIN_HEADING = DOWNWIND and UPWIND packets stop being sent.
|
||||||
|
* @param actionType The boat action that will dictate packets sent.
|
||||||
|
*/
|
||||||
|
public void sendBoatAction(BoatAction actionType) {
|
||||||
|
switch (actionType) {
|
||||||
|
case MAINTAIN_HEADING:
|
||||||
|
if (upwindTimerFlag) {
|
||||||
|
cancelTimer(upWindPacketTimer);
|
||||||
|
upwindTimerFlag = false;
|
||||||
|
upWindPacketTimer = new Timer();
|
||||||
|
}
|
||||||
|
if (downwindTimerFlag) {
|
||||||
|
cancelTimer(downWindPacketTimer);
|
||||||
|
downwindTimerFlag = false;
|
||||||
|
downWindPacketTimer = new Timer();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case DOWNWIND:
|
||||||
|
if (!downwindTimerFlag) {
|
||||||
|
downwindTimerFlag = true;
|
||||||
|
downWindPacketTimer.scheduleAtFixedRate(
|
||||||
|
new TimerTask() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
sendBoatAction(new BoatActionMessage(BoatAction.DOWNWIND));
|
||||||
|
}
|
||||||
|
}, 0, PACKET_SENDING_INTERVAL_MS
|
||||||
|
);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case UPWIND:
|
||||||
|
if (!upwindTimerFlag) {
|
||||||
|
upwindTimerFlag = true;
|
||||||
|
upWindPacketTimer.scheduleAtFixedRate(
|
||||||
|
new TimerTask() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
sendBoatAction(new BoatActionMessage(BoatAction.UPWIND));
|
||||||
|
}
|
||||||
|
}, 0, PACKET_SENDING_INTERVAL_MS
|
||||||
|
);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
sendBoatAction(new BoatActionMessage(actionType));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send the post-start race course information
|
* Cancels a packet sending timer.
|
||||||
* @param boatActionMessage The message to send
|
* @param timer The timer to cancel.
|
||||||
*/
|
*/
|
||||||
public void sendBoatActionMessage(BoatActionMessage boatActionMessage) {
|
private void cancelTimer (Timer timer) {
|
||||||
if (clientId == -1) return;
|
timer.cancel();
|
||||||
|
timer.purge();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends a boat action of the given message type.
|
||||||
|
* @param message The given message type.
|
||||||
|
*/
|
||||||
|
private void sendBoatAction(BoatActionMessage message) {
|
||||||
|
if (clientId != -1) {
|
||||||
try {
|
try {
|
||||||
os.write(boatActionMessage.getBuffer());
|
os.write(message.getBuffer());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
clientLog("Could not write to server", 1);
|
clientLog("Could not write to server", 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void closeSocket() {
|
private void closeSocket() {
|
||||||
try {
|
try {
|
||||||
@@ -275,11 +349,8 @@ public class ClientToServerThread implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Thread getThread() {
|
|
||||||
return thread;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getClientId () {
|
public int getClientId () {
|
||||||
return clientId;
|
return clientId;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,8 +13,7 @@ import javafx.scene.Node;
|
|||||||
import javafx.scene.input.KeyEvent;
|
import javafx.scene.input.KeyEvent;
|
||||||
import javafx.scene.layout.Pane;
|
import javafx.scene.layout.Pane;
|
||||||
import seng302.gameServer.MainServerThread;
|
import seng302.gameServer.MainServerThread;
|
||||||
import seng302.gameServer.server.messages.BoatActionMessage;
|
import seng302.gameServer.server.messages.BoatAction;
|
||||||
import seng302.gameServer.server.messages.BoatActionType;
|
|
||||||
import seng302.model.RaceState;
|
import seng302.model.RaceState;
|
||||||
import seng302.model.Yacht;
|
import seng302.model.Yacht;
|
||||||
import seng302.model.stream.packets.StreamPacket;
|
import seng302.model.stream.packets.StreamPacket;
|
||||||
@@ -31,7 +30,8 @@ import seng302.visualiser.controllers.LobbyController.CloseStatus;
|
|||||||
import seng302.visualiser.controllers.RaceViewController;
|
import seng302.visualiser.controllers.RaceViewController;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by cir27 on 20/07/17.
|
* This class is a client side instance of a yacht racing game in JavaFX. The game is instantiated
|
||||||
|
* with a JavaFX Pane to insert itself into.
|
||||||
*/
|
*/
|
||||||
public class GameClient {
|
public class GameClient {
|
||||||
|
|
||||||
@@ -48,13 +48,20 @@ public class GameClient {
|
|||||||
|
|
||||||
private ObservableList<String> clientLobbyList = FXCollections.observableArrayList();
|
private ObservableList<String> clientLobbyList = FXCollections.observableArrayList();
|
||||||
|
|
||||||
private long lastSendingTime;
|
/**
|
||||||
private int KEY_STROKE_SENDING_FREQUENCY = 50;
|
* Create an instance of the game client. Does not do anything until run with runAsClient()
|
||||||
|
* runAsHost().
|
||||||
|
* @param holder The JavaFX Pane that the visual elements for the race will be inserted into.
|
||||||
|
*/
|
||||||
public GameClient(Pane holder) {
|
public GameClient(Pane holder) {
|
||||||
this.holderPane = holder;
|
this.holderPane = holder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Connect to a game at the given address and starts the visualiser.
|
||||||
|
* @param ipAddress IP to connect to.
|
||||||
|
* @param portNumber Port to connect to.
|
||||||
|
*/
|
||||||
public void runAsClient(String ipAddress, Integer portNumber) {
|
public void runAsClient(String ipAddress, Integer portNumber) {
|
||||||
try {
|
try {
|
||||||
socketThread = new ClientToServerThread(ipAddress, portNumber);
|
socketThread = new ClientToServerThread(ipAddress, portNumber);
|
||||||
@@ -71,6 +78,11 @@ public class GameClient {
|
|||||||
lobbyController.addCloseListener((exitCause) -> this.loadStartScreen());
|
lobbyController.addCloseListener((exitCause) -> this.loadStartScreen());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Connect to a game as the host at the given address and starts the visualiser.
|
||||||
|
* @param ipAddress IP to connect to.
|
||||||
|
* @param portNumber Port to connect to.
|
||||||
|
*/
|
||||||
public void runAsHost(String ipAddress, Integer portNumber) {
|
public void runAsHost(String ipAddress, Integer portNumber) {
|
||||||
server = new MainServerThread();
|
server = new MainServerThread();
|
||||||
try {
|
try {
|
||||||
@@ -94,10 +106,8 @@ public class GameClient {
|
|||||||
|
|
||||||
private void loadStartScreen() {
|
private void loadStartScreen() {
|
||||||
socketThread.setSocketToClose();
|
socketThread.setSocketToClose();
|
||||||
socketThread = null;
|
|
||||||
if (server != null) {
|
if (server != null) {
|
||||||
// TODO: 26/07/17 cir27 - handle disconnecting
|
server.terminate();
|
||||||
// server.shutDown();
|
|
||||||
server = null;
|
server = null;
|
||||||
}
|
}
|
||||||
FXMLLoader fxmlLoader = new FXMLLoader(
|
FXMLLoader fxmlLoader = new FXMLLoader(
|
||||||
@@ -179,12 +189,9 @@ public class GameClient {
|
|||||||
StreamParser.extractXmlMessage(packet)
|
StreamParser.extractXmlMessage(packet)
|
||||||
);
|
);
|
||||||
clientLobbyList.clear();
|
clientLobbyList.clear();
|
||||||
allBoatsMap.forEach((id, boat) -> {
|
allBoatsMap.forEach((id, boat) ->
|
||||||
clientLobbyList.add(id + " " + boat.getBoatName());
|
clientLobbyList.add(id + " " + boat.getBoatName())
|
||||||
// System.out.println(id + " " + boat.getBoatName());
|
);
|
||||||
|
|
||||||
});
|
|
||||||
// startRaceIfAllDataReceived();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RACE_START_STATUS:
|
case RACE_START_STATUS:
|
||||||
@@ -281,28 +288,16 @@ public class GameClient {
|
|||||||
* Handle the key-pressed event from the text field.
|
* Handle the key-pressed event from the text field.
|
||||||
* @param e The key event triggering this call
|
* @param e The key event triggering this call
|
||||||
*/
|
*/
|
||||||
public void keyPressed(KeyEvent e) {
|
private void keyPressed(KeyEvent e) {
|
||||||
BoatActionMessage boatActionMessage;
|
|
||||||
long currentTime = System.currentTimeMillis();
|
|
||||||
if (currentTime - lastSendingTime > KEY_STROKE_SENDING_FREQUENCY) {
|
|
||||||
lastSendingTime = currentTime;
|
|
||||||
switch (e.getCode()) {
|
switch (e.getCode()) {
|
||||||
case SPACE: // align with vmg
|
case SPACE: // align with vmg
|
||||||
boatActionMessage = new BoatActionMessage(BoatActionType.VMG);
|
socketThread.sendBoatAction(BoatAction.VMG); break;
|
||||||
socketThread.sendBoatActionMessage(boatActionMessage);
|
|
||||||
break;
|
|
||||||
case PAGE_UP: // upwind
|
case PAGE_UP: // upwind
|
||||||
boatActionMessage = new BoatActionMessage(BoatActionType.UPWIND);
|
socketThread.sendBoatAction(BoatAction.UPWIND); break;
|
||||||
socketThread.sendBoatActionMessage(boatActionMessage);
|
|
||||||
break;
|
|
||||||
case PAGE_DOWN: // downwind
|
case PAGE_DOWN: // downwind
|
||||||
boatActionMessage = new BoatActionMessage(BoatActionType.DOWNWIND);
|
socketThread.sendBoatAction(BoatAction.DOWNWIND); break;
|
||||||
socketThread.sendBoatActionMessage(boatActionMessage);
|
|
||||||
break;
|
|
||||||
case ENTER: // tack/gybe
|
case ENTER: // tack/gybe
|
||||||
boatActionMessage = new BoatActionMessage(BoatActionType.TACK_GYBE);
|
socketThread.sendBoatAction(BoatAction.TACK_GYBE); break;
|
||||||
socketThread.sendBoatActionMessage(boatActionMessage);
|
|
||||||
break;
|
|
||||||
//TODO Allow a zoom in and zoom out methods
|
//TODO Allow a zoom in and zoom out methods
|
||||||
case Z: // zoom in
|
case Z: // zoom in
|
||||||
System.out.println("Zoom in");
|
System.out.println("Zoom in");
|
||||||
@@ -312,17 +307,15 @@ public class GameClient {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void keyReleased(KeyEvent e) {
|
private void keyReleased(KeyEvent e) {
|
||||||
switch (e.getCode()) {
|
switch (e.getCode()) {
|
||||||
//TODO 12/07/17 Determine the sail state and send the appropriate packet (eg. if sails are in, send a sail out packet)
|
//TODO 12/07/17 Determine the sail state and send the appropriate packet (eg. if sails are in, send a sail out packet)
|
||||||
case SHIFT: // sails in/sails out
|
case SHIFT: // sails in/sails out
|
||||||
BoatActionMessage boatActionMessage = new BoatActionMessage(
|
socketThread.sendBoatAction(BoatAction.SAILS_IN); break;
|
||||||
BoatActionType.SAILS_IN);
|
case PAGE_UP:
|
||||||
socketThread.sendBoatActionMessage(boatActionMessage);
|
case PAGE_DOWN:
|
||||||
raceView.getGameView().getPlayerYacht().toggleClientSail();
|
socketThread.sendBoatAction(BoatAction.MAINTAIN_HEADING); break;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ public class GameView extends Pane {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Platform.runLater(() ->
|
// Platform.runLater(() ->
|
||||||
// boatObjects.forEach((boat, boatObject) -> boatObject.updateLocation())
|
boatObjects.forEach((boat, boatObject) -> boatObject.updateLocation());
|
||||||
// );
|
// );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -494,7 +494,6 @@ public class GameView extends Pane {
|
|||||||
distanceFromReference = GeoUtility.getDistance(
|
distanceFromReference = GeoUtility.getDistance(
|
||||||
minLatPoint, new GeoPoint(unscaledLat, unscaledLon)
|
minLatPoint, new GeoPoint(unscaledLat, unscaledLon)
|
||||||
);
|
);
|
||||||
// System.out.println("distanceFromReference = " + distanceFromReference);
|
|
||||||
if (angleFromReference >= 0 && angleFromReference <= Math.PI / 2) {
|
if (angleFromReference >= 0 && angleFromReference <= Math.PI / 2) {
|
||||||
xAxisLocation += Math.round(distanceScaleFactor * Math.sin(angleFromReference) * distanceFromReference);
|
xAxisLocation += Math.round(distanceScaleFactor * Math.sin(angleFromReference) * distanceFromReference);
|
||||||
yAxisLocation -= Math.round(distanceScaleFactor * Math.cos(angleFromReference) * distanceFromReference);
|
yAxisLocation -= Math.round(distanceScaleFactor * Math.cos(angleFromReference) * distanceFromReference);
|
||||||
@@ -514,8 +513,6 @@ public class GameView extends Pane {
|
|||||||
if(horizontalInversion) {
|
if(horizontalInversion) {
|
||||||
xAxisLocation = canvasWidth - bufferSize - (xAxisLocation - bufferSize);
|
xAxisLocation = canvasWidth - bufferSize - (xAxisLocation - bufferSize);
|
||||||
}
|
}
|
||||||
// System.out.println("yAxisLocation = " + yAxisLocation + " " + unscaledLat);
|
|
||||||
// System.out.println("xAxisLocation = " + xAxisLocation + " " + unscaledLon);
|
|
||||||
return new Point2D(xAxisLocation, yAxisLocation);
|
return new Point2D(xAxisLocation, yAxisLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,15 +4,13 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.collections.FXCollections;
|
|
||||||
import javafx.collections.ListChangeListener;
|
import javafx.collections.ListChangeListener;
|
||||||
import javafx.collections.ObservableList;
|
import javafx.collections.ObservableList;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.control.ListView;
|
import javafx.scene.control.TextArea;
|
||||||
import javafx.scene.image.Image;
|
import javafx.scene.image.Image;
|
||||||
import javafx.scene.image.ImageView;
|
import javafx.scene.image.ImageView;
|
||||||
import javafx.scene.layout.GridPane;
|
|
||||||
import javafx.scene.text.Text;
|
import javafx.scene.text.Text;
|
||||||
import seng302.gameServer.GameStages;
|
import seng302.gameServer.GameStages;
|
||||||
import seng302.gameServer.GameState;
|
import seng302.gameServer.GameState;
|
||||||
@@ -33,28 +31,26 @@ public class LobbyController {
|
|||||||
void notify(CloseStatus exitCause);
|
void notify(CloseStatus exitCause);
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
|
||||||
private GridPane lobbyScreen;
|
|
||||||
@FXML
|
@FXML
|
||||||
private Text lobbyIpText;
|
private Text lobbyIpText;
|
||||||
@FXML
|
@FXML
|
||||||
private Button readyButton;
|
private Button readyButton;
|
||||||
@FXML
|
@FXML
|
||||||
private ListView<String> firstListView;
|
private TextArea playerOneTxt;
|
||||||
@FXML
|
@FXML
|
||||||
private ListView secondListView;
|
private TextArea playerTwoTxt;
|
||||||
@FXML
|
@FXML
|
||||||
private ListView thirdListView;
|
private TextArea playerThreeTxt;
|
||||||
@FXML
|
@FXML
|
||||||
private ListView fourthListView;
|
private TextArea playerFourTxt;
|
||||||
@FXML
|
@FXML
|
||||||
private ListView fifthListView;
|
private TextArea playerFiveTxt;
|
||||||
@FXML
|
@FXML
|
||||||
private ListView sixthListView;
|
private TextArea playerSixTxt;
|
||||||
@FXML
|
@FXML
|
||||||
private ListView seventhListView;
|
private TextArea playerSevenTxt;
|
||||||
@FXML
|
@FXML
|
||||||
private ListView eighthListView;
|
private TextArea playerEightTxt;
|
||||||
@FXML
|
@FXML
|
||||||
private ImageView firstImageView;
|
private ImageView firstImageView;
|
||||||
@FXML
|
@FXML
|
||||||
@@ -72,79 +68,67 @@ public class LobbyController {
|
|||||||
@FXML
|
@FXML
|
||||||
private ImageView eighthImageView;
|
private ImageView eighthImageView;
|
||||||
|
|
||||||
private List<ObservableList<String>> competitors = new ArrayList<>();
|
|
||||||
private ObservableList<String> firstCompetitor = FXCollections.observableArrayList();
|
|
||||||
private ObservableList<String> secondCompetitor = FXCollections.observableArrayList();
|
|
||||||
private ObservableList<String> thirdCompetitor = FXCollections.observableArrayList();
|
|
||||||
private ObservableList<String> fourthCompetitor = FXCollections.observableArrayList();
|
|
||||||
private ObservableList<String> fifthCompetitor = FXCollections.observableArrayList();
|
|
||||||
private ObservableList<String> sixthCompetitor = FXCollections.observableArrayList();
|
|
||||||
private ObservableList<String> seventhCompetitor = FXCollections.observableArrayList();
|
|
||||||
private ObservableList<String> eighthCompetitor = FXCollections.observableArrayList();
|
|
||||||
|
|
||||||
private List<ImageView> imageViews = new ArrayList<>();
|
private List<ImageView> imageViews = new ArrayList<>();
|
||||||
private List<ListView> listViews;
|
private List<TextArea> listViews = new ArrayList<>();
|
||||||
|
|
||||||
private int MAX_NUM_PLAYERS = 8;
|
private int MAX_NUM_PLAYERS = 8;
|
||||||
|
|
||||||
private List<LobbyCloseListener> lobbyListeners = new ArrayList<>();
|
private List<LobbyCloseListener> lobbyListeners = new ArrayList<>();
|
||||||
private ObservableList<String> players = FXCollections.observableArrayList();
|
private ObservableList<String> players;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add all FXObjects to lists and initialize images.
|
||||||
|
*/
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
imageViews = new ArrayList<>();
|
Collections.addAll(listViews,
|
||||||
Collections
|
playerOneTxt, playerTwoTxt, playerThreeTxt, playerFourTxt, playerFiveTxt, playerSixTxt,
|
||||||
.addAll(imageViews, firstImageView, secondImageView, thirdImageView, fourthImageView,
|
playerSevenTxt, playerEightTxt
|
||||||
fifthImageView, sixthImageView, seventhImageView, eighthImageView);
|
);
|
||||||
listViews = new ArrayList<>();
|
Collections.addAll(imageViews,
|
||||||
Collections.addAll(listViews, firstListView, secondListView, thirdListView, fourthListView, fifthListView,
|
firstImageView, secondImageView, thirdImageView, fourthImageView,
|
||||||
sixthListView, seventhListView, eighthListView);
|
fifthImageView, sixthImageView, seventhImageView, eighthImageView
|
||||||
competitors = new ArrayList<>();
|
);
|
||||||
Collections.addAll(competitors, firstCompetitor, secondCompetitor, thirdCompetitor,
|
|
||||||
fourthCompetitor, fifthCompetitor, sixthCompetitor, seventhCompetitor, eighthCompetitor);
|
|
||||||
|
|
||||||
initialiseImageView();
|
initialiseImageView();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initialiseListView() {
|
/**
|
||||||
listViews.forEach(listView -> listView.getItems().clear());
|
* Updates player names.
|
||||||
imageViews.forEach(gif -> gif.setVisible(false));
|
*/
|
||||||
competitors.forEach(ol -> ol.removeAll());
|
private void updatePlayers() {
|
||||||
|
//Update players if one added.
|
||||||
for (int i = 0; i < players.size(); i++) {
|
for (int i = 0; i < players.size(); i++) {
|
||||||
competitors.get(i).add(players.get(i));
|
listViews.get(i).setText(players.get(i));
|
||||||
listViews.get(i).setItems(competitors.get(i));
|
|
||||||
imageViews.get(i).setVisible(true);
|
imageViews.get(i).setVisible(true);
|
||||||
}
|
}
|
||||||
|
//Update empty text fields if player left.
|
||||||
|
for (int i = MAX_NUM_PLAYERS-1; i >= players.size(); i--) {
|
||||||
|
listViews.get(i).setText("");
|
||||||
|
imageViews.get(i).setVisible(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets all images and hides them till players join.
|
||||||
|
*/
|
||||||
private void initialiseImageView() {
|
private void initialiseImageView() {
|
||||||
imageViews.add(firstImageView);
|
for (ImageView viewer : imageViews) {
|
||||||
imageViews.add(secondImageView);
|
viewer.setImage(
|
||||||
imageViews.add(thirdImageView);
|
|
||||||
imageViews.add(fourthImageView);
|
|
||||||
imageViews.add(fifthImageView);
|
|
||||||
imageViews.add(sixthImageView);
|
|
||||||
imageViews.add(seventhImageView);
|
|
||||||
imageViews.add(eighthImageView);
|
|
||||||
for (int i = 0; i < MAX_NUM_PLAYERS; i++) {
|
|
||||||
imageViews.get(i).setImage(
|
|
||||||
new Image(
|
new Image(
|
||||||
RaceViewController.class.getResourceAsStream(
|
RaceViewController.class.getResourceAsStream(
|
||||||
"/pics/sail.png")
|
"/pics/sail.png")
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
viewer.setVisible(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
public void leaveLobbyButtonPressed() {
|
public void leaveLobbyButtonPressed() {
|
||||||
// TODO: 10/07/17 wmu16 - Finish function!
|
// TODO: 10/07/17 wmu16 - Finish function!
|
||||||
// setContentPane("/views/StartScreenView.fxml");
|
|
||||||
GameState.setCurrentStage(GameStages.CANCELLED);
|
GameState.setCurrentStage(GameStages.CANCELLED);
|
||||||
// TODO: 20/07/17 wmu16 - Implement some way of terminating the game
|
// TODO: 20/07/17 wmu16 - Implement some way of terminating the game
|
||||||
// ClientState.setConnectedToHost(false);
|
|
||||||
for (LobbyCloseListener readyListener : lobbyListeners)
|
for (LobbyCloseListener readyListener : lobbyListeners)
|
||||||
readyListener.notify(CloseStatus.LEAVE);
|
readyListener.notify(CloseStatus.LEAVE);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
@@ -154,32 +138,6 @@ public class LobbyController {
|
|||||||
readyListener.notify(CloseStatus.READY);
|
readyListener.notify(CloseStatus.READY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// private static MediaPlayer mediaPlayer;
|
|
||||||
//
|
|
||||||
// private void playTheme() {
|
|
||||||
// Random random = new Random(System.currentTimeMillis());
|
|
||||||
// Integer rand = random.nextInt();
|
|
||||||
// if(rand == 10) {
|
|
||||||
// URL file = getClass().getResource("/music/Disturbed - down with the sickness.mp3");
|
|
||||||
// Media hit = new Media(file.toString());
|
|
||||||
// mediaPlayer = new MediaPlayer(hit);
|
|
||||||
// mediaPlayer.play();
|
|
||||||
// } else if(rand == 9) {
|
|
||||||
// URL file = getClass().getResource("/music/Owl City - Fireflies.mp3");
|
|
||||||
// Media hit = new Media(file.toString());
|
|
||||||
// mediaPlayer = new MediaPlayer(hit);
|
|
||||||
// mediaPlayer.play();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// private void switchToRaceView() {
|
|
||||||
// if (!switchedPane) {
|
|
||||||
// switchedPane = true;
|
|
||||||
// setContentPane("/views/RaceView.fxml");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// TODO: 26/07/17 cir27 - Could probably be done in a cleaner way.
|
|
||||||
public void setTitle (String title) {
|
public void setTitle (String title) {
|
||||||
lobbyIpText.setText(title);
|
lobbyIpText.setText(title);
|
||||||
}
|
}
|
||||||
@@ -191,12 +149,13 @@ public class LobbyController {
|
|||||||
public void setPlayerListSource (ObservableList<String> players) {
|
public void setPlayerListSource (ObservableList<String> players) {
|
||||||
this.players = players;
|
this.players = players;
|
||||||
players.addListener((ListChangeListener<? super String>) (lcl) ->
|
players.addListener((ListChangeListener<? super String>) (lcl) ->
|
||||||
Platform.runLater(this::initialiseListView)
|
Platform.runLater(this::updatePlayers)
|
||||||
);
|
);
|
||||||
Platform.runLater(this::initialiseListView);
|
Platform.runLater(this::updatePlayers);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disableReadyButton () {
|
public void disableReadyButton () {
|
||||||
readyButton.setDisable(true);
|
readyButton.setDisable(true);
|
||||||
|
readyButton.setVisible(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -242,15 +242,15 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
// Adds the new data series to the sparkline (and set the colour of the series)
|
// Adds the new data series to the sparkline (and set the colour of the series)
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() ->
|
||||||
sparkLineData
|
sparkLineData
|
||||||
.stream()
|
.stream()
|
||||||
.filter(spark -> !raceSparkLine.getData().contains(spark))
|
.filter(spark -> !raceSparkLine.getData().contains(spark))
|
||||||
.forEach(spark -> {
|
.forEach(spark -> {
|
||||||
raceSparkLine.getData().add(spark);
|
raceSparkLine.getData().add(spark);
|
||||||
spark.getNode().lookup(".chart-series-line").setStyle("-fx-stroke:" + getBoatColorAsRGB(spark.getName()));
|
spark.getNode().lookup(".chart-series-line").setStyle("-fx-stroke:" + getBoatColorAsRGB(spark.getName()));
|
||||||
});
|
})
|
||||||
});
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initialiseSparkLine() {
|
private void initialiseSparkLine() {
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ public class MercatorProjection {
|
|||||||
* @param geo GeoPoint (lat, lng) location to be projected
|
* @param geo GeoPoint (lat, lng) location to be projected
|
||||||
* @return the projection Point2D (x, y) on planar
|
* @return the projection Point2D (x, y) on planar
|
||||||
*/
|
*/
|
||||||
static Point2D toMapPoint(GeoPoint geo) {
|
public static Point2D toMapPoint(GeoPoint geo) {
|
||||||
double x, y;
|
double x, y;
|
||||||
Point2D origin = new Point2D(MERCATOR_RANGE / 2.0, MERCATOR_RANGE / 2.0);
|
Point2D origin = new Point2D(MERCATOR_RANGE / 2.0, MERCATOR_RANGE / 2.0);
|
||||||
x = (origin.getX() + geo.getLng() * pixelsPerLngDegree);
|
x = (origin.getX() + geo.getLng() * pixelsPerLngDegree);
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import java.lang.*?>
|
||||||
|
<?import javafx.geometry.*?>
|
||||||
|
<?import javafx.scene.control.*?>
|
||||||
|
<?import javafx.scene.image.*?>
|
||||||
|
<?import javafx.scene.layout.*?>
|
||||||
|
<?import javafx.scene.text.*?>
|
||||||
<?import javafx.geometry.Insets?>
|
<?import javafx.geometry.Insets?>
|
||||||
<?import javafx.scene.control.Button?>
|
<?import javafx.scene.control.Button?>
|
||||||
<?import javafx.scene.control.ListView?>
|
<?import javafx.scene.control.ListView?>
|
||||||
@@ -11,6 +16,7 @@
|
|||||||
<?import javafx.scene.layout.RowConstraints?>
|
<?import javafx.scene.layout.RowConstraints?>
|
||||||
<?import javafx.scene.text.Font?>
|
<?import javafx.scene.text.Font?>
|
||||||
<?import javafx.scene.text.Text?>
|
<?import javafx.scene.text.Text?>
|
||||||
|
|
||||||
<GridPane fx:id="lobbyScreen" nodeOrientation="LEFT_TO_RIGHT" prefHeight="960.0" prefWidth="1530.0" style="-fx-background-color: #2C2c36;" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.visualiser.controllers.LobbyController">
|
<GridPane fx:id="lobbyScreen" nodeOrientation="LEFT_TO_RIGHT" prefHeight="960.0" prefWidth="1530.0" style="-fx-background-color: #2C2c36;" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.visualiser.controllers.LobbyController">
|
||||||
<columnConstraints>
|
<columnConstraints>
|
||||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
|
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
|
||||||
@@ -53,41 +59,14 @@
|
|||||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||||
</rowConstraints>
|
</rowConstraints>
|
||||||
<children>
|
<children>
|
||||||
<ListView fx:id="firstListView" prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1">
|
<TextArea fx:id="playerFourTxt" editable="false" maxHeight="211.0" maxWidth="175.0" minHeight="211.0" minWidth="175.0" prefHeight="211.0" prefWidth="175.0" GridPane.columnIndex="4" GridPane.halignment="CENTER" GridPane.valignment="CENTER" />
|
||||||
<GridPane.margin>
|
<TextArea fx:id="playerEightTxt" editable="false" maxHeight="211.0" maxWidth="175.0" minHeight="211.0" minWidth="175.0" prefHeight="211.0" prefWidth="175.0" GridPane.columnIndex="4" GridPane.halignment="CENTER" GridPane.rowIndex="1" GridPane.valignment="CENTER" />
|
||||||
<Insets bottom="10.0" left="40.0" right="40.0" top="10.0" />
|
<TextArea fx:id="playerSevenTxt" editable="false" maxHeight="211.0" maxWidth="175.0" minHeight="211.0" minWidth="175.0" prefHeight="211.0" prefWidth="175.0" GridPane.columnIndex="3" GridPane.halignment="CENTER" GridPane.rowIndex="1" GridPane.valignment="CENTER" />
|
||||||
</GridPane.margin>
|
<TextArea fx:id="playerThreeTxt" editable="false" maxHeight="211.0" maxWidth="175.0" minHeight="211.0" minWidth="175.0" prefHeight="211.0" prefWidth="175.0" GridPane.columnIndex="3" GridPane.halignment="CENTER" GridPane.valignment="CENTER" />
|
||||||
</ListView>
|
<TextArea fx:id="playerSixTxt" editable="false" maxHeight="211.0" maxWidth="175.0" minHeight="211.0" minWidth="175.0" prefHeight="211.0" prefWidth="175.0" GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.rowIndex="1" GridPane.valignment="CENTER" />
|
||||||
<ListView fx:id="secondListView" prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="2">
|
<TextArea fx:id="playerFiveTxt" editable="false" maxHeight="211.0" maxWidth="175.0" minHeight="211.0" minWidth="175.0" prefHeight="211.0" prefWidth="175.0" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="1" GridPane.valignment="CENTER" />
|
||||||
<GridPane.margin>
|
<TextArea fx:id="playerOneTxt" editable="false" maxHeight="211.0" maxWidth="175.0" minHeight="211.0" minWidth="175.0" prefHeight="211.0" prefWidth="175.0" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.valignment="CENTER" />
|
||||||
<Insets bottom="10.0" left="40.0" right="40.0" top="10.0" />
|
<TextArea fx:id="playerTwoTxt" editable="false" maxHeight="211.0" maxWidth="175.0" minHeight="211.0" minWidth="175.0" prefHeight="211.0" prefWidth="175.0" GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.valignment="CENTER" />
|
||||||
</GridPane.margin>
|
|
||||||
</ListView>
|
|
||||||
<ListView fx:id="thirdListView" prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="3">
|
|
||||||
<GridPane.margin>
|
|
||||||
<Insets bottom="10.0" left="40.0" right="40.0" top="10.0" />
|
|
||||||
</GridPane.margin></ListView>
|
|
||||||
<ListView fx:id="fourthListView" prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="4">
|
|
||||||
<GridPane.margin>
|
|
||||||
<Insets bottom="10.0" left="40.0" right="40.0" top="10.0" />
|
|
||||||
</GridPane.margin>
|
|
||||||
</ListView>
|
|
||||||
<ListView fx:id="eighthListView" prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="4" GridPane.rowIndex="1">
|
|
||||||
<GridPane.margin>
|
|
||||||
<Insets bottom="10.0" left="40.0" right="40.0" top="10.0" />
|
|
||||||
</GridPane.margin></ListView>
|
|
||||||
<ListView fx:id="fifthListView" prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="1">
|
|
||||||
<GridPane.margin>
|
|
||||||
<Insets bottom="10.0" left="40.0" right="40.0" top="10.0" />
|
|
||||||
</GridPane.margin></ListView>
|
|
||||||
<ListView fx:id="sixthListView" prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="2" GridPane.rowIndex="1">
|
|
||||||
<GridPane.margin>
|
|
||||||
<Insets bottom="10.0" left="40.0" right="40.0" top="10.0" />
|
|
||||||
</GridPane.margin></ListView>
|
|
||||||
<ListView fx:id="seventhListView" prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="3" GridPane.rowIndex="1">
|
|
||||||
<GridPane.margin>
|
|
||||||
<Insets bottom="10.0" left="40.0" right="40.0" top="10.0" />
|
|
||||||
</GridPane.margin></ListView>
|
|
||||||
<ImageView fx:id="firstImageView" fitHeight="150.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.valignment="BOTTOM">
|
<ImageView fx:id="firstImageView" fitHeight="150.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.valignment="BOTTOM">
|
||||||
<GridPane.margin>
|
<GridPane.margin>
|
||||||
<Insets bottom="10.0" />
|
<Insets bottom="10.0" />
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
package seng302;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
|
|
||||||
public class TestRaceTimer {
|
|
||||||
@Test
|
|
||||||
public void testPositiveTimeString(){
|
|
||||||
// RaceViewController controller = new RaceViewController();
|
|
||||||
// String result = controller.convertTimeToMinutesSeconds(61);
|
|
||||||
//
|
|
||||||
// assertTrue(result.equals("01:01"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testNegativeTimeString(){
|
|
||||||
// RaceViewController controller = new RaceViewController();
|
|
||||||
// String result = controller.convertTimeToMinutesSeconds(-61);
|
|
||||||
//
|
|
||||||
// assertTrue(result.equals("-01:01"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -37,12 +37,12 @@ public class YachtTest {
|
|||||||
for (Double begin : values.keySet()) {
|
for (Double begin : values.keySet()) {
|
||||||
y1.setHeading(begin);
|
y1.setHeading(begin);
|
||||||
y1.tackGybe(windDirection);
|
y1.tackGybe(windDirection);
|
||||||
for (int i = 0; i < 50; i++) {
|
|
||||||
|
for (int i = 0; i < 200; i++) {
|
||||||
y1.runAutoPilot();
|
y1.runAutoPilot();
|
||||||
}
|
}
|
||||||
assertEquals(values.get(begin), y1.getHeading(), 5.0);
|
assertEquals(values.get(begin), y1.getHeading(), 5.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -67,12 +67,10 @@ public class YachtTest {
|
|||||||
values.put(350d, downwindRight);
|
values.put(350d, downwindRight);
|
||||||
|
|
||||||
for (Double begin : values.keySet()) {
|
for (Double begin : values.keySet()) {
|
||||||
System.out.println(begin);
|
|
||||||
y1.setHeading(begin);
|
y1.setHeading(begin);
|
||||||
y1.turnToVMG();
|
y1.turnToVMG();
|
||||||
for (int i = 0; i < 50; i++) {
|
for (int i = 0; i < 200; i++) {
|
||||||
y1.runAutoPilot();
|
y1.runAutoPilot();
|
||||||
System.out.println(y1.getHeading());
|
|
||||||
}
|
}
|
||||||
y1.disableAutoPilot();
|
y1.disableAutoPilot();
|
||||||
assertEquals(values.get(begin), y1.getHeading(), 5.0);
|
assertEquals(values.get(begin), y1.getHeading(), 5.0);
|
||||||
|
|||||||
@@ -0,0 +1,80 @@
|
|||||||
|
package seng302.visualiser.ClientToServerTests;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import seng302.gameServer.GameStages;
|
||||||
|
import seng302.gameServer.GameState;
|
||||||
|
import seng302.gameServer.MainServerThread;
|
||||||
|
import seng302.gameServer.server.messages.BoatAction;
|
||||||
|
import seng302.model.Yacht;
|
||||||
|
import seng302.visualiser.ClientToServerThread;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for checking how regularly packets are sent from ClientToServer Thread.
|
||||||
|
*/
|
||||||
|
public class RegularPacketsTest {
|
||||||
|
|
||||||
|
private MainServerThread serverThread;
|
||||||
|
private ClientToServerThread clientThread;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() throws Exception {
|
||||||
|
new GameState("localhost");
|
||||||
|
serverThread = new MainServerThread();
|
||||||
|
clientThread = new ClientToServerThread("localhost", 4942);
|
||||||
|
GameState.setCurrentStage(GameStages.RACING);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void packetsSentAtRegularIntervals () throws Exception {
|
||||||
|
final double TEST_DISTANCE = 10.0;
|
||||||
|
serverThread.startGame();
|
||||||
|
SleepThreadMaxDelay();
|
||||||
|
Yacht yacht = new ArrayList<>(GameState.getYachts().values()).get(0);
|
||||||
|
double startAngle = yacht.getHeading();
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
clientThread.sendBoatAction(BoatAction.UPWIND);
|
||||||
|
Thread.sleep(200);
|
||||||
|
while (Math.abs(yacht.getHeading() - startAngle) < TEST_DISTANCE) {
|
||||||
|
Thread.sleep(1);
|
||||||
|
}
|
||||||
|
clientThread.sendBoatAction(BoatAction.MAINTAIN_HEADING);
|
||||||
|
long endTime = System.currentTimeMillis();
|
||||||
|
SleepThreadMaxDelay();
|
||||||
|
//Allowed to be two loops of delay due to loop delay and processing delay at client + server ends.
|
||||||
|
Assert.assertEquals(TEST_DISTANCE / Yacht.TURN_STEP * ClientToServerThread.PACKET_SENDING_INTERVAL_MS,
|
||||||
|
(endTime - startTime), 2 * ClientToServerThread.PACKET_SENDING_INTERVAL_MS);
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Test
|
||||||
|
// public void testArbitraryPacketSent() throws Exception {
|
||||||
|
// serverThread.startGame();
|
||||||
|
// SleepThreadMaxDelay();
|
||||||
|
// Yacht yacht = new ArrayList<>(GameState.getYachts().values()).get(0);
|
||||||
|
// boolean startState = yacht.getSailIn();
|
||||||
|
// clientThread.sendBoatAction(BoatAction.SAILS_IN);
|
||||||
|
// SleepThreadMaxDelay();
|
||||||
|
// Assert.assertEquals(startState, !yacht.getSailIn());
|
||||||
|
// }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Give time for processing and packet sending. 200ms listed as absolute maximum for an
|
||||||
|
* acceptable delay.
|
||||||
|
* @throws Exception Thrown if thread crashes or something
|
||||||
|
*/
|
||||||
|
private void SleepThreadMaxDelay() throws Exception {
|
||||||
|
Thread.sleep(200);
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void teardown () throws Exception {
|
||||||
|
clientThread.setSocketToClose();
|
||||||
|
serverThread.terminate();
|
||||||
|
GameState.setCurrentStage(GameStages.LOBBYING);
|
||||||
|
for (int i = 0; i<20; i++)
|
||||||
|
SleepThreadMaxDelay(); //Make sure socket is closed and toolkit remade.
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package seng302.visualizer.annotations;
|
package seng302.visualiser.annotations;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
Reference in New Issue
Block a user