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.given.GameSpecification;
 | 
				
			||||||
import ch.zhaw.pm2.racetrack.strategy.*;
 | 
					import ch.zhaw.pm2.racetrack.strategy.*;
 | 
				
			||||||
 | 
					import org.hamcrest.core.IsInstanceOf;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.io.File;
 | 
					import java.io.File;
 | 
				
			||||||
import java.io.FileNotFoundException;
 | 
					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.
 | 
					     * @return the ID of the winning car return null if there is no winner.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public String gamePhase() {
 | 
					    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);
 | 
					            userInterface.printTrack(track);
 | 
				
			||||||
            Direction direction;
 | 
					            Direction direction;
 | 
				
			||||||
            direction = track.getCar(currentCarIndex).getMoveStrategy().nextMove();
 | 
					            direction = track.getCar(currentCarIndex).getMoveStrategy().nextMove();
 | 
				
			||||||
            if (direction == null) {
 | 
					            if (direction == null) {
 | 
				
			||||||
                track.getCar(currentCarIndex).setMoveStrategy(new DoNotMoveStrategy());
 | 
					                if(track.getCar(currentCarIndex).getMoveStrategy() instanceof UserMoveStrategy){
 | 
				
			||||||
                direction = track.getCar(currentCarIndex).getMoveStrategy().nextMove();
 | 
					                    quit = true;
 | 
				
			||||||
 | 
					                    direction = Direction.NONE;
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    track.getCar(currentCarIndex).setMoveStrategy(new DoNotMoveStrategy());
 | 
				
			||||||
 | 
					                    direction = track.getCar(currentCarIndex).getMoveStrategy().nextMove();
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            doCarTurn(direction);
 | 
					            doCarTurn(direction);
 | 
				
			||||||
            switchToNextActiveCar();
 | 
					            switchToNextActiveCar();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        userInterface.printInformation("The game has finished!");
 | 
				
			||||||
        userInterface.printTrack(track);
 | 
					        userInterface.printTrack(track);
 | 
				
			||||||
        int indexWinner = getWinner();
 | 
					        int indexWinner = getWinner();
 | 
				
			||||||
        if (indexWinner == NO_WINNER) {
 | 
					        if (indexWinner == NO_WINNER) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue