In this game, each of the four players has a tree and a basket. They are trying to pick the 10 cherries from their tree and place these cherries in their basket. To do this, each player in turn spins a spinner. If the spinner lands on a number, 1-4, the player takes that many cherries from their tree and places them in the basket.
The spinner can also land on a hazard. There are three hazards, a bird that takes two cherries from the player's basket and puts these cherries back on the tree, a dog that does the same, and a spilled basket. If the spinner lands on the spilled basket, all of their cherries magically fly from the basket back onto the tree and they must start again.
Starting with the first player, the players each take turns spinning the the spinner and placing cherries in their basket. The first one to reach 10 cherries in the basket cries "Hi Ho Cherry-O!" and wins the game.
Before the games begins, gather player information. There are four players in every game, and these players are either human or computer. For each player, your program should ask if that player is a human or a computer. If the player is a human, ask for their name and age. If they are a computer, assign it a name. All players baskets should be initialized to hold 0 cherries and then the game begins.
The computer player names should be assigned as follows:
First Computer Player | Alphie |
Second Computer Player | Bettie |
Third Computer Player | Deltie |
Fourth Computer Player | Gammie |
For each round, print a report similar to the following:
Timmy, it is your turn. Press Enter to spin You picked 2 cherries. You now have 2 cherries. Player 2 Alphie, A computer Player You spilled your basket. You now have 0 cherries. Player 3 Bettie, A computer Player You picked 1 cherry. You now have 1 cherries. Player 4 Deltie, A computer Player You picked 4 cherries. You now have 4 cherries. Player 1, Timmy, (2) is a human. * * O O O O O O O O Player 2, Alphie, (0) is a computer. O O O O O O O O O O Player 3, Bettie, (1) is a computer. * O O O O O O O O O Player 4, Deltie, (4) is a computer. * * * * O O O O O O Press ENTER to continue:As soon as a player wins, the game should end, and report the winner and the number of rounds it took to win. In this case a round consists of the number of times the first player spins, even if the first player is not the winner.
Player 1, Timmy, (8) is a human. * * * * * * * * O O Player 2, Alphie, (3) is a computer. * * * O O O O O O O Player 3, Bettie, (8) is a computer. * * * * * * * * O O Player 4, Deltie, (2) is a computer. * * O O O O O O O O Press ENTER to continue: Timmy, it is your turn. Press Enter to spin You picked 2 cherries. You now have 10 cherries. Hi Ho Cherry-O!, you win. You won the game in 35 rounds. That is very good for a human who is 5 years old.You should provide similar verbiage if a computer wins.
setw.
-g -O2 -Wall -Wextra -Wpedantic -Werror --std=c++20 -Wnon-virtual-dtor -Wold-style-cast -Wunused-parameter -Wuninitialized -Winit-self -Wshadow -Wparentheses -Wdangling-else