Hi Ho Cherry O Design
Objects
Spinner
Domain:
One Cherry, Two Cherries, Three Cherries, Four Cherries,
Dog, Bird, Spill
Operations
Spin
GetResult
Bucket
Domain
Number of cherries
Operations
Add Cherries(n)
number of cherries += n
if (number of cherries > MAX_CHERRIES)
number of cherries = MAX_CHERRIES
Dump - removes the cherries and returns the number removed
SubtractCherries(n)
GetCherryCount
Tree:
Domain
Number of cherries
Operations
AddCherries
RemoveCherries
GetCherrieCount
Player
Domain
name
age
Bucket
Tree
Operations
GetName
GetAge
GetCherriesInBucket
TakeTurn(spinner)
Algorithm:
spin = spinner.Spin()
if the spin is pick n cherries
tree.RemoveCherries(n)
bucket.AddCherries(n)
if the spin is bird or dog
bucket.RemoveCherries(2)
tree.AddCherries(2)
else
count = bucket.Dump()
tree.AddCherries(count)
if number of cherries = MAX_CHERRIES
print "Hi Ho Cherry-O!"
Main Algorithm
ActivePlayer = player0
While the game is not finished
//Let active player take turn based on spin
player[activePlayer].TakeTurn(spinner);
finshed = (player[activePlayer].GetCherriesInBucket() == MAX_CHERRIES)
AcitvePlayer = nextPlayer;