refactoring Game.java
This commit is contained in:
parent
00cb917842
commit
a77d02b440
|
@ -56,23 +56,67 @@ public class Game implements GameSpecification {
|
|||
moveStrategies.add("Move List Strategy");
|
||||
moveStrategies.add("Path Follow Move Strategy");
|
||||
moveStrategies.add("Path Finder Move Strategy");
|
||||
for (int i = 0; i < track.getCarCount(); i++) {
|
||||
Car car = track.getCar(i);
|
||||
for (int carIndex = 0; carIndex < track.getCarCount(); carIndex++) {
|
||||
Car car = track.getCar(carIndex);
|
||||
MoveStrategy moveStrategy = null;
|
||||
while (moveStrategy == null) {
|
||||
File selectedFile = null;
|
||||
int moveStrategie = userInterface.selectOption(
|
||||
"Select Strategy for Car " + i + " (" + track.getCarId(i) + ")", moveStrategies);
|
||||
"Select Strategy for Car " + carIndex + " (" + track.getCarId(carIndex) + ")", moveStrategies);
|
||||
switch (moveStrategie) {
|
||||
case 0:
|
||||
moveStrategy = new DoNotMoveStrategy();
|
||||
break;
|
||||
case 1:
|
||||
moveStrategy = new UserMoveStrategy(userInterface, i, track.getCarId(i));
|
||||
moveStrategy = new UserMoveStrategy(userInterface, carIndex, track.getCarId(carIndex));
|
||||
break;
|
||||
case 2:
|
||||
moveStrategy = getMoveListStrategy(selectedTrack, carIndex, moveStrategy);
|
||||
break;
|
||||
case 3:
|
||||
moveStrategy = getPathFollowerMoveStrategy(selectedTrack, carIndex, moveStrategy);
|
||||
|
||||
break;
|
||||
case 4:
|
||||
moveStrategy = new PathFinderMoveStrategy(track, carIndex);
|
||||
break;
|
||||
}
|
||||
}
|
||||
selectMoveStrategy(car, moveStrategy);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
userInterface.printInformation("No Trackfile found!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private MoveStrategy getPathFollowerMoveStrategy(File selectedTrack, int carIndex, MoveStrategy moveStrategy) {
|
||||
File selectedFile = null;
|
||||
for (File file : config.getFollowerDirectory().listFiles()) {
|
||||
if (file.toString().equals(config.getFollowerDirectory().toString() + "\\" + selectedTrack.getName().split("\\.")[0] + "_points.txt")) {
|
||||
selectedFile = file;
|
||||
}
|
||||
}
|
||||
if (selectedFile != null) {
|
||||
try {
|
||||
moveStrategy = new PathFollowerMoveStrategy(selectedFile, track.getCarPos(carIndex));
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
userInterface.printInformation("There is no Point-List implemented. Choose another Strategy!");
|
||||
} catch (InvalidFileFormatException e) {
|
||||
e.printStackTrace();
|
||||
userInterface.printInformation("Invalid Point-List format. Change Strategy and clean Point-List");
|
||||
}
|
||||
} else {
|
||||
userInterface.printInformation("There is no Point-List implemented. Choose another Strategy!");
|
||||
}
|
||||
return moveStrategy;
|
||||
}
|
||||
|
||||
private MoveStrategy getMoveListStrategy(File selectedTrack, int carIndex, MoveStrategy moveStrategy) {
|
||||
File selectedFile = null;
|
||||
for (File file : config.getMoveDirectory().listFiles()) {
|
||||
if (file.toString().equals(config.getMoveDirectory().toString() + "\\" + selectedTrack.getName().split("\\.")[0] + "-car-" + track.getCar(i).getID() + ".txt")) {
|
||||
if (file.toString().equals(config.getMoveDirectory().toString() + "\\" + selectedTrack.getName().split("\\.")[0] + "-car-" + track.getCar(carIndex).getID() + ".txt")) {
|
||||
selectedFile = file;
|
||||
}
|
||||
}
|
||||
|
@ -89,41 +133,7 @@ public class Game implements GameSpecification {
|
|||
} else {
|
||||
userInterface.printInformation("There is no Move-List implemented. Choose another Strategy!");
|
||||
}
|
||||
|
||||
break;
|
||||
case 3:
|
||||
for (File file : config.getFollowerDirectory().listFiles()) {
|
||||
if (file.toString().equals(config.getFollowerDirectory().toString() + "\\" + selectedTrack.getName().split("\\.")[0] + "_points.txt")) {
|
||||
selectedFile = file;
|
||||
}
|
||||
}
|
||||
if (selectedFile != null) {
|
||||
try {
|
||||
moveStrategy = new PathFollowerMoveStrategy(selectedFile, track.getCarPos(i));
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
userInterface.printInformation("There is no Point-List implemented. Choose another Strategy!");
|
||||
} catch (InvalidFileFormatException e) {
|
||||
e.printStackTrace();
|
||||
userInterface.printInformation("Invalid Point-List format. Change Strategy and clean Point-List");
|
||||
}
|
||||
} else {
|
||||
userInterface.printInformation("There is no Point-List implemented. Choose another Strategy!");
|
||||
}
|
||||
|
||||
break;
|
||||
case 4:
|
||||
moveStrategy = new PathFinderMoveStrategy(track, i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
selectMoveStrategy(car, moveStrategy);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
userInterface.printInformation("No Trackfile found!");
|
||||
return false;
|
||||
}
|
||||
return moveStrategy;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue