mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Added method to create the race with names from the config file
- # implement
This commit is contained in:
@@ -1,19 +1,56 @@
|
||||
package seng302;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.Random;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class App
|
||||
{
|
||||
public static Race createRace(int numberOfBoats) throws Exception{
|
||||
Race race = new Race();
|
||||
|
||||
// Read team names from file
|
||||
FileParser fp = new FileParser("src/test/java/seng302/valid.json");
|
||||
ArrayList<String> boatNames = fp.getTeams();
|
||||
|
||||
// Shuffle team names
|
||||
long seed = System.nanoTime();
|
||||
Collections.shuffle(boatNames, new Random(seed));
|
||||
|
||||
if (numberOfBoats > Array.getLength(boatNames.toArray())){
|
||||
return null;
|
||||
}
|
||||
|
||||
for (int i = 0; i < numberOfBoats; i++) {
|
||||
race.addBoat(new Boat(boatNames.get(i)));
|
||||
}
|
||||
|
||||
return race;
|
||||
}
|
||||
|
||||
public static void main( String[] args )
|
||||
{
|
||||
Race race = new Race();
|
||||
race.addBoat(new Boat("Team 1"));
|
||||
race.addBoat(new Boat("Team 2"));
|
||||
Race race = null;
|
||||
|
||||
race.displayStartingBoats();
|
||||
try{
|
||||
race = createRace(2);
|
||||
|
||||
System.out.println("");
|
||||
}
|
||||
catch (Exception e){
|
||||
System.out.println(e);
|
||||
}
|
||||
|
||||
race.displayFinishingOrder();
|
||||
if (race != null){
|
||||
race.displayStartingBoats();
|
||||
|
||||
System.out.println("");
|
||||
|
||||
race.displayFinishingOrder();
|
||||
}
|
||||
else{
|
||||
System.out.println("e");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user