Merge remote-tracking branch 'origin/develop' into NewUI_merge

# Conflicts:
#	src/main/java/seng302/gameServer/GameState.java
#	src/main/java/seng302/gameServer/MainServerThread.java
#	src/main/java/seng302/gameServer/ServerToClientThread.java
#	src/main/java/seng302/visualiser/GameClient.java
#	src/main/java/seng302/visualiser/GameView.java
#	src/main/java/seng302/visualiser/controllers/FinishScreenViewController.java
#	src/main/java/seng302/visualiser/controllers/LobbyController.java
#	src/main/java/seng302/visualiser/controllers/RaceViewController.java
#	src/main/java/seng302/visualiser/controllers/StartScreenController.java
#	src/main/resources/views/LobbyView.fxml
#	src/main/resources/views/RaceView.fxml
#	src/main/resources/views/StartScreenView.fxml
This commit is contained in:
Haoming Yin
2017-09-11 18:15:08 +12:00
43 changed files with 1303 additions and 312 deletions
@@ -0,0 +1,247 @@
package seng302.gameServer.server;
import java.io.IOException;
import org.junit.Assert;
import org.junit.Test;
import seng302.gameServer.GameState;
import seng302.gameServer.MainServerThread;
import seng302.gameServer.messages.BoatStatus;
import seng302.model.stream.packets.StreamPacket;
import seng302.model.stream.parser.RaceStatusData;
import seng302.utilities.StreamParser;
import seng302.visualiser.ClientToServerThread;
/**
* Created by cir27 on 3/09/17.
*/
public class ChatCommandsTest {
private boolean dcSent = false;
private ClientToServerThread client;
private ClientToServerThread host;
private MainServerThread mst;
@Test
public void sendFinishAsHost () {
try {
Thread.sleep(1000);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
try {
dcSent = false;
new GameState("localhost");
mst = new MainServerThread();
host = new ClientToServerThread("localhost", 4942);
host.addStreamObserver(() -> {
while (host.getPacketQueue().peek() != null) {
StreamPacket packet = host.getPacketQueue().poll();
switch (packet.getType()) {
case RACE_STATUS:
RaceStatusData rsd = StreamParser.extractRaceStatus(packet);
if (rsd.getBoatData().get(0)[4] == BoatStatus.FINISHED.getCode()) {
mst.terminate();
Assert.assertTrue(dcSent);
}
break;
default:
break;
}
}
});
try {
Thread.sleep(100);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
mst.startGame();
try {
Thread.sleep(100);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
host.sendChatterMessage("[time_prefix] <name_prefix> >finish");
dcSent = true;
try {
Thread.sleep(2000);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
host = null;
client = null;
mst = null;
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
@Test
public void sendSpeedAsHostValid () {
try {
Thread.sleep(1000);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
new GameState("localhost");
mst = new MainServerThread();
host = null;
try {
host = new ClientToServerThread("localhost", 4942);
} catch (IOException ioe) {
ioe.printStackTrace();
}
try {
Thread.sleep(100);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
mst.startGame();
host.sendChatterMessage("[time_prefix] <name_prefix> >speed 5.0");
try {
Thread.sleep(100);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
Assert.assertEquals(5.0, GameState.getSpeedMultiplier(), 0.00001);
mst.terminate();
try {
Thread.sleep(2000);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
host = null;
client = null;
mst = null;
}
@Test
public void sendSpeedAsHostInvalid () {
try {
Thread.sleep(1000);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
new GameState("localhost");
mst = new MainServerThread();
host = null;
try {
host = new ClientToServerThread("localhost", 4942);
} catch (IOException ioe) {
ioe.printStackTrace();
}
try {
Thread.sleep(100);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
mst.startGame();
host.sendChatterMessage("[time_prefix] <name_prefix> >speed fdgdgdfg");
try {
Thread.sleep(100);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
mst.terminate();
Assert.assertEquals(1.0, GameState.getSpeedMultiplier(), 0.00001);
try {
Thread.sleep(2000);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
}
@Test
public void sendCommandAsClient () {
try {
Thread.sleep(1000);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
mst = new MainServerThread();
try {
host = new ClientToServerThread("localhost", 4942);
try {
Thread.sleep(100);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
client = new ClientToServerThread("localhost", 4942);
} catch (IOException ioe) {
ioe.printStackTrace();
}
try {
Thread.sleep(100);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
mst.startGame();
try {
Thread.sleep(200);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
client.sendChatterMessage("[time_prefix] <name_prefix> >speed 5.0");
try {
Thread.sleep(200);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
Assert.assertEquals(1.0, GameState.getSpeedMultiplier(), 0.00001);
mst.terminate();
host.setSocketToClose();
client.setSocketToClose();
try {
Thread.sleep(2000);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
}
@Test
public void receiveFinishedAsClient () {
try {
Thread.sleep(1000);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
new GameState("localhost");
dcSent = false;
mst = new MainServerThread();
host = null;
try {
host = new ClientToServerThread("localhost", 4942);
try {
Thread.sleep(100);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
client = new ClientToServerThread("localhost", 4942);
try {
Thread.sleep(100);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
client.addStreamObserver(() -> {
while (client.getPacketQueue().peek() != null) {
StreamPacket packet = client.getPacketQueue().poll();
switch (packet.getType()) {
case RACE_STATUS:
RaceStatusData rsd = StreamParser.extractRaceStatus(packet);
if (rsd.getBoatData().get(0)[4] == BoatStatus.FINISHED.getCode()) {
mst.terminate();
Assert.assertTrue(dcSent);
}
break;
default:
break;
}
}
});
} catch (IOException ioe) {
ioe.printStackTrace();
}
host.sendChatterMessage("[time_prefix] <name_prefix> >finish");
dcSent = true;
}
}
+12 -8
View File
@@ -2,7 +2,10 @@ package seng302.models;
import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javafx.util.Pair;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -21,6 +24,7 @@ public class YachtTest {
@BeforeClass
public static void setUp() {
new GameState("localhost");
y1 = new ServerYacht("Yacht", 1, "Y1", "Y1", "Yacht 1", "C1");
gs = new GameState("localhost");
}
@@ -52,7 +56,7 @@ public class YachtTest {
Double upwind = PolarTable.getOptimalUpwindVMG(windSpeed).keySet().iterator().next();
Double downwind = PolarTable.getOptimalDownwindVMG(windSpeed).keySet().iterator().next();
HashMap<Double, Double> values = new HashMap<>();
List<Pair<Double, Double>> values = new ArrayList<>();
upwind = (double) Math.floorMod(upwind.longValue() + windDirection.longValue(), 360L);
Double upwindRight = upwind;
@@ -61,19 +65,19 @@ public class YachtTest {
Double downwindRight = downwind;
Double downwindLeft = 360 - downwindRight;
values.put(190d, upwindRight);
values.put(170d, upwindLeft);
values.put(10d, downwindLeft);
values.put(350d, downwindRight);
values.add(new Pair<>(190d, upwindRight));
values.add(new Pair<>(170d, upwindLeft));
values.add(new Pair<>(10d, downwindLeft));
values.add(new Pair<>(350d, downwindRight));
for (Double begin : values.keySet()) {
y1.setHeading(begin);
for (Pair<Double, Double> beginEndPair : values) {
y1.setHeading(beginEndPair.getKey());
y1.turnToVMG();
for (int i = 0; i < 200; i++) {
y1.runAutoPilot();
}
y1.disableAutoPilot();
assertEquals(values.get(begin), y1.getHeading(), 5.0);
assertEquals(beginEndPair.getValue(), y1.getHeading(), 5.0);
}
}