|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object wyvern.lib.Direction
Encapsulates the cardinal game directions (n, s, e, w, ne, nw ,se, sw). Contains various utilities for converting directions to strings, Points and so on.
Nested Class Summary | |
static interface |
Direction.Dirs
You can implement this interface to get syntactic access to the Direction constants (NORTH, SOUTH, etc.) |
Field Summary | |
static int |
DOWN
|
static int |
E
|
static int |
EAST
|
static int |
ILLEGAL_DIR
|
static int |
N
|
static int |
NE
|
static int |
NONE
|
static int |
NORTH
|
static int |
NW
|
static Point |
POINT_EAST
|
static Point |
POINT_NE
|
static Point |
POINT_NORTH
|
static Point |
POINT_NW
|
static Point |
POINT_SE
|
static Point |
POINT_SOUTH
|
static Point |
POINT_SW
|
static Point |
POINT_WEST
|
static int |
S
|
static int |
SE
|
static int |
SOUTH
|
static int |
SW
|
static int |
UP
|
static int |
W
|
static int |
WEST
|
Constructor Summary | |
Direction()
|
Method Summary | |
static boolean |
cardinalDirection(int dir)
Returns true if the passed direction is one of the eight cardinal directions (n,s,e,w,ne,nw,sw,se). |
static int |
computeClosestDirection(Point src,
Point dest)
Figures out the nearest cardinal direction to the specified direction. |
static int |
computeDirection(Point p1,
Point p2)
Computes the relative direction of one point to another. |
protected static void |
createDirectionTables()
Establishes all the direction commands we recognize, for checking the arguments to "move" or "go". |
static java.lang.String |
dirToLongString(int dir)
Converts a direction constant to a user-readable string. |
static java.lang.String |
dirToString(int dir)
Converts a direction constant to a string that can be used as a movement command. |
static int |
getDir(Point p)
Turns a movement Point (with offsets -1,0,1) into a direction |
static int |
getDirection(int xoffset,
int yoffset)
Returns the direction for the specified offsets. |
static int |
getDirection(Point offsets)
Returns the direction for the specified offsets. |
static java.lang.String |
getDirString(int xoffset,
int yoffset)
Returns the direction for the specified offsets. |
static java.lang.String |
getDirString(Point offsets)
Returns the direction for the specified offsets. |
static Point |
getNextMove(Point p,
int dir)
Returns the next Point if you go in the passed direction |
static java.lang.String |
getSuffix(int direction)
Return the suffix associated with the image-file naming convention for the specified direction. |
static Point |
getXYOffsets(int dir)
Turns a movement direction into x & y offsets. |
static void |
main(java.lang.String[] args)
Test. |
static int |
oppositeOf(int direction)
Return opposite direction (e.g., N -> S) |
static int |
parseDirection(java.lang.String dir)
Figures out what direction the user specified from the string. |
static int |
randomDirection()
Returns a random cardinal direction. |
static int |
rotateLeft(int direction)
Return point counter-clockwise to this. |
static int |
rotateRight(int direction)
Return direction clockwise to this one. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int ILLEGAL_DIR
public static final int NONE
public static final int N
public static final int NORTH
public static final int S
public static final int SOUTH
public static final int E
public static final int EAST
public static final int W
public static final int WEST
public static final int NE
public static final int NW
public static final int SE
public static final int SW
public static final int UP
public static final int DOWN
public static final Point POINT_NORTH
public static final Point POINT_SOUTH
public static final Point POINT_EAST
public static final Point POINT_WEST
public static final Point POINT_NE
public static final Point POINT_NW
public static final Point POINT_SE
public static final Point POINT_SW
Constructor Detail |
public Direction()
Method Detail |
public static java.lang.String getSuffix(int direction)
public static java.lang.String dirToString(int dir)
dir
- the direction to convertpublic static java.lang.String dirToLongString(int dir)
dir
- the direction to convert
public static int oppositeOf(int direction)
direction
- direction to reversepublic static int rotateLeft(int direction)
direction
- direction to rotatepublic static int rotateRight(int direction)
direction
- direction to rotatepublic static int getDir(Point p)
p
- contains offsets
public static Point getXYOffsets(int dir)
dir
- the direction to move
public static Point getNextMove(Point p, int dir)
p
- square to move fromdir
- the direction to move
public static int parseDirection(java.lang.String dir)
dir
- a string (e.g. "northwest", "left", "s", "down" )
protected static void createDirectionTables()
public static java.lang.String getDirString(int xoffset, int yoffset)
xoffset
- 1, 0 or -1yoffset
- 1, 0 or -1
java.lang.IllegalArgumentException
- if the offsets are invalidpublic static java.lang.String getDirString(Point offsets)
offsets
- a Point whose x & y specify one of the 8
points around (0,0).
java.lang.IllegalArgumentException
- if the offsets are invalidpublic static int getDirection(int xoffset, int yoffset)
xoffset
- 1, 0 or -1yoffset
- 1, 0 or -1
java.lang.IllegalArgumentException
- if the offsets are invalidpublic static int getDirection(Point offsets)
offsets
- a Point whose x & y specify one of the 8 points
around (0,0).
java.lang.IllegalArgumentException
- if the offsets are invalidpublic static boolean cardinalDirection(int dir)
dir
- the direction to test
public static int computeDirection(Point p1, Point p2)
p1
- the start pointp2
- the end point
public static int randomDirection()
public static int computeClosestDirection(Point src, Point dest)
src
- start pointdest
- end point
public static void main(java.lang.String[] args)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |