Game #23
|
@ -41,7 +41,7 @@ public class Game implements GameSpecification {
|
||||||
File selectedTrack = listOfFiles[userInterface.selectOption("Select Track file", tracks)];
|
File selectedTrack = listOfFiles[userInterface.selectOption("Select Track file", tracks)];
|
||||||
try {
|
try {
|
||||||
track = new Track(selectedTrack);
|
track = new Track(selectedTrack);
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException | PositionVectorNotValid e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
List<String> moveStrategies = new ArrayList<>();
|
List<String> moveStrategies = new ArrayList<>();
|
||||||
|
@ -52,7 +52,7 @@ public class Game implements GameSpecification {
|
||||||
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 + 1) { //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;
|
||||||
|
@ -157,7 +157,7 @@ public class Game implements GameSpecification {
|
||||||
* for this turn
|
* for this turn
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void doCarTurn(Direction acceleration) {
|
public void doCarTurn(Direction acceleration) throws PositionVectorNotValid {
|
||||||
// TODO: implementation
|
// TODO: implementation
|
||||||
track.getCar(currentCarIndex).accelerate(acceleration);
|
track.getCar(currentCarIndex).accelerate(acceleration);
|
||||||
|
|
||||||
|
@ -178,7 +178,7 @@ public class Game implements GameSpecification {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int gamePhase() {
|
public int gamePhase() throws PositionVectorNotValid {
|
||||||
do{
|
do{
|
||||||
userInterface.printTrack(track);
|
userInterface.printTrack(track);
|
||||||
Direction direction = track.getCar(currentCarIndex).getMoveStrategy().nextMove();
|
Direction direction = track.getCar(currentCarIndex).getMoveStrategy().nextMove();
|
||||||
|
@ -321,8 +321,8 @@ public class Game implements GameSpecification {
|
||||||
* @return A boolean indicator if the car would crash with a WALL or another car.
|
* @return A boolean indicator if the car would crash with a WALL or another car.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean willCarCrash(int carIndex, PositionVector position) {
|
public boolean willCarCrash(int carIndex, PositionVector position) throws PositionVectorNotValid {
|
||||||
return track.willCrashAtPosition(position); //TODO: add carIndex
|
return track.willCrashAtPosition(carIndex, position);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean allCarsCrashed() {
|
public boolean allCarsCrashed() {
|
||||||
|
|
|
@ -4,7 +4,7 @@ import java.io.FileNotFoundException;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
public static void main(String[] args) throws InvalidTrackFormatException, FileNotFoundException {
|
public static void main(String[] args) throws InvalidTrackFormatException, FileNotFoundException, PositionVectorNotValid {
|
||||||
UserInterface userInterface = new UserInterface("Hello and Welcome");
|
UserInterface userInterface = new UserInterface("Hello and Welcome");
|
||||||
Game game = new Game(userInterface);
|
Game game = new Game(userInterface);
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@ import ch.zhaw.pm2.racetrack.given.TrackSpecification;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package ch.zhaw.pm2.racetrack.given;
|
package ch.zhaw.pm2.racetrack.given;
|
||||||
|
|
||||||
import ch.zhaw.pm2.racetrack.PositionVector;
|
import ch.zhaw.pm2.racetrack.PositionVector;
|
||||||
|
import ch.zhaw.pm2.racetrack.PositionVectorNotValid;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -18,11 +19,11 @@ public interface GameSpecification {
|
||||||
|
|
||||||
int getWinner();
|
int getWinner();
|
||||||
|
|
||||||
void doCarTurn(PositionVector.Direction acceleration);
|
void doCarTurn(PositionVector.Direction acceleration) throws PositionVectorNotValid;
|
||||||
|
|
||||||
void switchToNextActiveCar();
|
void switchToNextActiveCar();
|
||||||
|
|
||||||
List<PositionVector> calculatePath(PositionVector startPosition, PositionVector endPosition);
|
List<PositionVector> calculatePath(PositionVector startPosition, PositionVector endPosition);
|
||||||
|
|
||||||
boolean willCarCrash(int carIndex, PositionVector position);
|
boolean willCarCrash(int carIndex, PositionVector position) throws PositionVectorNotValid;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue