mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Action packets now sent at regular 20ms intervals
#issue[38] #implement
This commit is contained in:
@@ -69,6 +69,21 @@
|
||||
<artifactId>commons-cli</artifactId>
|
||||
<version>1.4</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.testfx/testfx-core -->
|
||||
<dependency>
|
||||
<groupId>org.testfx</groupId>
|
||||
<artifactId>testfx-core</artifactId>
|
||||
<version>4.0.1-alpha</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.testfx/testfx-junit -->
|
||||
<dependency>
|
||||
<groupId>org.testfx</groupId>
|
||||
<artifactId>testfx-junit</artifactId>
|
||||
<version>4.0.6-alpha</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
||||
@@ -13,7 +13,8 @@ public enum BoatActionType {
|
||||
SAILS_OUT(3),
|
||||
TACK_GYBE(4),
|
||||
UPWIND(5),
|
||||
DOWNWIND(6);
|
||||
DOWNWIND(6),
|
||||
MAINTAIN_HEADING(7);
|
||||
|
||||
private final int type;
|
||||
private static final Map<Integer, BoatActionType> intToTypeMap = new HashMap<>();
|
||||
|
||||
@@ -48,7 +48,7 @@ public class Yacht {
|
||||
private Integer legNumber = 0;
|
||||
|
||||
//SERVER SIDE
|
||||
private final Double TURN_STEP = 5.0;
|
||||
static public final Double TURN_STEP = 1.0; //This should be in some utils class somewhere 2bh. Public for tests sake.
|
||||
private Double lastHeading;
|
||||
private Boolean sailIn;
|
||||
private GeoPoint location;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package seng302.visualiser.map;
|
||||
package seng302.v.map;
|
||||
|
||||
/**
|
||||
* The Boundary class represents a rectangle territorial boundary on a map. It
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package seng302.visualiser.map;
|
||||
package seng302.v.map;
|
||||
|
||||
import java.net.URL;
|
||||
import javafx.geometry.Point2D;
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
package seng302.visualiser.map;
|
||||
package seng302.v.map;
|
||||
|
||||
import javafx.geometry.Point2D;
|
||||
import seng302.model.GeoPoint;
|
||||
@@ -28,7 +28,7 @@ public class MercatorProjection {
|
||||
* @param geo GeoPoint (lat, lng) location to be projected
|
||||
* @return the projection Point2D (x, y) on planar
|
||||
*/
|
||||
static Point2D toMapPoint(GeoPoint geo) {
|
||||
public static Point2D toMapPoint(GeoPoint geo) {
|
||||
double x, y;
|
||||
Point2D origin = new Point2D(MERCATOR_RANGE / 2.0, MERCATOR_RANGE / 2.0);
|
||||
x = (origin.getX() + geo.getLng() * pixelsPerLngDegree);
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package seng302.visualiser.map;
|
||||
package seng302.v.map;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
@@ -9,12 +9,15 @@ import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.zip.CRC32;
|
||||
import java.util.zip.Checksum;
|
||||
import javafx.application.Platform;
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.control.Alert.AlertType;
|
||||
import seng302.gameServer.server.messages.BoatActionType;
|
||||
import seng302.model.stream.packets.StreamPacket;
|
||||
import seng302.gameServer.server.messages.BoatActionMessage;
|
||||
import seng302.gameServer.server.messages.Message;
|
||||
@@ -47,11 +50,15 @@ public class ClientToServerThread implements Runnable {
|
||||
|
||||
private Socket socket;
|
||||
private InputStream is;
|
||||
|
||||
//Output stream
|
||||
private OutputStream os;
|
||||
private Timer osTimer = new Timer();
|
||||
private Queue<BoatActionType> eventQueue = new ConcurrentLinkedQueue<>();
|
||||
private boolean upwindFlag = false, downwindFlag = false;
|
||||
static public final int PACKET_SENDING_INTERVAL_MS = 20;
|
||||
|
||||
private int clientId;
|
||||
|
||||
// private Boolean updateClient = true;
|
||||
private ByteArrayOutputStream crcBuffer;
|
||||
private boolean socketOpen = true;
|
||||
|
||||
@@ -83,6 +90,15 @@ public class ClientToServerThread implements Runnable {
|
||||
|
||||
thread = new Thread(this);
|
||||
thread.start();
|
||||
|
||||
osTimer.scheduleAtFixedRate(
|
||||
new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
processBoatActionQueue();
|
||||
}
|
||||
}, 0, PACKET_SENDING_INTERVAL_MS
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -181,18 +197,42 @@ public class ClientToServerThread implements Runnable {
|
||||
|
||||
|
||||
/**
|
||||
* Send the post-start race course information
|
||||
* @param boatActionMessage The message to send
|
||||
* Processes next element in the queue of events to send.
|
||||
*/
|
||||
public void sendBoatActionMessage(BoatActionMessage boatActionMessage) {
|
||||
private void processBoatActionQueue() {
|
||||
BoatActionType action = eventQueue.poll();
|
||||
if (action != null) {
|
||||
switch (action) {
|
||||
case MAINTAIN_HEADING:
|
||||
downwindFlag = upwindFlag = false; break;
|
||||
case DOWNWIND:
|
||||
downwindFlag = true; break;
|
||||
case UPWIND:
|
||||
upwindFlag = true; break;
|
||||
default:
|
||||
sendBoatAction(new BoatActionMessage(action)); break;
|
||||
}
|
||||
}
|
||||
if (downwindFlag) {
|
||||
sendBoatAction(new BoatActionMessage(BoatActionType.DOWNWIND));
|
||||
}
|
||||
if (upwindFlag) {
|
||||
sendBoatAction(new BoatActionMessage(BoatActionType.UPWIND));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a boat action of the given message type.
|
||||
* @param message The given message type.
|
||||
*/
|
||||
private void sendBoatAction(BoatActionMessage message) {
|
||||
try {
|
||||
os.write(boatActionMessage.getBuffer());
|
||||
os.write(message.getBuffer());
|
||||
} catch (IOException e) {
|
||||
clientLog("Could not write to server", 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void closeSocket() {
|
||||
try {
|
||||
socket.close();
|
||||
@@ -245,11 +285,11 @@ public class ClientToServerThread implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
public Thread getThread() {
|
||||
return thread;
|
||||
}
|
||||
|
||||
public int getClientId () {
|
||||
return clientId;
|
||||
}
|
||||
|
||||
public void sendBoatEvent(BoatActionType actionType) {
|
||||
eventQueue.add(actionType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import javafx.scene.Node;
|
||||
import javafx.scene.input.KeyEvent;
|
||||
import javafx.scene.layout.Pane;
|
||||
import seng302.gameServer.MainServerThread;
|
||||
import seng302.gameServer.server.messages.BoatActionType;
|
||||
import seng302.model.RaceState;
|
||||
import seng302.model.Yacht;
|
||||
import seng302.model.stream.packets.StreamPacket;
|
||||
@@ -22,8 +23,6 @@ import seng302.model.stream.parser.PositionUpdateData.DeviceType;
|
||||
import seng302.model.stream.parser.RaceStatusData;
|
||||
import seng302.model.stream.xml.parser.RaceXMLData;
|
||||
import seng302.model.stream.xml.parser.RegattaXMLData;
|
||||
import seng302.gameServer.server.messages.BoatActionMessage;
|
||||
import seng302.gameServer.server.messages.BoatActionType;
|
||||
import seng302.utilities.StreamParser;
|
||||
import seng302.utilities.XMLParser;
|
||||
import seng302.visualiser.controllers.LobbyController;
|
||||
@@ -48,9 +47,6 @@ public class GameClient {
|
||||
|
||||
private ObservableList<String> clientLobbyList = FXCollections.observableArrayList();
|
||||
|
||||
private long lastSendingTime;
|
||||
private int KEY_STROKE_SENDING_FREQUENCY = 50;
|
||||
|
||||
public GameClient(Pane holder) {
|
||||
this.holderPane = holder;
|
||||
}
|
||||
@@ -174,17 +170,13 @@ public class GameClient {
|
||||
break;
|
||||
|
||||
case BOAT_XML:
|
||||
System.out.println("GOT SUM BOATS YAY :)");
|
||||
allBoatsMap = XMLParser.parseBoats(
|
||||
StreamParser.extractXmlMessage(packet)
|
||||
);
|
||||
clientLobbyList.clear();
|
||||
allBoatsMap.forEach((id, boat) -> {
|
||||
clientLobbyList.add(id + " " + boat.getBoatName());
|
||||
// System.out.println(id + " " + boat.getBoatName());
|
||||
|
||||
});
|
||||
// startRaceIfAllDataReceived();
|
||||
break;
|
||||
|
||||
case RACE_START_STATUS:
|
||||
@@ -279,47 +271,34 @@ public class GameClient {
|
||||
* Handle the key-pressed event from the text field.
|
||||
* @param e The key event triggering this call
|
||||
*/
|
||||
public void keyPressed(KeyEvent e) {
|
||||
BoatActionMessage boatActionMessage;
|
||||
long currentTime = System.currentTimeMillis();
|
||||
if (currentTime - lastSendingTime > KEY_STROKE_SENDING_FREQUENCY) {
|
||||
lastSendingTime = currentTime;
|
||||
switch (e.getCode()) {
|
||||
case SPACE: // align with vmg
|
||||
boatActionMessage = new BoatActionMessage(BoatActionType.VMG);
|
||||
socketThread.sendBoatActionMessage(boatActionMessage);
|
||||
break;
|
||||
case PAGE_UP: // upwind
|
||||
boatActionMessage = new BoatActionMessage(BoatActionType.UPWIND);
|
||||
socketThread.sendBoatActionMessage(boatActionMessage);
|
||||
break;
|
||||
case PAGE_DOWN: // downwind
|
||||
boatActionMessage = new BoatActionMessage(BoatActionType.DOWNWIND);
|
||||
socketThread.sendBoatActionMessage(boatActionMessage);
|
||||
break;
|
||||
case ENTER: // tack/gybe
|
||||
boatActionMessage = new BoatActionMessage(BoatActionType.TACK_GYBE);
|
||||
socketThread.sendBoatActionMessage(boatActionMessage);
|
||||
break;
|
||||
//TODO Allow a zoom in and zoom out methods
|
||||
case Z: // zoom in
|
||||
System.out.println("Zoom in");
|
||||
break;
|
||||
case X: // zoom out
|
||||
System.out.println("Zoom out");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void keyReleased(KeyEvent e) {
|
||||
private void keyPressed(KeyEvent e) {
|
||||
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)
|
||||
case SHIFT: // sails in/sails out
|
||||
BoatActionMessage boatActionMessage = new BoatActionMessage(
|
||||
BoatActionType.SAILS_IN);
|
||||
socketThread.sendBoatActionMessage(boatActionMessage);
|
||||
case SPACE: // align with vmg
|
||||
socketThread.sendBoatEvent(BoatActionType.VMG); break;
|
||||
case PAGE_UP: // upwind
|
||||
socketThread.sendBoatEvent(BoatActionType.UPWIND); break;
|
||||
case PAGE_DOWN: // downwind
|
||||
socketThread.sendBoatEvent(BoatActionType.DOWNWIND); break;
|
||||
case ENTER: // tack/gybe
|
||||
socketThread.sendBoatEvent(BoatActionType.TACK_GYBE); break;
|
||||
//TODO Allow a zoom in and zoom out methods
|
||||
case Z: // zoom in
|
||||
System.out.println("Zoom in");
|
||||
break;
|
||||
case X: // zoom out
|
||||
System.out.println("Zoom out");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void keyReleased(KeyEvent e) {
|
||||
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)
|
||||
case SHIFT: // sails in/sails out
|
||||
socketThread.sendBoatEvent(BoatActionType.SAILS_IN); break;
|
||||
case PAGE_UP:
|
||||
case PAGE_DOWN:
|
||||
socketThread.sendBoatEvent(BoatActionType.MAINTAIN_HEADING); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,8 +32,8 @@ import seng302.visualiser.fxObjects.BoatObject;
|
||||
import seng302.visualiser.fxObjects.CourseBoundary;
|
||||
import seng302.visualiser.fxObjects.Gate;
|
||||
import seng302.visualiser.fxObjects.Marker;
|
||||
import seng302.visualiser.map.Boundary;
|
||||
import seng302.visualiser.map.CanvasMap;
|
||||
import seng302.v.map.Boundary;
|
||||
import seng302.v.map.CanvasMap;
|
||||
|
||||
/**
|
||||
* Created by cir27 on 20/07/17.
|
||||
|
||||
@@ -4,15 +4,13 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javafx.application.Platform;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ListChangeListener;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.ListView;
|
||||
import javafx.scene.control.TextArea;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.text.Text;
|
||||
import seng302.gameServer.GameStages;
|
||||
import seng302.gameServer.GameState;
|
||||
@@ -33,28 +31,26 @@ public class LobbyController {
|
||||
void notify(CloseStatus exitCause);
|
||||
}
|
||||
|
||||
@FXML
|
||||
private GridPane lobbyScreen;
|
||||
@FXML
|
||||
private Text lobbyIpText;
|
||||
@FXML
|
||||
private Button readyButton;
|
||||
@FXML
|
||||
private ListView<String> firstListView;
|
||||
private TextArea playerOneTxt;
|
||||
@FXML
|
||||
private ListView secondListView;
|
||||
private TextArea playerTwoTxt;
|
||||
@FXML
|
||||
private ListView thirdListView;
|
||||
private TextArea playerThreeTxt;
|
||||
@FXML
|
||||
private ListView fourthListView;
|
||||
private TextArea playerFourTxt;
|
||||
@FXML
|
||||
private ListView fifthListView;
|
||||
private TextArea playerFiveTxt;
|
||||
@FXML
|
||||
private ListView sixthListView;
|
||||
private TextArea playerSixTxt;
|
||||
@FXML
|
||||
private ListView seventhListView;
|
||||
private TextArea playerSevenTxt;
|
||||
@FXML
|
||||
private ListView eighthListView;
|
||||
private TextArea playerEightTxt;
|
||||
@FXML
|
||||
private ImageView firstImageView;
|
||||
@FXML
|
||||
@@ -72,79 +68,67 @@ public class LobbyController {
|
||||
@FXML
|
||||
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<ListView> listViews;
|
||||
private List<TextArea> listViews = new ArrayList<>();
|
||||
|
||||
private int MAX_NUM_PLAYERS = 8;
|
||||
|
||||
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() {
|
||||
imageViews = new ArrayList<>();
|
||||
Collections
|
||||
.addAll(imageViews, firstImageView, secondImageView, thirdImageView, fourthImageView,
|
||||
fifthImageView, sixthImageView, seventhImageView, eighthImageView);
|
||||
listViews = new ArrayList<>();
|
||||
Collections.addAll(listViews, firstListView, secondListView, thirdListView, fourthListView, fifthListView,
|
||||
sixthListView, seventhListView, eighthListView);
|
||||
competitors = new ArrayList<>();
|
||||
Collections.addAll(competitors, firstCompetitor, secondCompetitor, thirdCompetitor,
|
||||
fourthCompetitor, fifthCompetitor, sixthCompetitor, seventhCompetitor, eighthCompetitor);
|
||||
|
||||
Collections.addAll(listViews,
|
||||
playerOneTxt, playerTwoTxt, playerThreeTxt, playerFourTxt, playerFiveTxt, playerSixTxt,
|
||||
playerSevenTxt, playerEightTxt
|
||||
);
|
||||
Collections.addAll(imageViews,
|
||||
firstImageView, secondImageView, thirdImageView, fourthImageView,
|
||||
fifthImageView, sixthImageView, seventhImageView, eighthImageView
|
||||
);
|
||||
initialiseImageView();
|
||||
}
|
||||
|
||||
private void initialiseListView() {
|
||||
listViews.forEach(listView -> listView.getItems().clear());
|
||||
imageViews.forEach(gif -> gif.setVisible(false));
|
||||
competitors.forEach(ol -> ol.removeAll());
|
||||
/**
|
||||
* Updates player names.
|
||||
*/
|
||||
private void updatePlayers() {
|
||||
//Update players if one added.
|
||||
for (int i = 0; i < players.size(); i++) {
|
||||
competitors.get(i).add(players.get(i));
|
||||
listViews.get(i).setItems(competitors.get(i));
|
||||
listViews.get(i).setText(players.get(i));
|
||||
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() {
|
||||
imageViews.add(firstImageView);
|
||||
imageViews.add(secondImageView);
|
||||
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(
|
||||
for (ImageView viewer : imageViews) {
|
||||
viewer.setImage(
|
||||
new Image(
|
||||
RaceViewController.class.getResourceAsStream(
|
||||
"/pics/sail.png")
|
||||
)
|
||||
);
|
||||
viewer.setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void leaveLobbyButtonPressed() {
|
||||
// TODO: 10/07/17 wmu16 - Finish function!
|
||||
// setContentPane("/views/StartScreenView.fxml");
|
||||
GameState.setCurrentStage(GameStages.CANCELLED);
|
||||
// TODO: 20/07/17 wmu16 - Implement some way of terminating the game
|
||||
// ClientState.setConnectedToHost(false);
|
||||
for (LobbyCloseListener readyListener : lobbyListeners)
|
||||
readyListener.notify(CloseStatus.LEAVE);
|
||||
|
||||
}
|
||||
|
||||
@FXML
|
||||
@@ -154,32 +138,6 @@ public class LobbyController {
|
||||
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) {
|
||||
lobbyIpText.setText(title);
|
||||
}
|
||||
@@ -191,12 +149,13 @@ public class LobbyController {
|
||||
public void setPlayerListSource (ObservableList<String> players) {
|
||||
this.players = players;
|
||||
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 () {
|
||||
readyButton.setDisable(true);
|
||||
readyButton.setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
<?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.scene.control.Button?>
|
||||
<?import javafx.scene.control.ListView?>
|
||||
@@ -11,6 +16,7 @@
|
||||
<?import javafx.scene.layout.RowConstraints?>
|
||||
<?import javafx.scene.text.Font?>
|
||||
<?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">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
|
||||
@@ -53,41 +59,14 @@
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<ListView fx:id="firstListView" prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1">
|
||||
<GridPane.margin>
|
||||
<Insets bottom="10.0" left="40.0" right="40.0" top="10.0" />
|
||||
</GridPane.margin>
|
||||
</ListView>
|
||||
<ListView fx:id="secondListView" prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="2">
|
||||
<GridPane.margin>
|
||||
<Insets bottom="10.0" left="40.0" right="40.0" top="10.0" />
|
||||
</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>
|
||||
<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" />
|
||||
<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" />
|
||||
<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" />
|
||||
<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" />
|
||||
<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" />
|
||||
<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" />
|
||||
<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" />
|
||||
<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" />
|
||||
<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>
|
||||
<Insets bottom="10.0" />
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
<?import javafx.scene.canvas.Canvas?>
|
||||
<?import javafx.scene.layout.Pane?>
|
||||
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="960.0" prefWidth="1280.0" style="-fx-background-color: #ddd;" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.visualiser.map.TestMapController">
|
||||
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="960.0" prefWidth="1280.0" style="-fx-background-color: #ddd;" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.v.map.TestMapController">
|
||||
<children>
|
||||
<Canvas fx:id="mapCanvas" height="960.0" width="1280.0" />
|
||||
</children>
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
package seng302.visualiser.ClientToServerTests;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import javafx.application.Platform;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import javafx.scene.input.KeyEvent;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.stage.Stage;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Test;
|
||||
import org.junit.runners.MethodSorters;
|
||||
import org.testfx.api.FxToolkit;
|
||||
import seng302.gameServer.GameStages;
|
||||
import seng302.gameServer.GameState;
|
||||
import seng302.gameServer.MainServerThread;
|
||||
import seng302.model.Yacht;
|
||||
import seng302.visualiser.ClientToServerThread;
|
||||
import seng302.visualiser.GameClient;
|
||||
|
||||
/**
|
||||
* Test for checking how regularly packets are sent from ClientToServer Thread.
|
||||
*/
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
public class RegularPacketsTest {
|
||||
|
||||
private MainServerThread serverThread;
|
||||
private GameClient gameClient;
|
||||
private Pane pane;
|
||||
private Scene scene;
|
||||
private Stage stage;
|
||||
|
||||
// @BeforeClass
|
||||
// public static void preSetup() throws Exception {
|
||||
// FxToolkit toolkit = FxToolkit.registerPrimaryStage();
|
||||
// }
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
stage = FxToolkit.registerPrimaryStage();
|
||||
Platform.runLater(() -> {
|
||||
pane = new Pane();
|
||||
scene = new Scene(pane);
|
||||
stage.setScene(scene);
|
||||
});
|
||||
while (stage != null && pane != null && scene != null && stage.getScene() != null);
|
||||
gameClient = new GameClient(pane);
|
||||
gameClient.runAsHost("localhost", 4942);
|
||||
Field server = gameClient.getClass().getDeclaredField("server");
|
||||
server.setAccessible(true);
|
||||
serverThread = (MainServerThread) server.get(gameClient);
|
||||
GameState.setCurrentStage(GameStages.RACING);
|
||||
serverThread.startGame();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void Test1PacketsSentAtRegularIntervals () throws Exception {
|
||||
Yacht yacht = GameState.getYachts().get(0);
|
||||
double startAngle = yacht.getHeading();
|
||||
KeyEvent keyPress = new KeyEvent(null, scene,
|
||||
KeyEvent.KEY_PRESSED, "page_up", "page_up", KeyCode.PAGE_UP,
|
||||
false, false, false, false
|
||||
);
|
||||
KeyEvent keyRelease = new KeyEvent(null, scene,
|
||||
KeyEvent.KEY_RELEASED, "page_up", "page_up", KeyCode.PAGE_UP,
|
||||
false, false, false, false
|
||||
);
|
||||
long startTime = System.currentTimeMillis();
|
||||
pane.fireEvent(keyPress);
|
||||
while (yacht.getHeading() - startAngle > 100);
|
||||
pane.fireEvent(keyRelease);
|
||||
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(100 / Yacht.TURN_STEP * ClientToServerThread.PACKET_SENDING_INTERVAL_MS,
|
||||
endTime - startTime / (100 / Yacht.TURN_STEP), 2 * ClientToServerThread.PACKET_SENDING_INTERVAL_MS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void Test2ArbitraryPacketSentOnRelease() throws Exception {
|
||||
KeyEvent keyPress = new KeyEvent(null, scene,
|
||||
KeyEvent.KEY_PRESSED, "shift", "shift", KeyCode.SHIFT,
|
||||
false, false, false, false
|
||||
);
|
||||
KeyEvent keyRelease = new KeyEvent(null, scene,
|
||||
KeyEvent.KEY_RELEASED, "shift", "shift", KeyCode.SHIFT,
|
||||
false, false, false, false
|
||||
);
|
||||
Yacht yacht = GameState.getYachts().get(0);
|
||||
boolean startState = yacht.getSailIn();
|
||||
pane.fireEvent(keyPress);
|
||||
pane.fireEvent(keyRelease);
|
||||
SleepThreadMaxDelay();
|
||||
Assert.assertEquals(startState, !yacht.getSailIn());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void Test3ArbitraryPacketSentOnPress() throws Exception {
|
||||
KeyEvent keyPress = new KeyEvent(null, scene,
|
||||
KeyEvent.KEY_PRESSED, "space", "space", KeyCode.SPACE,
|
||||
false, false, false, false
|
||||
);
|
||||
Yacht yacht = GameState.getYachts().get(0);
|
||||
double heading = yacht.getHeading();
|
||||
double windDirection = GameState.getWindDirection();
|
||||
Yacht testYacht = new Yacht("", 0, "", "", "", "");
|
||||
testYacht.setHeading(heading);
|
||||
testYacht.tackGybe(windDirection);
|
||||
pane.fireEvent(keyPress);
|
||||
SleepThreadMaxDelay();
|
||||
Assert.assertEquals(testYacht.getHeading(), yacht.getHeading(), 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package seng302.visualizer.annotations;
|
||||
package seng302.visualiser.annotations;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@@ -4,6 +4,7 @@ import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import seng302.model.GeoPoint;
|
||||
import seng302.v.map.MercatorProjection;
|
||||
|
||||
/**
|
||||
* Unit test for Mercator Project class.
|
||||
|
||||
Reference in New Issue
Block a user