added javadocs in InvalidFileFormatException, InvalidTrackFormatException, Track, UserInterface and Main. Enhanced Game methods
This commit is contained in:
parent
2f6b2d2e41
commit
bb0e52b8bd
|
@ -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<String> 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);
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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 + ")";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ import java.util.Scanner;
|
|||
* There are 1 to {@link Config#MAX_CARS} allowed. </li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>All lines must have the same length, used to initialize the grid width).
|
||||
* <p>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.<br>
|
||||
* 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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue