예제 #1
0
 private void moveGamePiece() {
   Position newPosition = findNewPosition();
   while (position2Piece.containsKey(newPosition)) {
     newPosition = findNewPosition();
   }
   moveTo(newPosition, gamePiece);
 }
예제 #2
0
 private GameState invokeMove(Piece piece, Position position) {
   if (position2Piece.containsKey(position)) {
     throw new IllegalArgumentException("Position " + position + " is already occupied");
   }
   moveTo(position, piece);
   moveGamePiece();
   return createBoard();
 }
예제 #3
0
  @Override
  public void move(Piece piece, Position position, ResultHandler<GameState> resultHandler) {
    try {
      final Position oldPosition = piece2Position.get(piece);
      final GameState gameState = invokeMove(piece, position);
      resultHandler.result(gameState);

      nofityListeners(new Move(oldPosition, position));
    } catch (Exception e) {
      handleException(e, resultHandler);
    }
  }
예제 #4
0
 private void clear() {
   piece2Position.clear();
   position2Piece.clear();
 }
예제 #5
0
 private void moveTo(Position position, Piece piece) {
   Position oldPosition = piece2Position.get(piece);
   position2Piece.remove(oldPosition);
   position2Piece.put(position, piece);
   piece2Position.put(piece, position);
 }