5
Difficulty: Easy
We copied a lot of code in our last activity. Let's use subclassing to make better use of code.

RedKangaroo

September 27, 2009 at 08:18 pm - by oddron
0

Play Submission

Remarks

To minimise the amount of duplicated code, I created a class Animal and I moved all the common parts of Wombat, Kangaroo, and RedKangaroo into Animal. Common parts would be things like canMove() and move(). I then made Wombat, Kangaroo, and RedKangaroo subclasses of Animal, with each class overriding act() and whatever else it had to override. Wombats turn left and run in counter-clockwise loops. Red Kangaroos turn right and run in clockwise loops. Kangaroos frequently turn at random. All three animals occasionally make a random turn so that they can explore the entire map. The world also randomly adds leaves as it runs.