fixing function quit in usermovestrategy
This commit is contained in:
parent
c43a08cef9
commit
52f9eb7629
|
@ -2,6 +2,7 @@ package ch.zhaw.pm2.racetrack;
|
|||
|
||||
import ch.zhaw.pm2.racetrack.given.GameSpecification;
|
||||
import ch.zhaw.pm2.racetrack.strategy.*;
|
||||
import org.hamcrest.core.IsInstanceOf;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
|
@ -240,17 +241,25 @@ public class Game implements GameSpecification {
|
|||
* @return the ID of the winning car return null if there is no winner.
|
||||
*/
|
||||
public String gamePhase() {
|
||||
while (carsMoving() && getWinner() == NO_WINNER) {
|
||||
boolean quit = false;
|
||||
while (carsMoving() && getWinner() == NO_WINNER && !quit) {
|
||||
userInterface.printInformation("Player " + track.getCar(currentCarIndex).getID() + "'s turn!");
|
||||
userInterface.printTrack(track);
|
||||
Direction direction;
|
||||
direction = track.getCar(currentCarIndex).getMoveStrategy().nextMove();
|
||||
if (direction == null) {
|
||||
track.getCar(currentCarIndex).setMoveStrategy(new DoNotMoveStrategy());
|
||||
direction = track.getCar(currentCarIndex).getMoveStrategy().nextMove();
|
||||
if(track.getCar(currentCarIndex).getMoveStrategy() instanceof UserMoveStrategy){
|
||||
quit = true;
|
||||
direction = Direction.NONE;
|
||||
} else {
|
||||
track.getCar(currentCarIndex).setMoveStrategy(new DoNotMoveStrategy());
|
||||
direction = track.getCar(currentCarIndex).getMoveStrategy().nextMove();
|
||||
}
|
||||
}
|
||||
doCarTurn(direction);
|
||||
switchToNextActiveCar();
|
||||
}
|
||||
userInterface.printInformation("The game has finished!");
|
||||
userInterface.printTrack(track);
|
||||
int indexWinner = getWinner();
|
||||
if (indexWinner == NO_WINNER) {
|
||||
|
|
Loading…
Reference in New Issue