- updated javadoc

- added playscenario to GameTest
This commit is contained in:
Andrin Fassbind
2022-03-25 11:06:08 +01:00
parent d038132055
commit 8581b7ee64
8 changed files with 49 additions and 16 deletions
@@ -271,7 +271,6 @@ public class Game implements GameSpecification {
currentCarIndex++;
}
} while (track.getCar(currentCarIndex).isCrashed());
// TODO: evtl andere Kapselung
}
/**
@@ -123,7 +123,6 @@ public class Track implements TrackSpecification {
}
}
//TODO: THIS
/**
* Determines the finish line and saves it in a list, throws an Exception if none is found.
@@ -5,10 +5,14 @@ import ch.zhaw.pm2.racetrack.PositionVector;
import static ch.zhaw.pm2.racetrack.PositionVector.Direction;
/**
* Do not accelerate in any direction.
* This Class represents the DoNotMoveStrategy.
*/
public class DoNotMoveStrategy implements MoveStrategy {
/**
* This method will be used to return the next Direction for the car.
* @return a NONE Direction
*/
@Override
public Direction nextMove() {
return PositionVector.Direction.NONE;
@@ -10,6 +10,11 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/**
* This Class represent the MoveListStrategy. The Directions returned by the
* nextMove() are written down in a List.
*
*/
public class MoveListStrategy implements MoveStrategy {
private final List<Direction> moveList;
@@ -21,6 +26,12 @@ public class MoveListStrategy implements MoveStrategy {
readFile(new File(path));
}
/**
* This Method will read in a File and checks line by line if the file contains a valid direction.
* If so the direction will be added to the moveList.
* @param trackFile the file to read in the directions
* @throws FileNotFoundException if the file does not exist.
*/
private void readFile(File trackFile) throws FileNotFoundException {
Scanner scanner = new Scanner(new FileInputStream(trackFile), StandardCharsets.UTF_8);
Direction[] directions = Direction.values();
@@ -35,6 +46,10 @@ public class MoveListStrategy implements MoveStrategy {
}
}
/**
* This method will be used to return the next Direction for the car.
* @return the next direction from the list. Returns null if the list is empty.
*/
@Override
public Direction nextMove() {
pointer += 1;
@@ -141,7 +141,7 @@ public class PathFinderMoveStrategy implements MoveStrategy{
@Override
public PositionVector.Direction nextMove() { //TODO check for crash and recreate movelist if crash
public PositionVector.Direction nextMove() {
pointer += 1;
if (pointer < moveList.size()) {
PositionVector.Direction direction = moveList.get(pointer);
@@ -5,6 +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.
*/
public class UserMoveStrategy implements MoveStrategy {
private final UserInterface userInterface;