Updated and added more documentations

#story[1047]
This commit is contained in:
Haoming Yin
2017-07-26 19:55:35 +12:00
parent af9f1417f1
commit ef6821a0cd
5 changed files with 32 additions and 18 deletions
@@ -5,7 +5,8 @@ import java.util.concurrent.ConcurrentHashMap;
import seng302.models.Yacht; 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 { public class ClientState {
@@ -13,8 +13,10 @@ public class ClientStateQueryingRunnable extends Observable implements Runnable
public ClientStateQueryingRunnable() {} public ClientStateQueryingRunnable() {}
/** /**
* Notifies observers "game started" if ClientState raceStarted flag is true and terminates itself. * Notifies observers(the lobby controller) that "game started" if ClientState
* Notifies observers "update players" if ClientState boatsUpdated flag is true and resets the flag to false; * 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 @Override
public void run() { 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. * Only perform task if log level is below LOG_LEVEL variable.
* *
* @param message a string of message to be printed out * @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() { public void run() {
int sync1; int sync1;
@@ -104,7 +105,6 @@ public class ClientToServerThread implements Runnable {
if (computedCrc == packetCrc) { if (computedCrc == packetCrc) {
ClientPacketParser ClientPacketParser
.parsePacket(new StreamPacket(type, payloadLength, timeStamp, payload)); .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)); // packetBufferDelegate.addToBuffer(new StreamPacket(type, payloadLength, timeStamp, payload));
} else { } else {
clientLog("Packet has been dropped", 1); 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 * @return the sourceID allocated to us by the server
*/ */
private Integer threeWayHandshake() { private Integer threeWayHandshake() {
@@ -74,7 +74,7 @@ public class CanvasController {
private List<MarkGroup> markGroups = new ArrayList<>(); private List<MarkGroup> markGroups = new ArrayList<>();
private List<BoatGroup> boatGroups = new ArrayList<>(); private List<BoatGroup> boatGroups = new ArrayList<>();
private Text FPSdisplay = new Text(); private Text FPSDisplay = new Text();
private Polygon raceBorder = new Polygon(); private Polygon raceBorder = new Polygon();
//FRAME RATE //FRAME RATE
@@ -119,10 +119,10 @@ public class CanvasController {
gc.setGlobalAlpha(0.5); gc.setGlobalAlpha(0.5);
fitMarksToCanvas(); fitMarksToCanvas();
drawGoogleMap(); drawGoogleMap();
FPSdisplay.setLayoutX(5); FPSDisplay.setLayoutX(5);
FPSdisplay.setLayoutY(20); FPSDisplay.setLayoutY(20);
FPSdisplay.setStrokeWidth(2); FPSDisplay.setStrokeWidth(2);
group.getChildren().add(FPSdisplay); group.getChildren().add(FPSDisplay);
group.getChildren().add(raceBorder); group.getChildren().add(raceBorder);
initializeMarks(); initializeMarks();
initializeBoats(); initializeBoats();
@@ -391,10 +391,10 @@ public class CanvasController {
private void drawFps(int fps){ private void drawFps(int fps){
if (raceViewController.isDisplayFps()){ if (raceViewController.isDisplayFps()){
FPSdisplay.setVisible(true); FPSDisplay.setVisible(true);
FPSdisplay.setText(String.format("%d FPS", fps)); FPSDisplay.setText(String.format("%d FPS", fps));
} else { } else {
FPSdisplay.setVisible(false); FPSDisplay.setVisible(false);
} }
} }
@@ -112,6 +112,7 @@ public class LobbyController implements Initializable, Observer{
readyButton.setDisable(true); readyButton.setDisable(true);
} }
// put all javafx objects in lists, so we can iterate though conveniently
imageViews = new ArrayList<>(); imageViews = new ArrayList<>();
Collections.addAll(imageViews, firstImageView, secondImageView, thirdImageView, fourthImageView, Collections.addAll(imageViews, firstImageView, secondImageView, thirdImageView, fourthImageView,
fifthImageView, sixthImageView, seventhImageView, eighthImageView); fifthImageView, sixthImageView, seventhImageView, eighthImageView);
@@ -134,6 +135,13 @@ public class LobbyController implements Initializable, Observer{
clientStateQueryingThread.start(); 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 @Override
public void update(Observable o, Object arg) { public void update(Observable o, Object arg) {
Platform.runLater(new Runnable() { 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() { private void initialiseListView() {
listViews.forEach(listView -> listView.getItems().clear()); listViews.forEach(listView -> listView.getItems().clear());
imageViews.forEach(gif -> gif.setVisible(false)); imageViews.forEach(gif -> gif.setVisible(false));
@@ -162,6 +173,9 @@ public class LobbyController implements Initializable, Observer{
} }
} }
/**
* Loads preset images into imageViews
*/
private void initialiseImageView() { private void initialiseImageView() {
for (int i = 0; i < MAX_NUM_PLAYERS; i++) { for (int i = 0; i < MAX_NUM_PLAYERS; i++) {
imageViews.get(i).setImage(new Image(getClass().getResourceAsStream("/pics/sail.png"))); imageViews.get(i).setImage(new Image(getClass().getResourceAsStream("/pics/sail.png")));
@@ -195,14 +209,11 @@ public class LobbyController implements Initializable, Observer{
@FXML @FXML
public void readyButtonPressed() { public void readyButtonPressed() {
// setContentPane("/views/RaceView.fxml");
GameState.setCurrentStage(GameStages.RACING); GameState.setCurrentStage(GameStages.RACING);
mainServerThread.startGame(); mainServerThread.startGame();
} }
private void switchToRaceView() { private void switchToRaceView() {
if (!switchedPane) { if (!switchedPane) {
switchedPane = true; switchedPane = true;