Skip to content

Instantly share code, notes, and snippets.

@cangevine
Last active August 29, 2015 13:56
Show Gist options
  • Save cangevine/9106964 to your computer and use it in GitHub Desktop.
Save cangevine/9106964 to your computer and use it in GitHub Desktop.
Race
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