mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Merged with remote changes
This commit is contained in:
@@ -44,12 +44,12 @@ public class HeartbeatThread implements Runnable {
|
||||
* The delegate is notified if a player has disconnected
|
||||
*/
|
||||
private void sendHeartbeatToAllPlayers(){
|
||||
try {
|
||||
Message heartbeat = new Heartbeat(seqNum);
|
||||
for (Player player : GameState.getPlayers()) {
|
||||
if (!player.getSocket().isConnected()) {
|
||||
playerLostConnection(player);
|
||||
}
|
||||
|
||||
try {
|
||||
player.getSocket().getOutputStream().write(heartbeat.getBuffer());
|
||||
} catch (IOException e) {
|
||||
@@ -58,6 +58,9 @@ public class HeartbeatThread implements Runnable {
|
||||
}
|
||||
updateDelegate();
|
||||
seqNum++;
|
||||
} catch (NullPointerException ne) {
|
||||
// TODO: 4/09/17 Just ignoring this at the moment. Caused by players getting removed elsewhere.
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -234,7 +234,6 @@ public class GameClient {
|
||||
|
||||
private void parsePackets() {
|
||||
while (socketThread.getPacketQueue().peek() != null) {
|
||||
System.out.println("PARSING PACKET");
|
||||
StreamPacket packet = socketThread.getPacketQueue().poll();
|
||||
switch (packet.getType()) {
|
||||
case RACE_STATUS:
|
||||
@@ -298,8 +297,6 @@ public class GameClient {
|
||||
case CHATTER_TEXT:
|
||||
Pair<Integer, String> playerIdMessagePair = StreamParser
|
||||
.extractChatterText(packet);
|
||||
|
||||
System.out.println("playerIdMessagePair = " + playerIdMessagePair);
|
||||
raceView.updateChatHistory(
|
||||
allBoatsMap.get(playerIdMessagePair.getKey()).getColour(),
|
||||
playerIdMessagePair.getValue()
|
||||
|
||||
@@ -574,7 +574,6 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
yachtSelectionComboBox.setItems(
|
||||
FXCollections.observableArrayList(participants.values())
|
||||
);
|
||||
//Null check is if the listener is fired but nothing selected
|
||||
yachtSelectionComboBox.valueProperty().addListener((obs, lastSelection, selectedBoat) -> {
|
||||
if (selectedBoat != null) {
|
||||
gameView.selectBoat(selectedBoat);
|
||||
@@ -677,7 +676,6 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
||||
}
|
||||
|
||||
public void updateChatHistory(Paint playerColour, String newMessage) {
|
||||
// Platform.runLater(() -> chatHistory.appendText(newMessage + "\n\n"));
|
||||
Platform.runLater(() -> chatHistory.addMessage(playerColour, newMessage));
|
||||
}
|
||||
|
||||
|
||||
@@ -24,9 +24,18 @@ public class ChatHistory extends ScrollPane {
|
||||
this.setMaxWidth(Double.MAX_VALUE);
|
||||
this.setVbarPolicy(ScrollBarPolicy.ALWAYS);
|
||||
this.setHbarPolicy(ScrollBarPolicy.NEVER);
|
||||
textFlow.getChildren().addListener((ListChangeListener<Node>) c -> {
|
||||
this.setVvalue(1.0);
|
||||
});
|
||||
//This makes the window auto scroll.
|
||||
textFlow.getChildren().addListener((ListChangeListener<Node>) c ->
|
||||
this.setVvalue(1.0)
|
||||
);
|
||||
//This just makes it so that the ChatHistory is on focus it passes it off to the parent.
|
||||
this.parentProperty().addListener((obs, old, parent) ->
|
||||
this.focusedProperty().addListener((obsVal, oldVal, onFocus) -> {
|
||||
if (onFocus) {
|
||||
parent.requestFocus();
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,4 +2,4 @@ Feature: SendChat
|
||||
Scenario: User send chat to another client
|
||||
Given The are two games running
|
||||
When the user has pressed sends the message "Hello world" in a text box
|
||||
Then the other client should recieve the message "Hello world"
|
||||
Then the other client should receive the message "Hello world"
|
||||
|
||||
@@ -26,6 +26,11 @@ public class ChatCommandsTest {
|
||||
|
||||
@Test
|
||||
public void sendFinishAsHost () {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException ie) {
|
||||
ie.printStackTrace();
|
||||
}
|
||||
try {
|
||||
dcSent = false;
|
||||
new GameState("localhost");
|
||||
@@ -39,6 +44,7 @@ public class ChatCommandsTest {
|
||||
RaceStatusData rsd = StreamParser.extractRaceStatus(packet);
|
||||
if (rsd.getBoatData().get(0)[4] == BoatStatus.FINISHED.getCode()) {
|
||||
mst.terminate();
|
||||
System.out.println("AY WE DID IT");
|
||||
// host.setSocketToClose();
|
||||
Assert.assertTrue(dcSent);
|
||||
}
|
||||
@@ -76,6 +82,11 @@ public class ChatCommandsTest {
|
||||
|
||||
@Test
|
||||
public void sendSpeedAsHostValid () {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException ie) {
|
||||
ie.printStackTrace();
|
||||
}
|
||||
new GameState("localhost");
|
||||
mst = new MainServerThread();
|
||||
host = null;
|
||||
@@ -97,6 +108,7 @@ public class ChatCommandsTest {
|
||||
ie.printStackTrace();
|
||||
}
|
||||
Assert.assertEquals(5.0, GameState.getSpeedMultiplier(), 0.00001);
|
||||
System.out.println("the thing " + GameState.getSpeedMultiplier());
|
||||
mst.terminate();
|
||||
// host.setSocketToClose();
|
||||
try {
|
||||
@@ -111,6 +123,11 @@ public class ChatCommandsTest {
|
||||
|
||||
@Test
|
||||
public void sendSpeedAsHostInvalid () {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException ie) {
|
||||
ie.printStackTrace();
|
||||
}
|
||||
new GameState("localhost");
|
||||
mst = new MainServerThread();
|
||||
host = null;
|
||||
@@ -134,6 +151,7 @@ public class ChatCommandsTest {
|
||||
mst.terminate();
|
||||
// host.setSocketToClose();
|
||||
Assert.assertEquals(1.0, GameState.getSpeedMultiplier(), 0.00001);
|
||||
System.out.println("value " + GameState.getSpeedMultiplier());
|
||||
try {
|
||||
Thread.sleep(2000);
|
||||
} catch (InterruptedException ie) {
|
||||
@@ -143,10 +161,12 @@ public class ChatCommandsTest {
|
||||
|
||||
@Test
|
||||
public void sendCommandAsClient () {
|
||||
new GameState("localhost");
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException ie) {
|
||||
ie.printStackTrace();
|
||||
}
|
||||
mst = new MainServerThread();
|
||||
host = null;
|
||||
client = null;
|
||||
try {
|
||||
host = new ClientToServerThread("localhost", 4942);
|
||||
try {
|
||||
@@ -189,13 +209,28 @@ public class ChatCommandsTest {
|
||||
|
||||
@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();
|
||||
@@ -204,6 +239,7 @@ public class ChatCommandsTest {
|
||||
RaceStatusData rsd = StreamParser.extractRaceStatus(packet);
|
||||
if (rsd.getBoatData().get(0)[4] == BoatStatus.FINISHED.getCode()) {
|
||||
mst.terminate();
|
||||
System.out.println("TEST COMPLETE");
|
||||
// client.setSocketToClose();
|
||||
// host.setSocketToClose();
|
||||
Assert.assertTrue(dcSent);
|
||||
@@ -217,25 +253,26 @@ public class ChatCommandsTest {
|
||||
} catch (IOException ioe) {
|
||||
ioe.printStackTrace();
|
||||
}
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException ie) {
|
||||
ie.printStackTrace();
|
||||
}
|
||||
mst.startGame();
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException ie) {
|
||||
ie.printStackTrace();
|
||||
}
|
||||
// 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(200);
|
||||
} catch (InterruptedException ie) {
|
||||
ie.printStackTrace();
|
||||
}
|
||||
// host.setSocketToClose();
|
||||
// try {
|
||||
// Thread.sleep(200);
|
||||
// } catch (InterruptedException ie) {
|
||||
// ie.printStackTrace();
|
||||
// }
|
||||
//// host.setSocketToClose();
|
||||
// mst.terminate();
|
||||
try {
|
||||
Thread.sleep(2000);
|
||||
} catch (InterruptedException ie) {
|
||||
|
||||
@@ -1,22 +1,10 @@
|
||||
package steps;
|
||||
|
||||
import cucumber.api.PendingException;
|
||||
import cucumber.api.java.en.Given;
|
||||
import cucumber.api.java.en.Then;
|
||||
import cucumber.api.java.en.When;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javafx.scene.layout.Pane;
|
||||
import org.junit.Assert;
|
||||
import org.mockito.Mock;
|
||||
import seng302.gameServer.GameStages;
|
||||
import seng302.gameServer.GameState;
|
||||
import seng302.gameServer.MainServerThread;
|
||||
import seng302.gameServer.messages.BoatAction;
|
||||
import seng302.model.ServerYacht;
|
||||
import seng302.visualiser.ClientToServerThread;
|
||||
import seng302.visualiser.GameClient;
|
||||
import seng302.visualiser.controllers.StartScreenController;
|
||||
|
||||
/**
|
||||
* Created by kre39 on 7/08/17.
|
||||
@@ -44,7 +32,7 @@ public class SendChatSteps {
|
||||
// client1.getSocketThread().sendChatterMessage(arg1);
|
||||
}
|
||||
|
||||
@Then("^the other client should recieve the message \"([^\"]*)\"$")
|
||||
@Then("^the other client should receive the message \"([^\"]*)\"$")
|
||||
public void the_other_client_should_recieve_the_message(String arg1) throws Throwable {
|
||||
// System.out.println(client2.getPacketQueue());
|
||||
// client2.setSocketToClose();
|
||||
|
||||
Reference in New Issue
Block a user