From 2b2834f47a692cf68139cd580d9889a75e642cfa Mon Sep 17 00:00:00 2001 From: Leonardo Brandenberger Date: Thu, 24 Mar 2022 17:26:44 +0100 Subject: [PATCH 1/4] added all javadocs to class Track --- src/main/java/ch/zhaw/pm2/racetrack/Track.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/ch/zhaw/pm2/racetrack/Track.java b/src/main/java/ch/zhaw/pm2/racetrack/Track.java index 79f5e70..e4eeaa7 100644 --- a/src/main/java/ch/zhaw/pm2/racetrack/Track.java +++ b/src/main/java/ch/zhaw/pm2/racetrack/Track.java @@ -66,8 +66,8 @@ public class Track implements TrackSpecification { private ConfigSpecification.SpaceType finishTyp; /** - * Initialize a Track from the given track file. - * + * Initializes the Track from the given track File including the cars. + * Throws an corresponding error if one of the conditions are not met to build a track. * @param trackFile Reference to a file containing the track data * @throws FileNotFoundException if the given track file could not be found * @throws InvalidTrackFormatException if the track file contains invalid data (no tracklines, ...) @@ -123,10 +123,11 @@ public class Track implements TrackSpecification { } } - //TODO: THIS + //TODO: SAVE Finish somewhere maybe? /** + * Checks if there is a finish line in the track if there is no finish line found throws a Exception. * - * @throws InvalidTrackFormatException + * @throws InvalidTrackFormatException if there is no finish Line found in the track */ private void findFinish() throws InvalidTrackFormatException { for (int i = 0; i < track.size(); i++) { From badec0d16fedabca2ec584d1ea626026ae9d26d4 Mon Sep 17 00:00:00 2001 From: Andrin Fassbind Date: Thu, 24 Mar 2022 17:50:03 +0100 Subject: [PATCH 2/4] removed PositionVectorNotValidException.java --- .../ch/zhaw/pm2/racetrack/UserInterface.java | 1 - .../java/ch/zhaw/pm2/racetrack/GameTest.java | 16 ++++------------ 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/main/java/ch/zhaw/pm2/racetrack/UserInterface.java b/src/main/java/ch/zhaw/pm2/racetrack/UserInterface.java index b6c9e02..3ef450a 100644 --- a/src/main/java/ch/zhaw/pm2/racetrack/UserInterface.java +++ b/src/main/java/ch/zhaw/pm2/racetrack/UserInterface.java @@ -25,7 +25,6 @@ public class UserInterface { public UserInterface(String welcomeText) { textIO = TextIoFactory.getTextIO(); textTerminal = textIO.getTextTerminal(); - textTerminal.println(welcomeText + "\n"); } diff --git a/src/test/java/ch/zhaw/pm2/racetrack/GameTest.java b/src/test/java/ch/zhaw/pm2/racetrack/GameTest.java index a956fac..4aca662 100644 --- a/src/test/java/ch/zhaw/pm2/racetrack/GameTest.java +++ b/src/test/java/ch/zhaw/pm2/racetrack/GameTest.java @@ -112,22 +112,14 @@ class GameTest { @Test void carTurnCorrect() { - try { - game.doCarTurn(RIGHT); - Assertions.assertEquals(new PositionVector(1, 0), game.getCarVelocity(0)); - } catch (PositionVectorNotValidException positionVectorNotValidException) { - positionVectorNotValidException.printStackTrace(); - } + game.doCarTurn(RIGHT); + Assertions.assertEquals(new PositionVector(1, 0), game.getCarVelocity(0)); } @Test void carCrash() { - try { - game.doCarTurn(PositionVector.Direction.UP); - Assertions.assertTrue(game.onlyOneCarLeft()); - } catch (PositionVectorNotValidException positionVectorNotValidException) { - positionVectorNotValidException.printStackTrace(); - } + game.doCarTurn(PositionVector.Direction.UP); + Assertions.assertTrue(game.onlyOneCarLeft()); } } From 95ef0b9d767ee3c82f3a14a1869806ce5a44400b Mon Sep 17 00:00:00 2001 From: Andrin Fassbind Date: Thu, 24 Mar 2022 18:33:29 +0100 Subject: [PATCH 3/4] refactor gametest --- src/main/java/ch/zhaw/pm2/racetrack/Game.java | 1 - src/main/java/ch/zhaw/pm2/racetrack/Track.java | 2 +- src/test/java/ch/zhaw/pm2/racetrack/GameTest.java | 8 ++++---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/ch/zhaw/pm2/racetrack/Game.java b/src/main/java/ch/zhaw/pm2/racetrack/Game.java index 05698c0..b7715fa 100644 --- a/src/main/java/ch/zhaw/pm2/racetrack/Game.java +++ b/src/main/java/ch/zhaw/pm2/racetrack/Game.java @@ -290,7 +290,6 @@ public class Game implements GameSpecification { * If the car is passing the finishline in the correct direction, the car will gain a winpoint. * @param start the startposition of the car * @param finish the expected finishpositon of the car after the move - * @param carIndex of the current player. */ private void calculateWinner(PositionVector start, PositionVector finish, int carIndex) { List path = calculatePath(start, finish); diff --git a/src/main/java/ch/zhaw/pm2/racetrack/Track.java b/src/main/java/ch/zhaw/pm2/racetrack/Track.java index f7eee0e..37c1493 100644 --- a/src/main/java/ch/zhaw/pm2/racetrack/Track.java +++ b/src/main/java/ch/zhaw/pm2/racetrack/Track.java @@ -284,7 +284,7 @@ public class Track implements TrackSpecification { } } - return null; + return ConfigSpecification.SpaceType.WALL; } /** diff --git a/src/test/java/ch/zhaw/pm2/racetrack/GameTest.java b/src/test/java/ch/zhaw/pm2/racetrack/GameTest.java index 4aca662..77b9148 100644 --- a/src/test/java/ch/zhaw/pm2/racetrack/GameTest.java +++ b/src/test/java/ch/zhaw/pm2/racetrack/GameTest.java @@ -133,7 +133,7 @@ class GameTest { @Test void winner() { - game = new Game(new interFace("Test",new Integer[]{0,2,1},new PositionVector.Direction[]{RIGHT, + game = new Game(new interFace("Test",new Integer[]{0,2,0},new PositionVector.Direction[]{RIGHT, RIGHT, RIGHT, NONE, @@ -178,7 +178,7 @@ class GameTest { @Test void crashA() { - game = new Game(new interFace("Test",new Integer[]{0,2,2},new PositionVector.Direction[]{UP})); + game = new Game(new interFace("Test",new Integer[]{0,1,1},new PositionVector.Direction[]{UP})); game.initPhase(); Assertions.assertEquals("b",game.gamePhase()); } @@ -187,8 +187,8 @@ class GameTest { private class interFace extends UserInterface { - private final PositionVector.Direction[] directions; - private final Integer[] instructions; + private PositionVector.Direction[] directions; + private Integer[] instructions; private int pointerDir,pointerInstruction; From 2366f798ca1577cc6037071e52e1c51b419d7ba2 Mon Sep 17 00:00:00 2001 From: Leonardo Brandenberger Date: Fri, 25 Mar 2022 08:58:34 +0100 Subject: [PATCH 4/4] added all javadocs to class Track --- src/main/java/ch/zhaw/pm2/racetrack/Track.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/ch/zhaw/pm2/racetrack/Track.java b/src/main/java/ch/zhaw/pm2/racetrack/Track.java index 63db2db..0f36149 100644 --- a/src/main/java/ch/zhaw/pm2/racetrack/Track.java +++ b/src/main/java/ch/zhaw/pm2/racetrack/Track.java @@ -123,10 +123,11 @@ public class Track implements TrackSpecification { } } - //TODO: THIS /** - * @throws InvalidTrackFormatException + * Determines the finish line and saves it in a list, throws an Exception if none is found. + * + * @throws InvalidTrackFormatException thrown if no finish line is found */ private void findFinish() throws InvalidTrackFormatException { for (int i = 0; i < track.size(); i++) { @@ -271,10 +272,11 @@ public class Track implements TrackSpecification { * If the location is outside the track bounds, it is considered a wall. * * @param position The coordinates of the position to examine - * @return The type of track position at the given location + * @return The type of space at the desired position */ @Override public Config.SpaceType getSpaceType(PositionVector position) { + //TODO: TO BE DELETED?? //isPositionVectorOnTrack(position); Should be used but we are not allowed to change method head. We don't use function anyway char charAtPosition = track.get(position.getY()).charAt(position.getX()); ConfigSpecification.SpaceType[] spaceTypes = ConfigSpecification.SpaceType.values(); @@ -284,7 +286,7 @@ public class Track implements TrackSpecification { } } - return ConfigSpecification.SpaceType.WALL; + return null; } /**