mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Updated and added more documentations
#story[1047]
This commit is contained in:
@@ -5,7 +5,8 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import seng302.models.Yacht;
|
||||
|
||||
/**
|
||||
* Used by the client to store static variables to be used in game.
|
||||
* Used by the client to store static variables, which other threads and classes
|
||||
* observer so that they can update their status accordingly.
|
||||
*/
|
||||
public class ClientState {
|
||||
|
||||
|
||||
@@ -13,8 +13,10 @@ public class ClientStateQueryingRunnable extends Observable implements Runnable
|
||||
public ClientStateQueryingRunnable() {}
|
||||
|
||||
/**
|
||||
* Notifies observers "game started" if ClientState raceStarted flag is true and terminates itself.
|
||||
* Notifies observers "update players" if ClientState boatsUpdated flag is true and resets the flag to false;
|
||||
* Notifies observers(the lobby controller) that "game started" if ClientState
|
||||
* raceStarted flag is true and terminates itself. Also, it notifies observers
|
||||
* to add/remove players if ClientState boatsUpdated flag is true, then resets
|
||||
* the flag to false;
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
@@ -65,7 +65,7 @@ public class ClientToServerThread implements Runnable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints out log message and time happened.
|
||||
* Prints out log messages and the time happened.
|
||||
* Only perform task if log level is below LOG_LEVEL variable.
|
||||
*
|
||||
* @param message a string of message to be printed out
|
||||
@@ -78,7 +78,8 @@ public class ClientToServerThread implements Runnable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform the thread loop. Will exit loop if ClientState connected to host variable is false.
|
||||
* Perform the thread loop. It exits the loop if ClientState connected to host
|
||||
* variable is false.
|
||||
*/
|
||||
public void run() {
|
||||
int sync1;
|
||||
@@ -104,7 +105,6 @@ public class ClientToServerThread implements Runnable {
|
||||
if (computedCrc == packetCrc) {
|
||||
ClientPacketParser
|
||||
.parsePacket(new StreamPacket(type, payloadLength, timeStamp, payload));
|
||||
// TODO: 17/07/17 wmu16 - Fix this or maybe we dont need to go through the main server at all!?!?
|
||||
// packetBufferDelegate.addToBuffer(new StreamPacket(type, payloadLength, timeStamp, payload));
|
||||
} else {
|
||||
clientLog("Packet has been dropped", 1);
|
||||
@@ -122,7 +122,7 @@ public class ClientToServerThread implements Runnable {
|
||||
|
||||
|
||||
/**
|
||||
* Listens for an allocated sourceID and returns it to the server if received
|
||||
* Listens for an allocated sourceID and returns it to the server
|
||||
* @return the sourceID allocated to us by the server
|
||||
*/
|
||||
private Integer threeWayHandshake() {
|
||||
|
||||
@@ -74,7 +74,7 @@ public class CanvasController {
|
||||
|
||||
private List<MarkGroup> markGroups = new ArrayList<>();
|
||||
private List<BoatGroup> boatGroups = new ArrayList<>();
|
||||
private Text FPSdisplay = new Text();
|
||||
private Text FPSDisplay = new Text();
|
||||
private Polygon raceBorder = new Polygon();
|
||||
|
||||
//FRAME RATE
|
||||
@@ -119,10 +119,10 @@ public class CanvasController {
|
||||
gc.setGlobalAlpha(0.5);
|
||||
fitMarksToCanvas();
|
||||
drawGoogleMap();
|
||||
FPSdisplay.setLayoutX(5);
|
||||
FPSdisplay.setLayoutY(20);
|
||||
FPSdisplay.setStrokeWidth(2);
|
||||
group.getChildren().add(FPSdisplay);
|
||||
FPSDisplay.setLayoutX(5);
|
||||
FPSDisplay.setLayoutY(20);
|
||||
FPSDisplay.setStrokeWidth(2);
|
||||
group.getChildren().add(FPSDisplay);
|
||||
group.getChildren().add(raceBorder);
|
||||
initializeMarks();
|
||||
initializeBoats();
|
||||
@@ -391,10 +391,10 @@ public class CanvasController {
|
||||
|
||||
private void drawFps(int fps){
|
||||
if (raceViewController.isDisplayFps()){
|
||||
FPSdisplay.setVisible(true);
|
||||
FPSdisplay.setText(String.format("%d FPS", fps));
|
||||
FPSDisplay.setVisible(true);
|
||||
FPSDisplay.setText(String.format("%d FPS", fps));
|
||||
} else {
|
||||
FPSdisplay.setVisible(false);
|
||||
FPSDisplay.setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -112,6 +112,7 @@ public class LobbyController implements Initializable, Observer{
|
||||
readyButton.setDisable(true);
|
||||
}
|
||||
|
||||
// put all javafx objects in lists, so we can iterate though conveniently
|
||||
imageViews = new ArrayList<>();
|
||||
Collections.addAll(imageViews, firstImageView, secondImageView, thirdImageView, fourthImageView,
|
||||
fifthImageView, sixthImageView, seventhImageView, eighthImageView);
|
||||
@@ -134,6 +135,13 @@ public class LobbyController implements Initializable, Observer{
|
||||
clientStateQueryingThread.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Observers "ClientStateQueryingRunnable".
|
||||
* When the clients state has been marked to "race start", the querying thread
|
||||
* will notify this lobby to change the view
|
||||
* @param o
|
||||
* @param arg
|
||||
*/
|
||||
@Override
|
||||
public void update(Observable o, Object arg) {
|
||||
Platform.runLater(new Runnable() {
|
||||
@@ -149,6 +157,9 @@ public class LobbyController implements Initializable, Observer{
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset all ListViews and ImageViews according to the current competitors
|
||||
*/
|
||||
private void initialiseListView() {
|
||||
listViews.forEach(listView -> listView.getItems().clear());
|
||||
imageViews.forEach(gif -> gif.setVisible(false));
|
||||
@@ -162,6 +173,9 @@ public class LobbyController implements Initializable, Observer{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads preset images into imageViews
|
||||
*/
|
||||
private void initialiseImageView() {
|
||||
for (int i = 0; i < MAX_NUM_PLAYERS; i++) {
|
||||
imageViews.get(i).setImage(new Image(getClass().getResourceAsStream("/pics/sail.png")));
|
||||
@@ -195,14 +209,11 @@ public class LobbyController implements Initializable, Observer{
|
||||
|
||||
@FXML
|
||||
public void readyButtonPressed() {
|
||||
// setContentPane("/views/RaceView.fxml");
|
||||
GameState.setCurrentStage(GameStages.RACING);
|
||||
mainServerThread.startGame();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void switchToRaceView() {
|
||||
if (!switchedPane) {
|
||||
switchedPane = true;
|
||||
|
||||
Reference in New Issue
Block a user