diff --git a/src/main/java/ch/zhaw/pm2/racetrack/Game.java b/src/main/java/ch/zhaw/pm2/racetrack/Game.java index 8f6fd94..da453c7 100644 --- a/src/main/java/ch/zhaw/pm2/racetrack/Game.java +++ b/src/main/java/ch/zhaw/pm2/racetrack/Game.java @@ -6,6 +6,7 @@ import ch.zhaw.pm2.racetrack.strategy.*; import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import static ch.zhaw.pm2.racetrack.PositionVector.Direction; @@ -35,9 +36,7 @@ public class Game implements GameSpecification { public boolean initPhase() { if (config.getTrackDirectory().listFiles().length > 0) { List tracks = new ArrayList<>(); - for (String file : config.getTrackDirectory().list()) { - tracks.add(file); - } + tracks.addAll(Arrays.asList(config.getTrackDirectory().list())); File selectedTrack = config.getTrackDirectory().listFiles()[userInterface.selectOption("Select Track file", tracks)]; try { @@ -62,22 +61,11 @@ public class Game implements GameSpecification { int moveStrategie = userInterface.selectOption( "Select Strategy for Car " + carIndex + " (" + track.getCarId(carIndex) + ")", moveStrategies); switch (moveStrategie) { - case 0: - moveStrategy = new DoNotMoveStrategy(); - break; - case 1: - moveStrategy = new UserMoveStrategy(userInterface, carIndex, track.getCarId(carIndex)); - break; - case 2: - moveStrategy = getMoveListStrategy(selectedTrack, carIndex); - break; - case 3: - moveStrategy = getPathFollowerMoveStrategy(selectedTrack, carIndex); - - break; - case 4: - moveStrategy = new PathFinderMoveStrategy(track, carIndex); - break; + case 0 -> moveStrategy = new DoNotMoveStrategy(); + case 1 -> moveStrategy = new UserMoveStrategy(userInterface, carIndex, track.getCarId(carIndex)); + case 2 -> moveStrategy = getMoveListStrategy(selectedTrack, carIndex); + case 3 -> moveStrategy = getPathFollowerMoveStrategy(selectedTrack, carIndex); + case 4 -> moveStrategy = new PathFinderMoveStrategy(track, carIndex); } } selectMoveStrategy(car, moveStrategy); diff --git a/src/main/java/ch/zhaw/pm2/racetrack/InvalidFileFormatException.java b/src/main/java/ch/zhaw/pm2/racetrack/InvalidFileFormatException.java index ee9699e..6cebf5a 100644 --- a/src/main/java/ch/zhaw/pm2/racetrack/InvalidFileFormatException.java +++ b/src/main/java/ch/zhaw/pm2/racetrack/InvalidFileFormatException.java @@ -1,7 +1,7 @@ package ch.zhaw.pm2.racetrack; /** - * Class for Exception when invalid file format is used. + * Class for Exception when an invalid file format is used. */ public class InvalidFileFormatException extends Exception { public InvalidFileFormatException() { diff --git a/src/main/java/ch/zhaw/pm2/racetrack/InvalidTrackFormatException.java b/src/main/java/ch/zhaw/pm2/racetrack/InvalidTrackFormatException.java index 4d102f9..d4af349 100644 --- a/src/main/java/ch/zhaw/pm2/racetrack/InvalidTrackFormatException.java +++ b/src/main/java/ch/zhaw/pm2/racetrack/InvalidTrackFormatException.java @@ -4,11 +4,17 @@ package ch.zhaw.pm2.racetrack; * Class for Exception when invalid track format is used. */ public class InvalidTrackFormatException extends Exception { + public InvalidTrackFormatException() { + super(); + } + + /** + * Constructor that is used when an error message is given with the exception. + * + * @param errorMessage is the message to be displayed + */ public InvalidTrackFormatException(String errorMessage) { super(errorMessage); } - public InvalidTrackFormatException() { - super(); - } } diff --git a/src/main/java/ch/zhaw/pm2/racetrack/Main.java b/src/main/java/ch/zhaw/pm2/racetrack/Main.java index c426124..fde1053 100644 --- a/src/main/java/ch/zhaw/pm2/racetrack/Main.java +++ b/src/main/java/ch/zhaw/pm2/racetrack/Main.java @@ -3,8 +3,19 @@ package ch.zhaw.pm2.racetrack; import java.util.ArrayList; import java.util.List; +/** + * Class containing the main method + * + * @author Roman Schenk + */ public class Main { - + /** + * Method creating the game and initializing the Configs and Userinterface. + * Starts and initializes a new game until the user decides to stop the game. + * In charge of closing the user interface when user decides to stop the game + * + * @param args no arguments needed + */ public static void main(String[] args) { UserInterface userInterface = new UserInterface("Hello and Welcome to Racetrack by Team02-\"AngryNerds\""); Config config = new Config(); diff --git a/src/main/java/ch/zhaw/pm2/racetrack/PositionVector.java b/src/main/java/ch/zhaw/pm2/racetrack/PositionVector.java index a33302e..10209a3 100644 --- a/src/main/java/ch/zhaw/pm2/racetrack/PositionVector.java +++ b/src/main/java/ch/zhaw/pm2/racetrack/PositionVector.java @@ -7,8 +7,8 @@ package ch.zhaw.pm2.racetrack; * Created by mach 21.01.2020 */ public final class PositionVector { - private final int x; // horizontal component (position / velocity) - private final int y; // vertical component (position / velocity) + private int x; // horizontal component (position / velocity) + private int y; // vertical component (position / velocity) /** * Enum representing a direction on the track grid. @@ -33,7 +33,6 @@ public final class PositionVector { /** * Adds two PositionVectors (e.g. car position and velocity vector or two velocity vectors). - * * @param vectorA A position or velocity vector * @param vectorB A position or velocity vector * @return A new PositionVector holding the result of the addition. If both @@ -46,7 +45,6 @@ public final class PositionVector { /** * Subtracts two PositionVectors (e.g. car position and velocity vector or two velocity vectors). - * * @param vectorA A position or velocity vector * @param vectorB A position or velocity vector * @return A new PositionVector holding the result of the addition. If both @@ -60,7 +58,6 @@ public final class PositionVector { /** * Calculates the scalar product (Skalarprodukt) of two 2D vectors. The scalar product * multiplies the lengths of the parallel components of the vectors. - * * @param vectorA A position or velocity vector * @param vectorB A position or velocity vector * @return The scalar product (vectorA * vectorB). Since vectorA and @@ -78,7 +75,6 @@ public final class PositionVector { /** * Copy constructor - * * @param other */ public PositionVector(final PositionVector other) { @@ -113,6 +109,6 @@ public final class PositionVector { @Override public String toString() { - return "(X:" + this.x + ", Y:" + this.y + ")"; + return "(X:" + this.x + ", Y:" + this.y + ")"; } } diff --git a/src/main/java/ch/zhaw/pm2/racetrack/Track.java b/src/main/java/ch/zhaw/pm2/racetrack/Track.java index e1d0ca5..04ff87f 100644 --- a/src/main/java/ch/zhaw/pm2/racetrack/Track.java +++ b/src/main/java/ch/zhaw/pm2/racetrack/Track.java @@ -45,7 +45,7 @@ import java.util.Scanner; * There are 1 to {@link Config#MAX_CARS} allowed. * * - *

All lines must have the same length, used to initialize the grid width). + *

All lines must have the same length, used to initialize the grid width. * Beginning empty lines are skipped. * The tracks ends with the first empty line or the file end.
* An {@link InvalidTrackFormatException} is thrown, if @@ -122,7 +122,6 @@ public class Track implements TrackSpecification { } } } - } /** @@ -473,8 +472,6 @@ public class Track implements TrackSpecification { } break; } - - } return 0; } diff --git a/src/main/java/ch/zhaw/pm2/racetrack/UserInterface.java b/src/main/java/ch/zhaw/pm2/racetrack/UserInterface.java index 3ef450a..f1da9a6 100644 --- a/src/main/java/ch/zhaw/pm2/racetrack/UserInterface.java +++ b/src/main/java/ch/zhaw/pm2/racetrack/UserInterface.java @@ -8,7 +8,7 @@ import java.util.List; /** * Class representing the Userinterface. - * Used to get inputs from users via textio. + * Used to get inputs from users via text io. * * @author Roman Schenk */