completed Method initphase

This commit is contained in:
romanschenk37 2022-03-10 16:30:33 +01:00
parent 6285cfe215
commit 3fe1bb1426
2 changed files with 33 additions and 2 deletions

View File

@ -1,6 +1,10 @@
package ch.zhaw.pm2.racetrack; package ch.zhaw.pm2.racetrack;
import ch.zhaw.pm2.racetrack.given.GameSpecification; import ch.zhaw.pm2.racetrack.given.GameSpecification;
import ch.zhaw.pm2.racetrack.strategy.DoNotMoveStrategy;
import ch.zhaw.pm2.racetrack.strategy.MoveListStrategy;
import ch.zhaw.pm2.racetrack.strategy.PathFollowerMoveStrategy;
import ch.zhaw.pm2.racetrack.strategy.UserMoveStrategy;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@ -17,6 +21,7 @@ import static ch.zhaw.pm2.racetrack.PositionVector.Direction;
public class Game implements GameSpecification { public class Game implements GameSpecification {
public static final int NO_WINNER = -1; public static final int NO_WINNER = -1;
private Track track; private Track track;
int currentCarIndex;
UserInterface userInterface; UserInterface userInterface;
@ -25,7 +30,7 @@ public class Game implements GameSpecification {
} }
public void initphase() throws InvalidTrackFormatException, FileNotFoundException { public void initphase() throws InvalidTrackFormatException, FileNotFoundException {
File folder = new File("your/path"); File folder = new File("tracks");
File[] listOfFiles = folder.listFiles(); File[] listOfFiles = folder.listFiles();
List<String> tracks = new ArrayList<>(); List<String> tracks = new ArrayList<>();
for(File file : listOfFiles){ for(File file : listOfFiles){
@ -33,6 +38,33 @@ public class Game implements GameSpecification {
} }
File selectedTrack = listOfFiles[userInterface.selectOption("Select Track file", tracks)]; File selectedTrack = listOfFiles[userInterface.selectOption("Select Track file", tracks)];
track = new Track(selectedTrack); track = new Track(selectedTrack);
List<String> moveStrategies = new ArrayList<>();
moveStrategies.add("Do not move Strategy");
moveStrategies.add("User Move Strategy");
moveStrategies.add("Move List Strategy");
moveStrategies.add("Path Follow Move Strategy");
for(int i = 0; i < track.getCarCount() ; i++ ){
int moveStrategie = userInterface.selectOption(
"Select Strategy for Car " + i + " (" + track.getCarId(i) + ")", moveStrategies);
switch(moveStrategie) { //TODO: set Movestrategy with method in Track
case 1:
track.getCar(i).setMoveStrategy(new DoNotMoveStrategy()); //TODO: add Arguments
break;
case 2:
track.getCar(i).setMoveStrategy(new UserMoveStrategy()); //TODO: add Arguments
break;
case 3:
track.getCar(i).setMoveStrategy(new MoveListStrategy()); //TODO: add Arguments
break;
case 4:
track.getCar(i).setMoveStrategy(new PathFollowerMoveStrategy()); //TODO: add Arguments
break;
}
}
userInterface.printTrack(track);
} }
/** /**

1
tracks/.gitignore vendored
View File

@ -1 +0,0 @@
challenge_points.txt