2 1/17: Fish Feeding Frenzy
Due: 1/17 at 11:59 PM.
You must follow the directory structure and naming conventions outlined in the notes on Git. In particular, all your work for this assignment must be in a directory named assign02 within your pairNN repository (where NN is your pair number).
Language: class/0.
2.1 Finger exercises: Designing classes
Design classes to represent ternary trees of numbers. (A ternary tree is like a binary tree, except nodes have three subtrees instead of two.)
In this representation, values are stored at both nodes and leaves, and there are no empty trees. Note that this means that trees with two or three values cannot be represented.
Implement the methods size (how many numbers are there in the tree), sum (sums all the numbers in the tree), prod (computes the product of all the numbers in the tree), contains? (is a given number in the tree?), map (apply a function to every number in the tree), and max (what’s the largest number in the tree?).
2.2 Fish Feeding Frenzy
In honor of last semester’s Hungry Henry, this week you’ll design and develop a simple version of the game Fishy!. In this game, you start off as a small fish in a pond of smaller and larger fish, and to survive you must eat the smaller fish while avoiding being eaten by the larger ones. Move your fish with the arrow keys. You win when you are larger than all the other fish in the pond.
Develop one or more classes to represent the player and the background fish.
Allow the player fish to move the the arrow keys
Correctly handle fish movement. Background fish swim onto the screen from one side, and leave on the other. The player fish loops around, so when it exits from one side it re-enters the screen on the other.
Determine when the player fish can eat another fish.
Determine when the player has been eaten by another fish.
End the game when the player is the largest fish in the pond.
Allow the player to grow based on how many fish it has eaten (and how big they are).
Be sure to test your game’s behavior thoroughly.
Add inertia: Once you let go of an arrow key, the player fish should not stop immediately, but should drift along until it slows to a halt.
Add more inertia: The bigger the player gets, the harder it should become to accelerate the fish...and also to stop!
Keep score: eating bigger fish is worth more than eating several little fish.
Add size snacks: eating these can make the player’s size grow immediately.
Add speed snacks: eating these can give the player a speed boost.
Remember – you will be graded for your program design, not making a cool video game. So whatever you add, make sure it’s well-designed.