merge track into game and fix in initphase

This commit is contained in:
romanschenk37 2022-03-18 10:19:23 +01:00
parent 5ec7260b1e
commit a723ea16ec
4 changed files with 10 additions and 10 deletions

View File

@ -41,7 +41,7 @@ public class Game implements GameSpecification {
File selectedTrack = listOfFiles[userInterface.selectOption("Select Track file", tracks)];
try {
track = new Track(selectedTrack);
} catch (FileNotFoundException e) {
} catch (FileNotFoundException | PositionVectorNotValid e) {
e.printStackTrace();
}
List<String> moveStrategies = new ArrayList<>();
@ -52,7 +52,7 @@ public class Game implements GameSpecification {
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
switch (moveStrategie + 1) { //TODO: set Movestrategy with method in Track
case 1:
track.getCar(i).setMoveStrategy(new DoNotMoveStrategy()); //TODO: add Arguments
break;
@ -157,7 +157,7 @@ public class Game implements GameSpecification {
* for this turn
*/
@Override
public void doCarTurn(Direction acceleration) {
public void doCarTurn(Direction acceleration) throws PositionVectorNotValid {
// TODO: implementation
track.getCar(currentCarIndex).accelerate(acceleration);
@ -178,7 +178,7 @@ public class Game implements GameSpecification {
}
}
public int gamePhase() {
public int gamePhase() throws PositionVectorNotValid {
do{
userInterface.printTrack(track);
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.
*/
@Override
public boolean willCarCrash(int carIndex, PositionVector position) {
return track.willCrashAtPosition(position); //TODO: add carIndex
public boolean willCarCrash(int carIndex, PositionVector position) throws PositionVectorNotValid {
return track.willCrashAtPosition(carIndex, position);
}
public boolean allCarsCrashed() {

View File

@ -4,7 +4,7 @@ import java.io.FileNotFoundException;
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");
Game game = new Game(userInterface);

View File

@ -6,7 +6,6 @@ import ch.zhaw.pm2.racetrack.given.TrackSpecification;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

View File

@ -1,6 +1,7 @@
package ch.zhaw.pm2.racetrack.given;
import ch.zhaw.pm2.racetrack.PositionVector;
import ch.zhaw.pm2.racetrack.PositionVectorNotValid;
import java.util.List;
@ -18,11 +19,11 @@ public interface GameSpecification {
int getWinner();
void doCarTurn(PositionVector.Direction acceleration);
void doCarTurn(PositionVector.Direction acceleration) throws PositionVectorNotValid;
void switchToNextActiveCar();
List<PositionVector> calculatePath(PositionVector startPosition, PositionVector endPosition);
boolean willCarCrash(int carIndex, PositionVector position);
boolean willCarCrash(int carIndex, PositionVector position) throws PositionVectorNotValid;
}