This is what the design might look like for a Wombat style scenario
where the wombat walks around and eats leaves while avoiding rocks. This is a
very simple example, but it is intended to give you the feel for what is expected in
a design. The outline format is intentional as it helps to organize things. You should
consider doing that in your own design.
- Wombat Class
- Member Data
- leavesEaten - this is an integer counting how many leaves have been eaten.
- direction - this integer stores a number for the direction that the wombat is
heading.
- Methods
- void act() - This method will check if the wombat is on the same square as a
leaf. It if it, it eats the leaf. If it isn't, it will check if it can move. If it can
then it does. If it can't, it will turn left.
- void turnLeft() - This method turns the wombat to the left. This involves changing the
direction member variable and calling setRotation to alter the image orientation.
- boolean canMove() - This method checks to see if the wombat is able to move forward.
It returns a boolean telling whether ot not it can. The check itself involves seeing if
the move would take it out of bounds or if it would put it on top of a rock.
- void eatLeaf() - tells the wombat to eat one leaf at the current location. It also
increments the number of leaves eaten.
- boolean foundLeaf() - Returns a boolen telling whether to not the wombat is standing on
a square with a leaf.
- void move() - Move the wombat forward one square in the current direction using
setLocation.
- Leaf Class - This class doesn't store anything or have any methods that do anything.
It just sits in the world and waits until a Wombat comes up to eat it.
- Rock Class - This class doesn't store anything or have any methods that do anything.
It is placed in the world and blocks the path of any Wombat that runs into it.