mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Finish screen now displays correctly on finishing.
GameState update now checks for finishing the race Can now go back to main menu from finish screen Labeled all threads for better debugging Still need to implement race list ordering and finish screen ordering
This commit is contained in:
@@ -89,7 +89,7 @@ public class GameState implements Runnable {
|
||||
markOrder = new MarkOrder(); //This could be instantiated at some point with a select map?
|
||||
markListeners = new ArrayList<>();
|
||||
|
||||
new Thread(this).start(); //Run the auto updates on the game state
|
||||
new Thread(this, "GameState").start(); //Run the auto updates on the game state
|
||||
|
||||
marks = new MarkOrder().getAllMarks();
|
||||
}
|
||||
@@ -184,7 +184,7 @@ public class GameState implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
while (true) {
|
||||
while (currentStage != GameStages.FINISHED) {
|
||||
try {
|
||||
Thread.sleep(1000 / STATE_UPDATES_PER_SECOND);
|
||||
} catch (InterruptedException e) {
|
||||
@@ -229,17 +229,24 @@ public class GameState implements Runnable {
|
||||
* Called periodically in this GameState thread to update the GameState values
|
||||
*/
|
||||
public void update() {
|
||||
Boolean raceFinished = true;
|
||||
|
||||
Double timeInterval = (System.currentTimeMillis() - previousUpdateTime) / 1000000.0;
|
||||
previousUpdateTime = System.currentTimeMillis();
|
||||
for (ServerYacht yacht : yachts.values()) {
|
||||
updateVelocity(yacht);
|
||||
yacht.runAutoPilot();
|
||||
yacht.updateLocation(timeInterval);
|
||||
if (!yacht.getFinishedRace()) {
|
||||
if (yacht.getBoatStatus() != BoatStatus.FINISHED) {
|
||||
checkForCollision(yacht);
|
||||
checkForLegProgression(yacht);
|
||||
raceFinished = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (raceFinished) {
|
||||
currentStage = GameStages.FINISHED;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -283,7 +290,7 @@ public class GameState implements Runnable {
|
||||
Double velocity = yacht.getCurrentVelocity();
|
||||
Double trueWindAngle = Math.abs(windDirection - yacht.getHeading());
|
||||
Double boatSpeedInKnots = PolarTable.getBoatSpeed(getWindSpeedKnots(), trueWindAngle);
|
||||
Double maxBoatSpeed = GeoUtility.knotsToMMS(boatSpeedInKnots) * 3;
|
||||
Double maxBoatSpeed = GeoUtility.knotsToMMS(boatSpeedInKnots);
|
||||
// TODO: 15/08/17 remove magic numbers from these equations.
|
||||
if (yacht.getSailIn()) {
|
||||
if (velocity < maxBoatSpeed - 500) {
|
||||
@@ -345,6 +352,7 @@ public class GameState implements Runnable {
|
||||
private void checkForLegProgression(ServerYacht yacht) {
|
||||
Integer currentMarkSeqID = yacht.getCurrentMarkSeqID();
|
||||
CompoundMark currentMark = markOrder.getCurrentMark(currentMarkSeqID);
|
||||
// System.out.println(yacht.getCurrentMarkSeqID());
|
||||
|
||||
Boolean hasProgressed;
|
||||
if (currentMarkSeqID == 0) {
|
||||
@@ -493,7 +501,6 @@ public class GameState implements Runnable {
|
||||
Boolean isClockwiseCross = GeoUtility.isClockwise(mark1, mark2, prevMark.getMidPoint());
|
||||
if (crossedLine == 1 && isClockwiseCross || crossedLine == 2 && !isClockwiseCross) {
|
||||
yacht.setClosestCurrentMark(mark1);
|
||||
yacht.setIsFinished(true);
|
||||
yacht.setBoatStatus(BoatStatus.FINISHED);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package seng302.gameServer;
|
||||
|
||||
import gherkin.lexer.Fi;
|
||||
import java.io.IOException;
|
||||
import java.net.ServerSocket;
|
||||
import java.time.LocalDateTime;
|
||||
@@ -48,7 +49,7 @@ public class MainServerThread implements Runnable, ClientConnectionDelegate {
|
||||
PolarTable.parsePolarFile(getClass().getResourceAsStream("/config/acc_polars.csv"));
|
||||
GameState.addMarkPassListener(this::broadcastMessage);
|
||||
terminated = false;
|
||||
thread = new Thread(this);
|
||||
thread = new Thread(this, "MainServer");
|
||||
thread.start();
|
||||
}
|
||||
|
||||
@@ -82,7 +83,7 @@ public class MainServerThread implements Runnable, ClientConnectionDelegate {
|
||||
|
||||
//FINISHED
|
||||
else if (GameState.getCurrentStage() == GameStages.FINISHED) {
|
||||
|
||||
terminate();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ public class ServerToClientThread implements Runnable, Observer {
|
||||
return;
|
||||
}
|
||||
|
||||
thread = new Thread(this);
|
||||
thread = new Thread(this, "ServerToClient");
|
||||
thread.start();
|
||||
}
|
||||
|
||||
|
||||
@@ -42,12 +42,11 @@ public class ServerYacht extends Observable {
|
||||
private Double autoHeading;
|
||||
|
||||
//Mark Rounding
|
||||
private Integer currentMarkSeqID = 0;
|
||||
private Integer currentMarkSeqID;
|
||||
private Boolean hasEnteredRoundingZone;
|
||||
private Mark closestCurrentMark;
|
||||
private Boolean hasPassedLine;
|
||||
private Boolean hasPassedThroughGate;
|
||||
private Boolean finishedRace;
|
||||
|
||||
|
||||
public ServerYacht(String boatType, Integer sourceId, String hullID, String shortName,
|
||||
@@ -65,11 +64,11 @@ public class ServerYacht extends Observable {
|
||||
this.lastLocation = location;
|
||||
this.heading = 120.0; //In degrees
|
||||
this.currentVelocity = 0d; //in mms-1
|
||||
this.currentMarkSeqID = 0;
|
||||
|
||||
this.hasEnteredRoundingZone = false;
|
||||
this.hasPassedLine = false;
|
||||
this.hasPassedThroughGate = false;
|
||||
this.finishedRace = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -322,15 +321,6 @@ public class ServerYacht extends Observable {
|
||||
return boatName;
|
||||
}
|
||||
|
||||
|
||||
public void setIsFinished(Boolean isFinished) {
|
||||
finishedRace = isFinished;
|
||||
}
|
||||
|
||||
public Boolean getFinishedRace() {
|
||||
return finishedRace;
|
||||
}
|
||||
|
||||
public Double getCurrentVelocity() {
|
||||
return currentVelocity;
|
||||
}
|
||||
|
||||
@@ -35,6 +35,14 @@
|
||||
<CompoundMarkSequence>
|
||||
<Corner SeqID="1" CompoundMarkID="1" Rounding="PS" ZoneSize="3" />
|
||||
<Corner SeqID="2" CompoundMarkID="2" Rounding="Port" ZoneSize="3" />
|
||||
<Corner SeqID="3" CompoundMarkID="3" Rounding="SP" ZoneSize="3" />
|
||||
<Corner SeqID="4" CompoundMarkID="4" Rounding="PS" ZoneSize="3" />
|
||||
<Corner SeqID="5" CompoundMarkID="3" Rounding="SP" ZoneSize="3" />
|
||||
<Corner SeqID="6" CompoundMarkID="4" Rounding="PS" ZoneSize="3" />
|
||||
<Corner SeqID="7" CompoundMarkID="3" Rounding="SP" ZoneSize="3" />
|
||||
<Corner SeqID="8" CompoundMarkID="4" Rounding="PS" ZoneSize="3" />
|
||||
<Corner SeqID="9" CompoundMarkID="3" Rounding="SP" ZoneSize="3" />
|
||||
<Corner SeqID="10" CompoundMarkID="4" Rounding="PS" ZoneSize="3" />
|
||||
<Corner SeqID="11" CompoundMarkID="5" Rounding="PS" ZoneSize="3" />
|
||||
</CompoundMarkSequence>
|
||||
<CourseLimit>
|
||||
|
||||
Reference in New Issue
Block a user