changes in Method initphase
added Method printInformation in UserInterface.java
This commit is contained in:
parent
3fe1bb1426
commit
dd625907c9
|
@ -29,24 +29,30 @@ public class Game implements GameSpecification {
|
||||||
userInterface = new UserInterface(welcometext);
|
userInterface = new UserInterface(welcometext);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initphase() throws InvalidTrackFormatException, FileNotFoundException {
|
|
||||||
|
public boolean initphase() throws InvalidTrackFormatException, FileNotFoundException {
|
||||||
File folder = new File("tracks");
|
File folder = new File("tracks");
|
||||||
File[] listOfFiles = folder.listFiles();
|
File[] listOfFiles = folder.listFiles();
|
||||||
|
if(listOfFiles.length > 0) {
|
||||||
List<String> tracks = new ArrayList<>();
|
List<String> tracks = new ArrayList<>();
|
||||||
for(File file : listOfFiles){
|
for(File file : listOfFiles){
|
||||||
tracks.add(file.getName());
|
tracks.add(file.getName());
|
||||||
}
|
}
|
||||||
File selectedTrack = listOfFiles[userInterface.selectOption("Select Track file", tracks)];
|
File selectedTrack = listOfFiles[userInterface.selectOption("Select Track file", tracks)];
|
||||||
|
try {
|
||||||
track = new Track(selectedTrack);
|
track = new Track(selectedTrack);
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
List<String> moveStrategies = new ArrayList<>();
|
List<String> moveStrategies = new ArrayList<>();
|
||||||
moveStrategies.add("Do not move Strategy");
|
moveStrategies.add("Do not move Strategy");
|
||||||
moveStrategies.add("User Move Strategy");
|
moveStrategies.add("User Move Strategy");
|
||||||
moveStrategies.add("Move List Strategy");
|
moveStrategies.add("Move List Strategy");
|
||||||
moveStrategies.add("Path Follow Move Strategy");
|
moveStrategies.add("Path Follow Move Strategy");
|
||||||
for(int i = 0; i < track.getCarCount() ; i++ ){
|
for(int i = 0; i < track.getCarCount() ; i++ ) {
|
||||||
int moveStrategie = userInterface.selectOption(
|
int moveStrategie = userInterface.selectOption(
|
||||||
"Select Strategy for Car " + i + " (" + track.getCarId(i) + ")", moveStrategies);
|
"Select Strategy for Car " + i + " (" + track.getCarId(i) + ")", moveStrategies);
|
||||||
switch(moveStrategie) { //TODO: set Movestrategy with method in Track
|
switch (moveStrategie) { //TODO: set Movestrategy with method in Track
|
||||||
case 1:
|
case 1:
|
||||||
track.getCar(i).setMoveStrategy(new DoNotMoveStrategy()); //TODO: add Arguments
|
track.getCar(i).setMoveStrategy(new DoNotMoveStrategy()); //TODO: add Arguments
|
||||||
break;
|
break;
|
||||||
|
@ -61,10 +67,12 @@ public class Game implements GameSpecification {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else{
|
||||||
userInterface.printTrack(track);
|
userInterface.printInformation("No Trackfile found!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -22,6 +22,14 @@ public class UserInterface {
|
||||||
textTerminal.println(welcomeText + "\n");
|
textTerminal.println(welcomeText + "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prints the given Text in textTerminal
|
||||||
|
* @param text The Text which should be printed.
|
||||||
|
*/
|
||||||
|
public void printInformation(String text) {
|
||||||
|
textTerminal.println(text);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* asks the user to choose one of the options given.
|
* asks the user to choose one of the options given.
|
||||||
* @param text Text which is printed befor the options are printed. Example: "Select Track file:"
|
* @param text Text which is printed befor the options are printed. Example: "Select Track file:"
|
||||||
|
@ -29,7 +37,7 @@ public class UserInterface {
|
||||||
* @return the list index of the selected option
|
* @return the list index of the selected option
|
||||||
*/
|
*/
|
||||||
public int selectOption(String text, List<String> options) {
|
public int selectOption(String text, List<String> options) {
|
||||||
textTerminal.println(text + ":\n");
|
textTerminal.println(text + ":");
|
||||||
for(int option = 0; option < options.size(); option ++) {
|
for(int option = 0; option < options.size(); option ++) {
|
||||||
textTerminal.println(" " + (option + 1) + ": " + options.get(option));
|
textTerminal.println(" " + (option + 1) + ": " + options.get(option));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue