fixed typos in several classes
This commit is contained in:
parent
efe1e1f304
commit
d0da883795
|
@ -14,7 +14,7 @@ You will then be prompted to select a track file from the selection by entering
|
||||||
#### For each car that is taking part in the race a strategy has to be chosen there are the following options:
|
#### For each car that is taking part in the race a strategy has to be chosen there are the following options:
|
||||||
|
|
||||||
+ Do not move Strategy
|
+ Do not move Strategy
|
||||||
> This Strategy sets the car stationary, and it won't make any moves during the game staying at the startpoint indefinitely.
|
> This Strategy sets the car stationary, and it won't make any moves during the game staying at the start point indefinitely.
|
||||||
+ User Move Strategy
|
+ User Move Strategy
|
||||||
> The player is prompted for each move to make a choice the different choices you are able to take are as following:
|
> The player is prompted for each move to make a choice the different choices you are able to take are as following:
|
||||||
> > 1=down-left <br> 2=down<br> 3=down-right<br> 4=left<br> 5=no acceleration<br> 6=right <br> 7=up-left<br> 8=up<br> 9=up-right<br> it is also possible to leave the game when it is your turn by entering 10
|
> > 1=down-left <br> 2=down<br> 3=down-right<br> 4=left<br> 5=no acceleration<br> 6=right <br> 7=up-left<br> 8=up<br> 9=up-right<br> it is also possible to leave the game when it is your turn by entering 10
|
||||||
|
@ -42,4 +42,4 @@ We choose a simple branching model where all starting features got a branch and
|
||||||
|
|
||||||
## Class Diagramm
|
## Class Diagramm
|
||||||
This Class Diagramm is additional to the Class Diagramm given in the Anleitung.pdf<br><br>
|
This Class Diagramm is additional to the Class Diagramm given in the Anleitung.pdf<br><br>
|
||||||
![Classdiagramm of this program](./Klassendiagramm.svg)
|
![Classdiagram of this program](./Klassendiagramm.svg)
|
||||||
|
|
|
@ -97,7 +97,7 @@ public class Car implements CarSpecification {
|
||||||
/**
|
/**
|
||||||
* Set this Car position directly, regardless of current position and velocity.
|
* Set this Car position directly, regardless of current position and velocity.
|
||||||
* This should only be used by the game controller in rare cases to set the crash or winning position.
|
* This should only be used by the game controller in rare cases to set the crash or winning position.
|
||||||
* The next position is normaly automatically calculated and set in the {@link #move()} method.
|
* The next position is normally automatically calculated and set in the {@link #move()} method.
|
||||||
*
|
*
|
||||||
* @param position The new position to set the car directly to.
|
* @param position The new position to set the car directly to.
|
||||||
* @throws IllegalArgumentException if invalid PositionVector is given.
|
* @throws IllegalArgumentException if invalid PositionVector is given.
|
||||||
|
|
|
@ -6,7 +6,6 @@ import ch.zhaw.pm2.racetrack.strategy.*;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static ch.zhaw.pm2.racetrack.PositionVector.Direction;
|
import static ch.zhaw.pm2.racetrack.PositionVector.Direction;
|
||||||
|
@ -36,16 +35,15 @@ public class Game implements GameSpecification {
|
||||||
public boolean initPhase() {
|
public boolean initPhase() {
|
||||||
if (config.getTrackDirectory().listFiles().length > 0) {
|
if (config.getTrackDirectory().listFiles().length > 0) {
|
||||||
List<String> tracks = new ArrayList<>();
|
List<String> tracks = new ArrayList<>();
|
||||||
tracks.addAll(Arrays.asList(config.getTrackDirectory().list()));
|
|
||||||
|
|
||||||
File selectedTrack = config.getTrackDirectory().listFiles()[userInterface.selectOption("Select Track file", tracks)];
|
File selectedTrack = config.getTrackDirectory().listFiles()[userInterface.selectOption("Select Track file", tracks)];
|
||||||
try {
|
try {
|
||||||
selectTrack(selectedTrack);
|
selectTrack(selectedTrack);
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
userInterface.printInformation("There is an unexpected Error with the trackfile Path. Add trackfiles only to tracks path. Exit the Game and Fix the Problem");
|
userInterface.printInformation("There is an unexpected Error with the track file Path. Add track files only to tracks path. Exit the Game and Fix the Problem");
|
||||||
return false;
|
return false;
|
||||||
} catch (InvalidTrackFormatException e) {
|
} catch (InvalidTrackFormatException e) {
|
||||||
userInterface.printInformation("There is an unexpected Error with the trackfile. Format does not match specifications! Exit the Game and Fix the Problem");
|
userInterface.printInformation("There is an unexpected Error with the track file. Format does not match specifications! Exit the Game and Fix the Problem");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
List<String> moveStrategies = new ArrayList<>();
|
List<String> moveStrategies = new ArrayList<>();
|
||||||
|
|
|
@ -55,7 +55,7 @@ import java.util.Scanner;
|
||||||
* <li>the file contains more than {@link Config#MAX_CARS} cars</li>
|
* <li>the file contains more than {@link Config#MAX_CARS} cars</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* <p>The Track can return a String representing the current state of the race (including car positons)</p>
|
* <p>The Track can return a String representing the current state of the race (including car positions)</p>
|
||||||
*/
|
*/
|
||||||
public class Track implements TrackSpecification {
|
public class Track implements TrackSpecification {
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ public class Track implements TrackSpecification {
|
||||||
*
|
*
|
||||||
* @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 track lines, ...)
|
||||||
*/
|
*/
|
||||||
public Track(File trackFile) throws FileNotFoundException, InvalidTrackFormatException {
|
public Track(File trackFile) throws FileNotFoundException, InvalidTrackFormatException {
|
||||||
track = new ArrayList<>();
|
track = new ArrayList<>();
|
||||||
|
@ -185,7 +185,7 @@ public class Track implements TrackSpecification {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method that returns the finishline as a List
|
* Method that returns the finish line as a List
|
||||||
*
|
*
|
||||||
* @return finishLine List
|
* @return finishLine List
|
||||||
*/
|
*/
|
||||||
|
@ -224,7 +224,7 @@ public class Track implements TrackSpecification {
|
||||||
//Removes the Car at Current Pos
|
//Removes the Car at Current Pos
|
||||||
drawCharOnTrackIndicator(carPositionVector, ConfigSpecification.SpaceType.TRACK.getValue());
|
drawCharOnTrackIndicator(carPositionVector, ConfigSpecification.SpaceType.TRACK.getValue());
|
||||||
|
|
||||||
//Redraw finishline if Car was on finish-line Position
|
//Redraw finish line if Car was on finish-line Position
|
||||||
for (PositionVector finishLinePositionVector : finishLine) {
|
for (PositionVector finishLinePositionVector : finishLine) {
|
||||||
if (finishLinePositionVector.equals(carPositionVector)) {
|
if (finishLinePositionVector.equals(carPositionVector)) {
|
||||||
drawCharOnTrackIndicator(carPositionVector, finishTyp.getValue());
|
drawCharOnTrackIndicator(carPositionVector, finishTyp.getValue());
|
||||||
|
@ -347,7 +347,7 @@ public class Track implements TrackSpecification {
|
||||||
* If there is a crashed car at the position, {@link #CRASH_INDICATOR} is returned.
|
* If there is a crashed car at the position, {@link #CRASH_INDICATOR} is returned.
|
||||||
*
|
*
|
||||||
* @param y position Y-value
|
* @param y position Y-value
|
||||||
* @param x position X-vlaue
|
* @param x position X-value
|
||||||
* @param currentSpace char to return if no car is at position (x,y)
|
* @param currentSpace char to return if no car is at position (x,y)
|
||||||
* @return character representing position (x,y) on the track
|
* @return character representing position (x,y) on the track
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -53,7 +53,7 @@ public class PathFinderMoveStrategy implements MoveStrategy {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// while no PossibleMove crosses the finishline
|
// while no PossibleMove crosses the finish line
|
||||||
// every PossibleMove will be accelerated in each direction to find a Move which finishes.
|
// every PossibleMove will be accelerated in each direction to find a Move which finishes.
|
||||||
while (finishedMove == null) {
|
while (finishedMove == null) {
|
||||||
List<PossibleMove> newMoves = new ArrayList<>();
|
List<PossibleMove> newMoves = new ArrayList<>();
|
||||||
|
@ -164,9 +164,9 @@ public class PathFinderMoveStrategy implements MoveStrategy {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check if the finishline is crossed (in correct direction) if this move is executed
|
* check if the finish line is crossed (in correct direction) if this move is executed
|
||||||
*
|
*
|
||||||
* @return true if finishline will be crossed
|
* @return true if finish line will be crossed
|
||||||
*/
|
*/
|
||||||
public boolean finished() {
|
public boolean finished() {
|
||||||
return track.calculateNewWinPoints(startPosition, endPosition) == 1;
|
return track.calculateNewWinPoints(startPosition, endPosition) == 1;
|
||||||
|
|
|
@ -21,9 +21,9 @@ class CarTest {
|
||||||
Car car;
|
Car car;
|
||||||
|
|
||||||
// Default coordinates for tests
|
// Default coordinates for tests
|
||||||
int DEFAULT_X = 10;
|
final int DEFAULT_X = 10;
|
||||||
int DEFAULT_Y = 10;
|
final int DEFAULT_Y = 10;
|
||||||
char DEFAULT_ID = 'f';
|
final char DEFAULT_ID = 'f';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new Car Object and set Position to a defined Default Position
|
* Create a new Car Object and set Position to a defined Default Position
|
||||||
|
@ -50,7 +50,7 @@ class CarTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* - checks if the position of the car can be set and saved correctly with valid positions.
|
* - checks if the position of the car can be set and saved correctly with valid positions.
|
||||||
* - checks if an exception is throwed and position keeps unchanged if invalid coordinates are entered.
|
* - checks if an exception is thrown and position keeps unchanged if invalid coordinates are entered.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
void setPosition() {
|
void setPosition() {
|
||||||
|
@ -118,7 +118,7 @@ class CarTest {
|
||||||
int expectedNextPosX = DEFAULT_X;
|
int expectedNextPosX = DEFAULT_X;
|
||||||
int expectedNextPosY = DEFAULT_Y;
|
int expectedNextPosY = DEFAULT_Y;
|
||||||
|
|
||||||
//variables to save the acutal expected result of method getVelocity
|
//variables to save the actual expected result of method getVelocity
|
||||||
int expectedVelocityX = 0;
|
int expectedVelocityX = 0;
|
||||||
int expectedVelocityY = 0;
|
int expectedVelocityY = 0;
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ class GameTest {
|
||||||
private final int CAR_INDEX_TWO = 1;
|
private final int CAR_INDEX_TWO = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This nested Class tests if the game gets initiatet correctly.
|
* This nested Class tests if the game gets initiated correctly.
|
||||||
*/
|
*/
|
||||||
@Nested
|
@Nested
|
||||||
@DisplayName("Test correct Setup")
|
@DisplayName("Test correct Setup")
|
||||||
|
@ -123,7 +123,7 @@ class GameTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This nested Class tests a playtrough and implements a userInterface which pretends to be a real player.
|
* This nested Class tests a play trough and implements a userInterface which pretends to be a real player.
|
||||||
* At the end of every Test the Userinterface stays open for 10 more sec to visualize the game.
|
* At the end of every Test the Userinterface stays open for 10 more sec to visualize the game.
|
||||||
*/
|
*/
|
||||||
@Nested
|
@Nested
|
||||||
|
|
|
@ -60,7 +60,7 @@ public class TrackTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Converts Trackfile correctly to List<String>")
|
@DisplayName("Converts track file correctly to List<String>")
|
||||||
void checkTrack() {
|
void checkTrack() {
|
||||||
Track trackObj;
|
Track trackObj;
|
||||||
try {
|
try {
|
||||||
|
@ -153,8 +153,8 @@ public class TrackTest {
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Throw error if File is invalid")
|
@DisplayName("Throw error if File is invalid")
|
||||||
void invalidTrackFile() {
|
void invalidTrackFile() {
|
||||||
File testfile = new File(".\\src\\test\\InvalidTracks\\sameCar.txt");
|
File testFile = new File(".\\src\\test\\InvalidTracks\\sameCar.txt");
|
||||||
Assertions.assertThrows(InvalidTrackFormatException.class, () -> new Track(testfile));
|
Assertions.assertThrows(InvalidTrackFormatException.class, () -> new Track(testFile));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue