Created methods to initialise and change wind direction throughout race.
-Method initialiseWinDir assigns an unsigned short value to wind direction. -Method changeWindDir randomly changes the wind direction throughout race. -Issue found regarding showing wind direction. #story[882]
This commit is contained in:
+11
-2
@@ -8,10 +8,12 @@
|
||||
</parent>
|
||||
|
||||
<packaging>jar</packaging>
|
||||
<name>mock</name>
|
||||
<artifactId>mock</artifactId>
|
||||
<name>visualiser</name>
|
||||
<artifactId>visualiser</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<url>https://eng-git.canterbury.ac.nz/SENG302-2016/team-7</url>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
@@ -52,6 +54,12 @@
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>eu.hansolo</groupId>
|
||||
<artifactId>Medusa</artifactId>
|
||||
<version>7.9</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
@@ -162,3 +170,4 @@
|
||||
</plugins>
|
||||
</reporting>
|
||||
</project>
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ public class Race implements Runnable {
|
||||
private MockOutput mockOutput;
|
||||
private static int boatOffset = 0;
|
||||
private int finished = 0;
|
||||
private int windDir;
|
||||
|
||||
|
||||
/**
|
||||
@@ -100,10 +101,36 @@ public class Race implements Runnable {
|
||||
* Runnable for the thread.
|
||||
*/
|
||||
public void run() {
|
||||
initialiseWindDir();
|
||||
initialiseBoats();
|
||||
countdownTimer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiate a random wind direction
|
||||
*/
|
||||
protected void initialiseWindDir(){
|
||||
windDir = new Random().nextInt(65535);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the wind direction. Checks to make sure wind direction is between 0 - 65535
|
||||
*/
|
||||
protected void changeWindDir(){
|
||||
int r = new Random().nextInt(3) + 1;
|
||||
if (r == 1){
|
||||
windDir+=250;
|
||||
} else if (r == 2) {
|
||||
windDir-=250;
|
||||
}
|
||||
if (windDir > 65535){
|
||||
windDir -= 65535;
|
||||
}
|
||||
if (windDir < 0){
|
||||
windDir += 65535;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the heartbeat timer, which sends a heartbeat message every so often (i.e., 5 seconds).
|
||||
*/
|
||||
@@ -134,7 +161,7 @@ public class Race implements Runnable {
|
||||
boatOffset = (boatOffset + 1) % (startingBoats.size());
|
||||
|
||||
if (timeLeft <= 60000/scaleFactor && timeLeft > 0) {
|
||||
RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, 2, startTime, 0, 2300, 1, boatStatuses);
|
||||
RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, 2, startTime, windDir, 2300, 1, boatStatuses);
|
||||
mockOutput.parseRaceStatus(raceStatus);
|
||||
}
|
||||
else if (timeLeft <= 0) {
|
||||
@@ -145,7 +172,7 @@ public class Race implements Runnable {
|
||||
stop();
|
||||
}
|
||||
else {
|
||||
RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, 1, startTime, 0, 2300,1, boatStatuses);
|
||||
RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, 1, startTime, windDir, 2300,1, boatStatuses);
|
||||
mockOutput.parseRaceStatus(raceStatus);
|
||||
}
|
||||
currentTime = System.currentTimeMillis();
|
||||
@@ -173,6 +200,7 @@ public class Race implements Runnable {
|
||||
|
||||
@Override
|
||||
public void handle(long arg0) {
|
||||
System.out.println(windDir);
|
||||
if (boatsFinished < startingBoats.size()) {
|
||||
//Get the current time.
|
||||
long currentTime = System.currentTimeMillis();
|
||||
@@ -199,7 +227,7 @@ public class Race implements Runnable {
|
||||
boat.getCurrentLeg().getLegNumber() >= 0 ? BoatStatusEnum.RACING : BoatStatusEnum.DNF, boat.getCurrentLeg().getLegNumber()));
|
||||
}
|
||||
if (startingBoats.size()==finished){
|
||||
RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, 4, startTime, 0, 2300, 2, boatStatuses);//TODO FIX the second currentTime is a placeholder! Also, replace magic values.
|
||||
RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, 4, startTime, windDir, 2300, 2, boatStatuses);//TODO FIX the second currentTime is a placeholder! Also, replace magic values.
|
||||
mockOutput.parseRaceStatus(raceStatus);
|
||||
}
|
||||
} else {
|
||||
@@ -207,9 +235,10 @@ public class Race implements Runnable {
|
||||
}
|
||||
}
|
||||
boatOffset = (boatOffset + 1) % (startingBoats.size());
|
||||
RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, 3, startTime, 0, 2300, 2, boatStatuses);//TODO FIX the second currentTime is a placeholder! Also, replace magic values.
|
||||
RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, 3, startTime, windDir, 2300, 2, boatStatuses);//TODO FIX the second currentTime is a placeholder! Also, replace magic values.
|
||||
mockOutput.parseRaceStatus(raceStatus);
|
||||
}
|
||||
changeWindDir();
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user