示例#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);
 }