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