implemented Movestrategies in Game.java
This commit is contained in:
		
							parent
							
								
									06ad28fbe8
								
							
						
					
					
						commit
						9b6908ef47
					
				| 
						 | 
					@ -57,7 +57,7 @@ public class Game implements GameSpecification {
 | 
				
			||||||
                        track.getCar(i).setMoveStrategy(new DoNotMoveStrategy()); //TODO: add Arguments
 | 
					                        track.getCar(i).setMoveStrategy(new DoNotMoveStrategy()); //TODO: add Arguments
 | 
				
			||||||
                        break;
 | 
					                        break;
 | 
				
			||||||
                    case 2:
 | 
					                    case 2:
 | 
				
			||||||
                        track.getCar(i).setMoveStrategy(new UserMoveStrategy()); //TODO: add Arguments
 | 
					                        track.getCar(i).setMoveStrategy(new UserMoveStrategy(userInterface, i, track.getCarId(i))); //TODO: add Arguments
 | 
				
			||||||
                        break;
 | 
					                        break;
 | 
				
			||||||
                    case 3:
 | 
					                    case 3:
 | 
				
			||||||
                        track.getCar(i).setMoveStrategy(new MoveListStrategy()); //TODO: add Arguments
 | 
					                        track.getCar(i).setMoveStrategy(new MoveListStrategy()); //TODO: add Arguments
 | 
				
			||||||
| 
						 | 
					@ -174,20 +174,21 @@ public class Game implements GameSpecification {
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        else {
 | 
					        else {
 | 
				
			||||||
            track.moveCar(currentCarIndex);
 | 
					            track.moveCar(currentCarIndex);
 | 
				
			||||||
 | 
					            calculateWinner(track.getCarPos(currentCarIndex), track.getCar(currentCarIndex).nextPosition(), currentCarIndex);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void gamePhase() {
 | 
					    public int gamePhase() {
 | 
				
			||||||
        do{
 | 
					        do{
 | 
				
			||||||
            userInterface.printTrack(track);
 | 
					            userInterface.printTrack(track);
 | 
				
			||||||
            track.getCar(currentCarIndex).getMoveStrategy(); //TODO Movestrategy berücksichtigen ??
 | 
					            Direction direction = track.getCar(currentCarIndex).getMoveStrategy().nextMove();
 | 
				
			||||||
            Direction direction = userInterface.selectDirection(currentCarIndex, track.getCarId(currentCarIndex));
 | 
					 | 
				
			||||||
            doCarTurn(direction);
 | 
					            doCarTurn(direction);
 | 
				
			||||||
            if(getWinner() != NO_WINNER) {
 | 
					            int winner = getWinner();
 | 
				
			||||||
                return;
 | 
					            if(winner != NO_WINNER) {
 | 
				
			||||||
 | 
					                return winner;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        } while (!allCarsCrashed());
 | 
					        } while (!allCarsCrashed());
 | 
				
			||||||
 | 
					        return NO_WINNER;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -9,8 +9,7 @@ public class Main {
 | 
				
			||||||
        Game game = new Game(userInterface);
 | 
					        Game game = new Game(userInterface);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if(game.initPhase()){
 | 
					        if(game.initPhase()){
 | 
				
			||||||
            game.gamePhase();
 | 
					            int winner = game.gamePhase();
 | 
				
			||||||
            int winner = game.getWinner();
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,7 @@
 | 
				
			||||||
package ch.zhaw.pm2.racetrack.strategy;
 | 
					package ch.zhaw.pm2.racetrack.strategy;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import ch.zhaw.pm2.racetrack.PositionVector;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import static ch.zhaw.pm2.racetrack.PositionVector.Direction;
 | 
					import static ch.zhaw.pm2.racetrack.PositionVector.Direction;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
| 
						 | 
					@ -9,7 +11,6 @@ public class DoNotMoveStrategy implements MoveStrategy {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public Direction nextMove() {
 | 
					    public Direction nextMove() {
 | 
				
			||||||
        // TODO: implementation
 | 
					        return PositionVector.Direction.NONE;
 | 
				
			||||||
        throw new UnsupportedOperationException();
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,15 +1,24 @@
 | 
				
			||||||
package ch.zhaw.pm2.racetrack.strategy;
 | 
					package ch.zhaw.pm2.racetrack.strategy;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import ch.zhaw.pm2.racetrack.PositionVector.Direction;
 | 
					import ch.zhaw.pm2.racetrack.PositionVector.Direction;
 | 
				
			||||||
 | 
					import ch.zhaw.pm2.racetrack.UserInterface;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Let the user decide the next move.
 | 
					 * Let the user decide the next move.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
public class UserMoveStrategy implements MoveStrategy {
 | 
					public class UserMoveStrategy implements MoveStrategy {
 | 
				
			||||||
 | 
					    private UserInterface userInterface;
 | 
				
			||||||
 | 
					    private int carIndex;
 | 
				
			||||||
 | 
					    private char carID;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public UserMoveStrategy(UserInterface userInterface, int carIndex, char carID) {
 | 
				
			||||||
 | 
					        this.userInterface = userInterface;
 | 
				
			||||||
 | 
					        this.carIndex = carIndex;
 | 
				
			||||||
 | 
					        this.carID = carID;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public Direction nextMove() {
 | 
					    public Direction nextMove() {
 | 
				
			||||||
        // TODO: implementation
 | 
					        return userInterface.selectDirection(carIndex, carID);
 | 
				
			||||||
        throw new UnsupportedOperationException();
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue