The game of beetle is a simple die game for children. I am using the rules found here.
A random player begins the game by rolling the die. Using the below reference, the player will then draw the body part correlated to the number they rolled. The next player will then roll the die and draw their body part.Ha$bro sells a version of this game called Cootie.
- Body
- Head
- A leg
- An eye
- An antenna
- The tail
You'll be sure to encounter a few challenges as you sketch your beetle. A body must be drawn before any other parts. A beetle without a body cannot have legs or a tail, after all! Furthermore, the head must be drawn before the eye and antenna can be added. Rolling a 1 and 2 is essential to completing your drawing. If you roll a number associated with a body part that cannot be drawn, your turn is skipped and the next player rolls. The first player with a fully sketched beetle is the winner!
We are going to write a simulation of this game.
Initially we will develop the game as written, but eventually we will want to expand this game to include bugs with more/different parts. In addition we will develop this game for two players, but we may expand that in the future as well.
The die class has the following interface:
#include "Die.h" ... int main() { // pick one of these // This one is for recording the game. DieDynamic die; die.Record("Afile.dice"); // This one is for replaying the game // DieStatic die("Afile.dice"); ...
Note, you can't copy the die, and it must be passed by reference. A function that uses the die might be:
void RollDie(Die & theDie){ int roll{theDie.Roll()}; cout << "You roll a " << roll << endl; roll = theDie.Roll(); cout << "The second roll is " << roll << endl; }This restriction is somewhat strange, but the die has an internal state AND we are able to pass any type of die in that we want. We will discuss this further when we get to chapter 10.
We will discuss UML diagrams this semester. Here is the one for the die class.
Your output should match the output in AGame.txt provided below. Briefly:
Player 1 is taking a turn! The player rolls a 1. This is the body. The player needs this part. Adding a body, the player now has 1.
Player 1's bug is: body 1 head 1 leg 6 eye 2 antenna 2 tail 1 This is a finished bug.
This is not a finished bug. ________________________________________
CXXFlAGS
line must remain, unchanged, and be used to compile.
beetle
.
DieStatic die("AGame.dice")
to declare your die.
beetle | diff - AGame.txt
and produce no output.
<
are your output.
>
are the standard output.
20c20 < This is not a finished BuG. --- > This is not a finished bug.This example indicates that the output differs on the 20th line. The programmer printed
BuG
, but the standard wants bug
.