Merge remote-tracking branch 'origin/main'

This commit is contained in:
romanschenk37 2022-03-25 20:57:19 +01:00
commit e2c6b5cb49
4 changed files with 30 additions and 23 deletions

View File

@ -47,7 +47,7 @@ import java.util.Scanner;
*
* <p>All lines must have the same length, used to initialize the grid width).
* Beginning empty lines are skipped.
* The the tracks ends with the first empty line or the file end.<br>
* The tracks ends with the first empty line or the file end.<br>
* An {@link InvalidTrackFormatException} is thrown, if
* <ul>
* <li>not all track lines have the same length</li>
@ -67,7 +67,8 @@ public class Track implements TrackSpecification {
/**
* 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.
* Throws a 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, ...)
@ -95,7 +96,7 @@ public class Track implements TrackSpecification {
}
/**
* Goes through the track ArrayList and determines the locations of each cars and initializes them at the location.
* Goes through the track ArrayList and determines the locations of each car and initializes them at the location.
*
* @throws InvalidTrackFormatException is thrown if a car is found more than once inside the track.
*/
@ -377,11 +378,11 @@ public class Track implements TrackSpecification {
int x = startPosition.getX();
int y = startPosition.getY();
// Relative Distance (x & y axis) between end- and starting position
// Relative Distance (x & y-axis) between end- and starting position
int diffX = endPosition.getX() - startPosition.getX();
int diffY = endPosition.getY() - startPosition.getY();
// Absolute distance (x & y axis) between end- and starting position
// Absolute distance (x & y-axis) between end- and starting position
int distX = Math.abs(diffX);
int distY = Math.abs(diffY);
@ -394,7 +395,7 @@ public class Track implements TrackSpecification {
int diagonalStepX, diagonalStepY;
int distanceSlowAxis, distanceFastAxis;
if (distX > distY) {
// x axis is the 'fast' direction
// x-axis is the 'fast' direction
parallelStepX = dirX;
parallelStepY = 0; // parallel step only moves in x direction
diagonalStepX = dirX;
@ -402,7 +403,7 @@ public class Track implements TrackSpecification {
distanceSlowAxis = distY;
distanceFastAxis = distX;
} else {
// y axis is the 'fast' direction
// y-axis is the 'fast' direction
parallelStepX = 0;
parallelStepY = dirY; // parallel step only moves in y direction
diagonalStepX = dirX;
@ -434,9 +435,10 @@ public class Track implements TrackSpecification {
* This method will check if a car is passing the finish line.
* If the car is passing the finish line in the wrong direction, the car will lose a winpoint.
* If the car is passing the finish line in the correct direction, the car will gain a winpoint.
*
* @param start the start position of the car
* @param finish the expected finishpositon of the car after the move
* @return Number of new Winpoints for the current player.
* @param finish the expected finish position of the car after the move
* @return Number of new winpoints for the current player.
*/
public int calculateNewWinPoints(PositionVector start, PositionVector finish) {
List<PositionVector> path = calculatePointsOnPath(start, finish);

View File

@ -98,8 +98,8 @@ public class PathFinderMoveStrategy implements MoveStrategy{
* Combination of position and velocity
*/
public static class State{
PositionVector position;
PositionVector velocity;
final PositionVector position;
final PositionVector velocity;
/**
* Constructor of State
@ -126,13 +126,13 @@ public class PathFinderMoveStrategy implements MoveStrategy{
*/
public class PossibleMove {
// List of all directions used for the previous moves and the direction of the current move (the highest Index).
List<PositionVector.Direction> directions;
final List<PositionVector.Direction> directions;
// Position of the car bevor the move is executed
PositionVector startPosition;
final PositionVector startPosition;
// Position of the car after the move is executed
PositionVector endPosition;
final PositionVector endPosition;
// Velocity of the car after the move is executed
PositionVector endVelocity;
final PositionVector endVelocity;
/**
* Constructor of PossibleMove

View File

@ -5,7 +5,7 @@ import ch.zhaw.pm2.racetrack.UserInterface;
/**
* Let the user decide the next move.
* Therefore it uses the UserInterface class to ask for a direction.
* Therefore, it uses the UserInterface class to ask for a direction.
*/
public class UserMoveStrategy implements MoveStrategy {
private final UserInterface userInterface;
@ -18,6 +18,11 @@ public class UserMoveStrategy implements MoveStrategy {
this.carID = carID;
}
/**
* Uses the interface to determine which move the user takes.
*
* @return the next taken move as Direction
*/
@Override
public Direction nextMove() {
return userInterface.selectDirection(carIndex, carID);

View File

@ -202,13 +202,13 @@ class GameTest {
}
/**
* This Class is used to communicate with the UserInterface. It overrides crucial methods and returns an instruction based on the instructions data field.
* This Class is used to communicate with the UserInterface. It overrides crucial methods and returns an instruction based on the instructions' data field.
* To implement the right instructions the user has to be aware of the game sequence.
*/
private class interFace extends UserInterface {
private PositionVector.Direction[] directions;
private Integer[] instructions;
private final PositionVector.Direction[] directions;
private final Integer[] instructions;
private int pointerDir,pointerInstruction;