SHARE
TWEET

Untitled

a guest Aug 13th, 2017 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.domain;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5.  
  6. public class WhiteKing extends GamePiece {
  7.    
  8.     public WhiteKing(GameBoard aBoard, Coordinate aTile) {
  9.         super(PieceType.WHITE_KING, aTile, aBoard);
  10.     }
  11.  
  12.     @Override
  13.     public List<Coordinate> candidateMoves() {
  14.         List<Coordinate> candidates = new ArrayList<Coordinate>();
  15.  
  16.         candidates = calculateStraightMoves(candidates);
  17.         candidates = calculateDiagonalMoves(candidates);
  18.  
  19.         return candidates;
  20.     }
  21.  
  22.     private List<Coordinate> calculateStraightMoves(List<Coordinate> aCandidates) {
  23.         aCandidates.add(super.position().oneSpaceForward());
  24.         aCandidates.add(super.position().oneSpaceBackward());
  25.         aCandidates.add(super.position().oneSpaceLeft());
  26.         aCandidates.add(super.position().oneSpaceRight());
  27.  
  28.         return aCandidates;
  29.     }
  30.  
  31.     private List<Coordinate> calculateDiagonalMoves(List<Coordinate> aCandidates) {
  32.         aCandidates.add(super.position().oneSpaceForwardLeft());
  33.         aCandidates.add(super.position().oneSpaceForwardRight());
  34.         aCandidates.add(super.position().oneSpaceBackwardLeft());
  35.         aCandidates.add(super.position().oneSpaceBackwardRight());
  36.  
  37.         return aCandidates;
  38.     }
  39.    
  40.     @Override
  41.     protected GamePiece constructNewPieceToMove(Coordinate aNewLocation) {
  42.         return new WhiteKing(board, aNewLocation);
  43.     }
  44.  
  45. }
RAW Paste Data
Top