Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.05 KB | None | 0 0
  1. // FIXME::: CHANGE HERE FOR VIDEO!!!!
  2.     public List<Position> getValidPositions() {
  3.         List<Position> list = initialisePositions();
  4.         list.removeIf(p -> !isPositionAllowed(p));
  5.         return list;
  6.     }
  7.  
  8.     private List<Position> initialisePositions() {
  9.         List<Position> list = new ArrayList<>();
  10.         Position C = new Position(r, c);
  11.         Position N = new Position(r - 1, c);
  12.         Position NE = new Position(r - 1, c + 1);
  13.         Position E = new Position(r, c + 1);
  14.         Position SE = new Position(r + 1, c + 1);
  15.         Position S = new Position(r + 1, c);
  16.         Position SW = new Position(r + 1, c - 1);
  17.         Position W = new Position(r, c - 1);
  18.         Position NW = new Position(r - 1, c - 1);
  19.  
  20.         list.addAll(Arrays.asList(C, N, NE, E, SE, S, SW, W, NW));
  21.         return list;
  22.     }
  23.  
  24.     private boolean isPositionAllowed(Position p) {
  25.         return p.getRow() >= 0 && p.getRow() < GameConstants.WORLDSIZE &&
  26.                 p.getColumn() >= 0 && p.getColumn() < GameConstants.WORLDSIZE;
  27.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement