You have been given a simulator for animals wandering around an environment. You need to define some animals for that simulation. Different kinds of animals will move in different ways and you are defining those differences. As the simulation runs, animals can die by ending up on the same location, in which case the simulator randomly selects one animal to survive the collision.
You have been given a lot of files to accompany this project. You can basically ignore all of them except Critter.java and Direction.java. The simulator will be responsible for moving the animals around, you just need to tell it what direction the animals want to go next.
Each of your classes will extend the Critter class. Critters move around in a world of finite size, but the word is toroidal (going off the end to the right brings you back to the left and vice versa; going off the end to the top brings you back to the bottom and vice versa).
There is also an interface in CritterInfo.java. An instance of this will be passed into the getMove() method, however it is completely optional (you may make use of it in your Wolf class if you wish, other animals do not need to use this parameter at all). Interfaces are discussed in detail in chapter 9 of the textbook and chapter 8 of the lab manual, but again, you do not need to know interfaces to complete this assignment.
You will be implementing five classes: Bird, Frog, Mouse, Turtle, and Wolf. These should each live in their own files which should not be part of a package. Create these class files and ensure they each extend the Critter class. Note: You are allowed to include a constructor for your classes if you want, although it must be a zero-argument constructors (one that takes no arguments).
At this point your code should compile and you can run the simulation with the command:
> java CritterMain
The simulation won't be very interesting; it will just appear as a series of dots and spaces, but that is expected.
Override the getChar() method in each animal's class to return first character of the animal's species. For example: B for Bird, F for Frog, etc. You can recompile your code at this point and now you should see letters where the spaces had been.
Animals should move around in the simulator and when they bump into each other (i.e. they occupy the same place) one will be deleted randomly. The removal of animals is done automatically by the simulator, but your animals each need to move in a certain pattern, described in the table below:
Class Movement
Bird Randomly selects one of the four directions (north, south, east, or west) each time.
Frog Picks a random direction, then moves three times in that direction before choosing a new random direction.
Mouse Moves west one step then north one step and repeats this west-north zig-zag pattern.
Turtle Walks south five steps, then wast five steps, the north five steps, then east five steps and repeats. This forms a clockwise box pattern.
Wolf You define this! Make it interesting for full credit!
You will need to override the getMove() method for each animal you've made to make these patterns. Note that each call to getMove() will make a single move, so animals that do things over a period of time will need to keep track of what they are doing with some internal state.
For example, the first time I call getMove() for a mouse, it will return west and the next call to getMove() will return north, and the next west, etc. These directions are defined in the Direction.java file as an enum. Enums are described in chapter 9 of the lab manual and Appendix C of the textbook, but you do not need to understand enums in detail to do this assignment, just a couple of details:
Referring to an enum is done by: EnumerationName.FIELD. For example, Direction.WEST or Direction.NORTH. These can be compared to each other with == and printed. The following code shows all you need to understand enums for this assignment:
Direction d = Direction.WEST;
if(d == Direction.WEST)
System.out.println(d); //prints WEST
Additional items:
You need to test this on your own! Here's some ideas: