Class Animal

java.lang.Object
  |
  +--Animal

public class Animal
extends java.lang.Object

Represents an animal.

Version:
October 12, 2001
Author:
David Matuszek

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
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

column

int column
The column of the field containing this animal (do not modify!)

randomNumberGenerator

static java.util.Random randomNumberGenerator

row

int row
The row of the field containing this animal (do not modify!)
Constructor Detail

Animal

public Animal(Model model,
              int row,
              int column)
Constructor for objects of class Animal.
Parameters:
model - the model (needed to use Model.look and Model.move methods
row - the row of the field in which to place this animal
column - the column of the field in which to place this animal
Method Detail

canMove

boolean canMove(int direction)
Determines whether this animal can move one step in the given direction. An animal cannot move off the edge of the array or onto a bush, but it can move onto another animal.

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.

Parameters:
direction - the direction in which to consider moving
Returns:
true if the move is possible

decideMove

int decideMove()
Decides what direction to move next.
Returns:
the desired direction

distance

int distance(int direction)
Finds the distance to the first visible thing in the given direction, starting from this animal's current position.
Parameters:
direction - the direction in which to look
Returns:
the distance to the object seen

look

int look(int direction)
Finds the first visible thing in the given direction, starting from this animal's current position.
Parameters:
direction - the direction in which to look
Returns:
the object seen

random

static int random(int min,
                  int max)
Utility method to choose a random integer from min to max, inclusive.
Parameters:
min - the minimum value to be returned
max - the maximum value to be returned
Returns:
a random integer N, where min <= N <= max


Generated by BlueJ