From a723ea16ec82cb1397a0445de45e5e07dab5935e Mon Sep 17 00:00:00 2001 From: romanschenk37 <84532681+romanschenk37@users.noreply.github.com> Date: Fri, 18 Mar 2022 10:19:23 +0100 Subject: [PATCH] merge track into game and fix in initphase --- src/main/java/ch/zhaw/pm2/racetrack/Game.java | 12 ++++++------ src/main/java/ch/zhaw/pm2/racetrack/Main.java | 2 +- src/main/java/ch/zhaw/pm2/racetrack/Track.java | 1 - .../zhaw/pm2/racetrack/given/GameSpecification.java | 5 +++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/ch/zhaw/pm2/racetrack/Game.java b/src/main/java/ch/zhaw/pm2/racetrack/Game.java index 32f8787..0b7595f 100644 --- a/src/main/java/ch/zhaw/pm2/racetrack/Game.java +++ b/src/main/java/ch/zhaw/pm2/racetrack/Game.java @@ -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 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() { diff --git a/src/main/java/ch/zhaw/pm2/racetrack/Main.java b/src/main/java/ch/zhaw/pm2/racetrack/Main.java index 73da6d8..0817f16 100644 --- a/src/main/java/ch/zhaw/pm2/racetrack/Main.java +++ b/src/main/java/ch/zhaw/pm2/racetrack/Main.java @@ -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); diff --git a/src/main/java/ch/zhaw/pm2/racetrack/Track.java b/src/main/java/ch/zhaw/pm2/racetrack/Track.java index d2441bb..f3e51f0 100644 --- a/src/main/java/ch/zhaw/pm2/racetrack/Track.java +++ b/src/main/java/ch/zhaw/pm2/racetrack/Track.java @@ -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; diff --git a/src/main/java/ch/zhaw/pm2/racetrack/given/GameSpecification.java b/src/main/java/ch/zhaw/pm2/racetrack/given/GameSpecification.java index 3596335..c9148e5 100644 --- a/src/main/java/ch/zhaw/pm2/racetrack/given/GameSpecification.java +++ b/src/main/java/ch/zhaw/pm2/racetrack/given/GameSpecification.java @@ -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 calculatePath(PositionVector startPosition, PositionVector endPosition); - boolean willCarCrash(int carIndex, PositionVector position); + boolean willCarCrash(int carIndex, PositionVector position) throws PositionVectorNotValid; }