|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectPrintGame.Direction
class representing a direction and provides constants for using and writing directions
Field Summary | |
static java.lang.String |
DIR_DOWN
|
static java.lang.String |
DIR_LEFT
|
static java.lang.String |
DIR_RIGHT
|
static java.lang.String |
DIR_UP
|
protected int |
direction_
current direction |
static int |
DIRECTION_DOWN
|
static int |
DIRECTION_LEFT
|
static int |
DIRECTION_RIGHT
|
static int |
DIRECTION_UP
|
protected static java.util.Random |
random_generator_
static random generator for generating random directions |
Constructor Summary | |
Direction()
constructor sets the direction to a non legal value and creates a new random generator |
|
Direction(Direction dir)
|
Method Summary | |
int |
getDirection()
method returns the current direction |
void |
invertDirection()
method turns the direction around 180° |
protected boolean |
isLegalDirection(int direction)
method detects whether the direction is legal or not |
protected void |
randomizeDirection()
method generates a new direction - every direction is possible |
void |
randomizeNextDirection()
method generates a new direction but not the invertet direction |
void |
setDirection(int direction)
method to set the current direction |
java.lang.String |
toString()
standard toString method for debugging |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final int DIRECTION_UP
public static final int DIRECTION_RIGHT
public static final int DIRECTION_DOWN
public static final int DIRECTION_LEFT
public static final java.lang.String DIR_UP
public static final java.lang.String DIR_RIGHT
public static final java.lang.String DIR_DOWN
public static final java.lang.String DIR_LEFT
protected int direction_
protected static java.util.Random random_generator_
Constructor Detail |
public Direction()
public Direction(Direction dir)
Method Detail |
protected boolean isLegalDirection(int direction)
direction
- direction constant to check
public int getDirection() throws IllegalDirectionException
IllegalDirectionException
- thrown if the current direction is not legalpublic void setDirection(int direction) throws IllegalDirectionException
direction
- new direction constant
IllegalDirectionException
- thrown if the new direction constant is not legalpublic void invertDirection() throws IllegalDirectionException
IllegalDirectionException
- thrown if the current direction is not legalpublic void randomizeNextDirection() throws IllegalDirectionException
IllegalDirectionException
- thrown if the current direction is not legalprotected void randomizeDirection()
public java.lang.String toString()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |