java.lang.Object | +--Model
Creates and maintains a "field" for the rabbit and fox, and sets up a number of methods to be used by animals. This class, rather than the Animal class, is in charge of letting animals move and look around--this makes it harder for an animal to "cheat" by knowing things it shouldn't know, or making moves it shouldn't be allowed to make.
| Field Summary | |
(package private) static int |
BUSH
Indicates a bush |
(package private) static int |
E
Represents the direction EAST |
(package private) static int |
EDGE
Indicates the edge of the playing field |
(package private) static int |
FOX
Indicates a fox |
(package private) boolean |
gameIsOver
Flag to tell when the game ends |
(package private) static int |
MAX_DIRECTION
The largest int representing a direction |
(package private) int |
MAX_NUMBER_OF_STEPS
The number of turns the rabbit has to survive in order to win |
(package private) static int |
MIN_DIRECTION
The smallest int representing a direction |
(package private) static int |
N
Represents the direction NORTH |
(package private) static int |
NE
Represents the direction NORTHEAST |
(package private) static int |
NW
Represents the direction NORTHWEST |
(package private) static int |
RABBIT
Indicates a rabbit |
(package private) boolean |
rabbitIsAlive
Flag used to end the game when the fox wins |
(package private) static int |
S
Represents the direction SOUTH |
(package private) static int |
SE
Represents the direction SOUTHEAST |
(package private) static int |
STAY
Represents the direction "right here" |
(package private) int |
stepsTaken
The number of turns taken so far in the game |
(package private) static int |
SW
Represents the direction SOUTHWEST |
(package private) static int |
W
Represents the direction WEST |
| Constructor Summary | |
(package private) |
Model(java.lang.Object[][] field)
Constructs a model that uses the given field. |
| Method Summary | |
(package private) void |
allowMoves()
Gives the rabbit a chance to move, then gives the fox a chance to move. |
(package private) static int |
columnChange(int direction)
Determines how moving in the given direction affects the column number. |
(package private) int |
distance(int row,
int column,
int direction)
Determines the distance to the nearest thing, or to the edge of the field, looking in a given direction. |
(package private) boolean |
legalLocation(int row,
int column)
Determines whether the given row and column numbers represent a legal location in the field. |
(package private) int |
look(int row,
int column,
int direction)
Determines what can be seen from a given location, looking in a given direction. |
(package private) void |
populate()
Puts a rabbit, a fox, and some bushes in the field. |
(package private) static int |
random(int min,
int max)
Utility method to choose a random integer from min to max, inclusive. |
(package private) void |
reset()
Sets up a new hunt. |
(package private) static int |
rowChange(int direction)
Determines how moving in the given direction affects the row number. |
(package private) static int |
turn(int direction,
int number)
Given a direction and a number of times to make 1/8 turn clockwise, return the resultant direction. |
| Methods inherited from class java.lang.Object |
|
| Field Detail |
static final int BUSH
static final int E
static final int EDGE
static final int FOX
boolean gameIsOver
static final int MAX_DIRECTION
final int MAX_NUMBER_OF_STEPS
static final int MIN_DIRECTION
static final int N
static final int NE
static final int NW
static final int RABBIT
boolean rabbitIsAlive
static final int S
static final int SE
static final int STAY
int stepsTaken
static final int SW
static final int W
| Constructor Detail |
Model(java.lang.Object[][] field)
field - the field to be used by the model| Method Detail |
void allowMoves()
static int columnChange(int direction)
direction - the direction in which to move
int distance(int row,
int column,
int direction)
row - the row of the object doing the lookingcolumn - the column of the object doing the lookingdirection - the direction of the look
boolean legalLocation(int row,
int column)
row - the row numbercolumn - the column number
int look(int row,
int column,
int direction)
row - the row of the object doing the lookingcolumn - the column of the object doing the lookingdirection - the direction of the lookvoid populate()
static int random(int min,
int max)
min - the smallest number to be returnedmax - the largest number to be returnedvoid reset()
static int rowChange(int direction)
direction - the direction in which to move
static int turn(int direction,
int number)
direction - the initial directionnumber - of 45 degree turns clockwise