You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
532 B

  1. package de.hsfulda.pmuw.oop;
  2. public enum NeighborPosition {
  3. NORTH(-1, 0),
  4. SOUTH(1, 0),
  5. EAST(0, 1),
  6. WEST(0, -1),
  7. NORTH_EAST(-1, 1),
  8. SOUTH_EAST(1, 1),
  9. SOUTH_WEST(1, -1),
  10. NORTH_WEST(-1, -1);
  11. private final int rowOffset;
  12. private final int columnOffset;
  13. NeighborPosition(int rowOffset, int columnOffset) {
  14. this.rowOffset = rowOffset;
  15. this.columnOffset = columnOffset;
  16. }
  17. int getIndex(int row, int column, int rowSize) {
  18. return (((row + rowOffset) * rowSize) + column + columnOffset);
  19. }
  20. }