예제 #1
0
 // dY > dX && dX > 0 == NORTH
 // dX > dY && dX > 0 == EAST
 // dY < dX && dX < 0 == SOUTH
 // dX < dY && dX < 0 == WEST
 public static Directions getDirectionByInteger(final int i, final int j) {
   for (Directions d : Directions.values()) {
     if (d.getX() == i && d.getY() == j) {
       return d;
     }
   }
   return null;
 }
  public Directions ParseDirectionArgument(Object Argument) throws Exception {
    if (Argument instanceof Double) {
      try {
        return (Directions.values()[(int) Math.round((Double) Argument)]);
      } catch (Throwable Throwable) {
        throw (new Exception("direction index out of range"));
      }
    }

    try {
      String Direction = (String) Argument;
      if (Direction.equalsIgnoreCase("down") || Direction.equalsIgnoreCase("negy")) {
        return (Directions.NegY);
      }

      if (Direction.equalsIgnoreCase("up") || Direction.equalsIgnoreCase("posy")) {
        return (Directions.PosY);
      }

      if (Direction.equalsIgnoreCase("north") || Direction.equalsIgnoreCase("negz")) {
        return (Directions.NegZ);
      }

      if (Direction.equalsIgnoreCase("south") || Direction.equalsIgnoreCase("posz")) {
        return (Directions.PosZ);
      }

      if (Direction.equalsIgnoreCase("west") || Direction.equalsIgnoreCase("negx")) {
        return (Directions.NegX);
      }

      if (Direction.equalsIgnoreCase("east") || Direction.equalsIgnoreCase("posx")) {
        return (Directions.PosX);
      }
    } catch (Throwable Throwable) {
      throw (new Exception("Test"));
    }

    throw (new Exception("invalid direction"));
  }