Exemplo n.º 1
0
 private void moveGamePiece() {
   Position newPosition = findNewPosition();
   while (position2Piece.containsKey(newPosition)) {
     newPosition = findNewPosition();
   }
   moveTo(newPosition, gamePiece);
 }
Exemplo n.º 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();
 }
Exemplo n.º 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);
    }
  }
Exemplo n.º 4
0
 private void clear() {
   piece2Position.clear();
   position2Piece.clear();
 }
Exemplo n.º 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);
 }