mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
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:
@@ -0,0 +1,5 @@
|
||||
Feature: SendChat
|
||||
Scenario: User send chat to another client
|
||||
Given There are two games running
|
||||
When the first client has sent the message "Hello world"
|
||||
Then the other client should receive the message "Hello world"
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package steps;
|
||||
|
||||
import cucumber.api.java.en.Given;
|
||||
import cucumber.api.java.en.Then;
|
||||
import cucumber.api.java.en.When;
|
||||
import javafx.util.Pair;
|
||||
import org.junit.Assert;
|
||||
import seng302.gameServer.MainServerThread;
|
||||
import seng302.model.stream.packets.StreamPacket;
|
||||
import seng302.utilities.StreamParser;
|
||||
import seng302.visualiser.ClientToServerThread;
|
||||
|
||||
/**
|
||||
* Cucumber test for sending chat messages
|
||||
* Created by kre39 on 7/08/17.
|
||||
*/
|
||||
public class SendChatSteps {
|
||||
|
||||
private ClientToServerThread client;
|
||||
private ClientToServerThread host;
|
||||
private MainServerThread mst;
|
||||
|
||||
|
||||
@Given("^There are two games running$")
|
||||
public void the_are_two_games_running() throws Throwable {
|
||||
mst = new MainServerThread();
|
||||
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();
|
||||
}
|
||||
mst.startGame();
|
||||
Thread.sleep(200);
|
||||
}
|
||||
|
||||
|
||||
@When("^the first client has sent the message \"([^\"]*)\"$")
|
||||
public void the_user_has_pressed_sends_the_message_in_a_text_box(String arg1) throws Throwable {
|
||||
client.sendChatterMessage("[time_prefix] <name_prefix> " + arg1);
|
||||
}
|
||||
|
||||
@Then("^the other client should receive the message \"([^\"]*)\"$")
|
||||
public void the_other_client_should_receive_the_message(String arg1) throws Throwable {
|
||||
Object[] packets = host.getPacketQueue().toArray();
|
||||
Pair<Integer, String> message = StreamParser.extractChatterText((StreamPacket) packets[packets.length - 1]);
|
||||
Assert.assertEquals("[time_prefix] <name_prefix> " + arg1, message.getValue());
|
||||
mst.terminate();
|
||||
host.setSocketToClose();
|
||||
client.setSocketToClose();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import seng302.model.ServerYacht;
|
||||
import seng302.visualiser.ClientToServerThread;
|
||||
|
||||
/**
|
||||
* Cucumber test for toggling sail
|
||||
* Created by kre39 on 7/08/17.
|
||||
*/
|
||||
public class ToggleSailSteps {
|
||||
@@ -49,5 +50,7 @@ public class ToggleSailSteps {
|
||||
} else {
|
||||
Assert.assertFalse(yacht.getSailIn());
|
||||
}
|
||||
mst.terminate();
|
||||
client.closeSocket();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user