Beispiel #1
0
  public boolean neighbor(EdgeLocation el) {
    el = el.getNormalizedLocation();

    switch (getNormalizedLocation().getDir()) {
      case NW:
        if (el.getHexLoc().compareTo(getHexLoc()) == 0 && el.getDir() == EdgeDirection.N)
          return true;
        if (el.getHexLoc().compareTo(new HexLocation(getHexLoc().getX() + 1, getHexLoc().getY()))
                == 0
            && (el.getDir() == EdgeDirection.NW || el.getDir() == EdgeDirection.N)) return true;
        if (el.getHexLoc()
                    .compareTo(new HexLocation(getHexLoc().getX() + 1, getHexLoc().getY() - 1))
                == 0
            && el.getDir() == EdgeDirection.NW) return true;
        return false;
      case NE:
        if (el.getHexLoc().compareTo((getHexLoc())) == 0 && el.getDir() == EdgeDirection.N)
          return true;
        if (el.getHexLoc().compareTo(new HexLocation(getHexLoc().getX() + 1, getHexLoc().getY()))
                == 0
            && (el.getDir() == EdgeDirection.N || el.getDir() == EdgeDirection.NW)) return true;
        if (el.getHexLoc()
                    .compareTo(new HexLocation(getHexLoc().getX() + 1, getHexLoc().getY() - 1))
                == 0
            && el.getDir() == EdgeDirection.NW) return true;
        return false;
      default:
        if (el.getHexLoc().compareTo(getHexLoc()) == 0
            && (el.getDir() == EdgeDirection.NW || el.getDir() == EdgeDirection.NE)) return true;
        if (el.getHexLoc().compareTo(new HexLocation(getHexLoc().getX() - 1, getHexLoc().getY()))
                == 0
            && el.getDir() == EdgeDirection.NE) return true;
        if (el.getHexLoc()
                    .compareTo(new HexLocation(getHexLoc().getX() + 1, getHexLoc().getY() - 1))
                == 0
            && el.getDir() == EdgeDirection.NW) return true;
        return false;
    }
  }
Beispiel #2
0
 public int compareTo(EdgeLocation edgeLocation) {
   if (edgeLocation.getHexLoc().compareTo(getHexLoc()) == 0)
     if (getDir() == edgeLocation.getDir()) return 0;
   return -1;
 }