diff --git a/mock/pom.xml b/mock/pom.xml index a81f8ac5..e5013da4 100644 --- a/mock/pom.xml +++ b/mock/pom.xml @@ -8,10 +8,12 @@ jar - mock - mock + visualiser + visualiser 1.0-SNAPSHOT + https://eng-git.canterbury.ac.nz/SENG302-2016/team-7 + junit @@ -52,6 +54,12 @@ 1.0-SNAPSHOT + + eu.hansolo + Medusa + 7.9 + + @@ -162,3 +170,4 @@ + diff --git a/mock/src/main/java/seng302/Model/Race.java b/mock/src/main/java/seng302/Model/Race.java index d4e92480..e360d11a 100644 --- a/mock/src/main/java/seng302/Model/Race.java +++ b/mock/src/main/java/seng302/Model/Race.java @@ -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(); }