Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
3b76abf760
|
@ -6,6 +6,7 @@ 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;
|
||||||
|
@ -34,9 +35,7 @@ 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<>();
|
File selectedTrack = config.getTrackDirectory().listFiles()[userInterface.selectOption("Select Track file", Arrays.asList(config.getTrackDirectory().list()))];
|
||||||
|
|
||||||
File selectedTrack = config.getTrackDirectory().listFiles()[userInterface.selectOption("Select Track file", tracks)];
|
|
||||||
try {
|
try {
|
||||||
selectTrack(selectedTrack);
|
selectTrack(selectedTrack);
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
|
|
|
@ -33,6 +33,9 @@ class CarTest {
|
||||||
car = new Car(DEFAULT_ID, new PositionVector(DEFAULT_X, DEFAULT_Y));
|
car = new Car(DEFAULT_ID, new PositionVector(DEFAULT_X, DEFAULT_Y));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks getID
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
void getID() {
|
void getID() {
|
||||||
assertEquals(DEFAULT_ID, car.getID());
|
assertEquals(DEFAULT_ID, car.getID());
|
||||||
|
|
|
@ -45,6 +45,9 @@ class GameTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests if Carindex is correct
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
void getCurrentCarIndex() {
|
void getCurrentCarIndex() {
|
||||||
Assertions.assertEquals(CAR_INDEX_ONE, game.getCurrentCarIndex());
|
Assertions.assertEquals(CAR_INDEX_ONE, game.getCurrentCarIndex());
|
||||||
|
@ -52,34 +55,52 @@ class GameTest {
|
||||||
Assertions.assertEquals(CAR_INDEX_TWO, game.getCurrentCarIndex());
|
Assertions.assertEquals(CAR_INDEX_TWO, game.getCurrentCarIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if CarId matches char given in trackfile
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
void getCarId() {
|
void getCarId() {
|
||||||
Assertions.assertEquals('a', game.getCarId(0));
|
Assertions.assertEquals('a', game.getCarId(0));
|
||||||
Assertions.assertEquals('b', game.getCarId(1));
|
Assertions.assertEquals('b', game.getCarId(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks initial carposition
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
void getCarPosition() {
|
void getCarPosition() {
|
||||||
Assertions.assertEquals(new PositionVector(24, 22), game.getCarPosition(0));
|
Assertions.assertEquals(new PositionVector(24, 22), game.getCarPosition(0));
|
||||||
Assertions.assertEquals(new PositionVector(24, 24), game.getCarPosition(1));
|
Assertions.assertEquals(new PositionVector(24, 24), game.getCarPosition(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if initial carvelocity is 0,0
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
void getCarVelocity() {
|
void getCarVelocity() {
|
||||||
Assertions.assertEquals(new PositionVector(0, 0), game.getCarVelocity(0));
|
Assertions.assertEquals(new PositionVector(0, 0), game.getCarVelocity(0));
|
||||||
Assertions.assertEquals(new PositionVector(0, 0), game.getCarVelocity(1));
|
Assertions.assertEquals(new PositionVector(0, 0), game.getCarVelocity(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks initial winner
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
void getWinner() {
|
void getWinner() {
|
||||||
Assertions.assertEquals(NO_WINNER, game.getWinner());
|
Assertions.assertEquals(NO_WINNER, game.getWinner());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks correct inital state
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
void onlyOneCarLeft() {
|
void onlyOneCarLeft() {
|
||||||
Assertions.assertFalse(game.onlyOneCarLeft());
|
Assertions.assertFalse(game.onlyOneCarLeft());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if cars are able to move
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
void carsMoving() {
|
void carsMoving() {
|
||||||
Assertions.assertTrue(game.carsMoving());
|
Assertions.assertTrue(game.carsMoving());
|
||||||
|
@ -109,6 +130,9 @@ class GameTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if car does change velocity specified by direction input
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
void carTurnCorrect() {
|
void carTurnCorrect() {
|
||||||
game.doCarTurn(RIGHT);
|
game.doCarTurn(RIGHT);
|
||||||
|
@ -131,6 +155,9 @@ class GameTest {
|
||||||
class Play {
|
class Play {
|
||||||
private Game game;
|
private Game game;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method will start a game instance on the challenge track. Car a uses MoveListStrategy. Car b uses DoNotMoveStrategy
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
void winner() {
|
void winner() {
|
||||||
game = new Game(new interFace("Test",new Integer[]{0,2,0},new PositionVector.Direction[]{RIGHT,
|
game = new Game(new interFace("Test",new Integer[]{0,2,0},new PositionVector.Direction[]{RIGHT,
|
||||||
|
@ -176,6 +203,9 @@ class GameTest {
|
||||||
Assertions.assertEquals("a",game.gamePhase());
|
Assertions.assertEquals("a",game.gamePhase());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Will start a game instance where car a does crash.
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
void crashA() {
|
void crashA() {
|
||||||
game = new Game(new interFace("Test",new Integer[]{0,1,0},new PositionVector.Direction[]{UP}), new Config());
|
game = new Game(new interFace("Test",new Integer[]{0,1,0},new PositionVector.Direction[]{UP}), new Config());
|
||||||
|
@ -183,6 +213,9 @@ class GameTest {
|
||||||
Assertions.assertEquals("b",game.gamePhase());
|
Assertions.assertEquals("b",game.gamePhase());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks that a car cant win before finishing a complete round around the track.
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
void passFinishLineInWrongDirection() {
|
void passFinishLineInWrongDirection() {
|
||||||
game = new Game(new interFace("Test",new Integer[]{1,0,1},new PositionVector.Direction[]{LEFT,NONE,NONE,RIGHT,RIGHT}), new Config());
|
game = new Game(new interFace("Test",new Integer[]{1,0,1},new PositionVector.Direction[]{LEFT,NONE,NONE,RIGHT,RIGHT}), new Config());
|
||||||
|
@ -190,6 +223,9 @@ class GameTest {
|
||||||
Assertions.assertEquals("a",game.gamePhase());
|
Assertions.assertEquals("a",game.gamePhase());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does wait 10 seconds before closing the textio.
|
||||||
|
*/
|
||||||
@AfterEach
|
@AfterEach
|
||||||
void cleanUp() {
|
void cleanUp() {
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue