Last active
August 29, 2015 13:56
-
-
Save cangevine/9106964 to your computer and use it in GitHub Desktop.
Race
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Race { | |
public static void main(String[] args) { | |
Race r = new Race(); | |
try { | |
r.beginRace(); | |
} catch (InterruptedException e) { | |
System.out.println("Unable to execute race..."); | |
} | |
System.out.println(rt.getWinnersList()); | |
} | |
private Racer[] racers; | |
private String[] map; | |
public Race() { | |
System.out.println("Welcome to the race! Let's get started..."); | |
map = new String[20]; | |
initTrack(); | |
racers = new Racer[9]; | |
initRacers(); | |
} | |
private void initRacers() { | |
/*racers[0] = new GianlucaRacer(); | |
racers[0].setTrack(map); | |
racers[1] = new LeeRacer(); | |
racers[1].setTrack(map); | |
...etc...*/ | |
} | |
private void initTrack() { | |
map = new String[] {"0", "0", "0", "x", "0", "s", "0", "p", "x", "x", "x", "0", "0", "p", "0", "s", "x", "x", "0", "0"}; | |
} | |
public void beginRace() throws InterruptedException { | |
while(raceIsInProgress()) { | |
for (int i = 0; i < racers.length; i++) { | |
if (!racers[i].crossedFinishLine()) { | |
racers[i].tick(); | |
} | |
} | |
Thread.sleep(100); | |
} | |
} | |
public boolean raceIsInProgress() { | |
int completedRacers = 0; | |
for (int i = 0; i < racers.length; i++) { | |
if (racers[i].crossedFinishLine()) { | |
completedRacers++; | |
} | |
} | |
return (completedRacers != racers.length); | |
} | |
public String getWinnersList() { | |
String str = ""; | |
// collect winners list | |
return str; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment