Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
e2c6b5cb49
|
@ -47,7 +47,7 @@ import java.util.Scanner;
|
||||||
*
|
*
|
||||||
* <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.
|
* 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
|
* An {@link InvalidTrackFormatException} is thrown, if
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>not all track lines have the same length</li>
|
* <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.
|
* 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
|
* @param trackFile Reference to a file containing the track data
|
||||||
* @throws FileNotFoundException if the given track file could not be found
|
* @throws FileNotFoundException if the given track file could not be found
|
||||||
* @throws InvalidTrackFormatException if the track file contains invalid data (no tracklines, ...)
|
* @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.
|
* @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 x = startPosition.getX();
|
||||||
int y = startPosition.getY();
|
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 diffX = endPosition.getX() - startPosition.getX();
|
||||||
int diffY = endPosition.getY() - startPosition.getY();
|
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 distX = Math.abs(diffX);
|
||||||
int distY = Math.abs(diffY);
|
int distY = Math.abs(diffY);
|
||||||
|
|
||||||
|
@ -394,7 +395,7 @@ public class Track implements TrackSpecification {
|
||||||
int diagonalStepX, diagonalStepY;
|
int diagonalStepX, diagonalStepY;
|
||||||
int distanceSlowAxis, distanceFastAxis;
|
int distanceSlowAxis, distanceFastAxis;
|
||||||
if (distX > distY) {
|
if (distX > distY) {
|
||||||
// x axis is the 'fast' direction
|
// x-axis is the 'fast' direction
|
||||||
parallelStepX = dirX;
|
parallelStepX = dirX;
|
||||||
parallelStepY = 0; // parallel step only moves in x direction
|
parallelStepY = 0; // parallel step only moves in x direction
|
||||||
diagonalStepX = dirX;
|
diagonalStepX = dirX;
|
||||||
|
@ -402,7 +403,7 @@ public class Track implements TrackSpecification {
|
||||||
distanceSlowAxis = distY;
|
distanceSlowAxis = distY;
|
||||||
distanceFastAxis = distX;
|
distanceFastAxis = distX;
|
||||||
} else {
|
} else {
|
||||||
// y axis is the 'fast' direction
|
// y-axis is the 'fast' direction
|
||||||
parallelStepX = 0;
|
parallelStepX = 0;
|
||||||
parallelStepY = dirY; // parallel step only moves in y direction
|
parallelStepY = dirY; // parallel step only moves in y direction
|
||||||
diagonalStepX = dirX;
|
diagonalStepX = dirX;
|
||||||
|
@ -431,12 +432,13 @@ public class Track implements TrackSpecification {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method will check if a car is passing the finishline.
|
* This method will check if a car is passing the finish line.
|
||||||
* If the car is passing the finishline in the wrong direction, the car will lose a winpoint.
|
* If the car is passing the finish line in the wrong direction, the car will lose a winpoint.
|
||||||
* If the car is passing the finishline in the correct direction, the car will gain a winpoint.
|
* If the car is passing the finish line 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 start the start position of the car
|
||||||
* @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) {
|
public int calculateNewWinPoints(PositionVector start, PositionVector finish) {
|
||||||
List<PositionVector> path = calculatePointsOnPath(start, finish);
|
List<PositionVector> path = calculatePointsOnPath(start, finish);
|
||||||
|
|
|
@ -98,8 +98,8 @@ public class PathFinderMoveStrategy implements MoveStrategy{
|
||||||
* Combination of position and velocity
|
* Combination of position and velocity
|
||||||
*/
|
*/
|
||||||
public static class State{
|
public static class State{
|
||||||
PositionVector position;
|
final PositionVector position;
|
||||||
PositionVector velocity;
|
final PositionVector velocity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor of State
|
* Constructor of State
|
||||||
|
@ -126,13 +126,13 @@ public class PathFinderMoveStrategy implements MoveStrategy{
|
||||||
*/
|
*/
|
||||||
public class PossibleMove {
|
public class PossibleMove {
|
||||||
// List of all directions used for the previous moves and the direction of the current move (the highest Index).
|
// 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
|
// Position of the car bevor the move is executed
|
||||||
PositionVector startPosition;
|
final PositionVector startPosition;
|
||||||
// Position of the car after the move is executed
|
// Position of the car after the move is executed
|
||||||
PositionVector endPosition;
|
final PositionVector endPosition;
|
||||||
// Velocity of the car after the move is executed
|
// Velocity of the car after the move is executed
|
||||||
PositionVector endVelocity;
|
final PositionVector endVelocity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor of PossibleMove
|
* Constructor of PossibleMove
|
||||||
|
|
|
@ -5,7 +5,7 @@ import ch.zhaw.pm2.racetrack.UserInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Let the user decide the next move.
|
* 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 {
|
public class UserMoveStrategy implements MoveStrategy {
|
||||||
private final UserInterface userInterface;
|
private final UserInterface userInterface;
|
||||||
|
@ -18,6 +18,11 @@ public class UserMoveStrategy implements MoveStrategy {
|
||||||
this.carID = carID;
|
this.carID = carID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uses the interface to determine which move the user takes.
|
||||||
|
*
|
||||||
|
* @return the next taken move as Direction
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Direction nextMove() {
|
public Direction nextMove() {
|
||||||
return userInterface.selectDirection(carIndex, carID);
|
return userInterface.selectDirection(carIndex, carID);
|
||||||
|
|
|
@ -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.
|
* To implement the right instructions the user has to be aware of the game sequence.
|
||||||
*/
|
*/
|
||||||
private class interFace extends UserInterface {
|
private class interFace extends UserInterface {
|
||||||
|
|
||||||
private PositionVector.Direction[] directions;
|
private final PositionVector.Direction[] directions;
|
||||||
private Integer[] instructions;
|
private final Integer[] instructions;
|
||||||
private int pointerDir,pointerInstruction;
|
private int pointerDir,pointerInstruction;
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue