java.lang.Object | +--Animal
Represents an animal.
| Field Summary | |
(package private) int |
column
The column of the field containing this animal (do not modify!) |
(package private) static java.util.Random |
randomNumberGenerator
|
(package private) int |
row
The row of the field containing this animal (do not modify!) |
| Constructor Summary | |
Animal(Model model,
int row,
int column)
Constructor for objects of class Animal. |
|
| Method Summary | |
(package private) boolean |
canMove(int direction)
Determines whether this animal can move one step in the given direction. |
(package private) int |
decideMove()
Decides what direction to move next. |
(package private) int |
distance(int direction)
Finds the distance to the first visible thing in the given direction, starting from this animal's current position. |
(package private) int |
look(int direction)
Finds the first visible thing in the given direction, starting from this animal's current position. |
(package private) static int |
random(int min,
int max)
Utility method to choose a random integer from min to max, inclusive. |
| Methods inherited from class java.lang.Object |
|
| Field Detail |
int column
static java.util.Random randomNumberGenerator
int row
| Constructor Detail |
public Animal(Model model,
int row,
int column)
model - the model (needed to use Model.look and Model.move methodsrow - the row of the field in which to place this animalcolumn - the column of the field in which to place this animal| Method Detail |
boolean canMove(int direction)
If we extend this program to allow multiple rabbits or multiple foxes, we should disallow an animal moving onto another animal of the same type.
direction - the direction in which to consider movingint decideMove()
int distance(int direction)
direction - the direction in which to lookint look(int direction)
direction - the direction in which to look
static int random(int min,
int max)
min - the minimum value to be returnedmax - the maximum value to be returned