Example #1
0
  /**
   * Returns the Direction represented by the given letter.
   *
   * @param theLetter The letter.
   * @return the Direction represented by the given letter, or CENTER if no Direction is represented
   *     by the given letter.
   */
  public static Direction valueOf(final char theLetter) {
    Direction result = CENTER;

    for (final Direction direction : Direction.values()) {
      if (direction.letter() == theLetter) {
        result = direction;
        break;
      }
    }

    return result;
  }
Example #2
0
 public void moveBack() throws IllegalMove {
   try {
     Point newHead = moves.remove(moves.size() - 1);
     Direction dir = Direction.getDirection(headX, headY, newHead.x, newHead.y);
     resetConnection(headX, headY, dir);
     resetConnection(newHead.x, newHead.y, dir.opposite());
     headX = newHead.x;
     headY = newHead.y;
     gameOver = false;
   } catch (Exception e) {
     e.printStackTrace();
     throw new IllegalMove();
   }
 }
 /**
  * Gets the directed waypoint NodeStatus associated with a particular direction.
  *
  * @param d the d
  * @return the directed waypoint
  */
 public static final NodeStatus getDirectedWaypoint(Direction d) {
   return NodeStatus.valueOf("WAYPOINT_" + d.getAbbreviation());
 }
Example #4
0
 /**
  * Unmark a connection from point (x, y)
  *
  * @param x x coordinate
  * @param y y coordinate
  * @param dir direction from the point
  * @return true if the operation was successful
  */
 protected boolean resetConnection(int x, int y, Direction dir) {
   if (!isInBounds(x, y)) return false;
   field[getX(x)][getY(y)] &= ((1 << 8) - 1) - (1 << dir.ordinal());
   return true;
 }