Please write an interactive game by using the specification below. And make sure
ID: 3773525 • Letter: P
Question
Please write an interactive game by using the specification below. And make sure to define a minimum of 2 classes...
"
Shut the Box
“The essentials are a surface on which two dice are thrown, integral with a row of boxes numbered 1 to 9 and having hinged lids. At start of play all boxes are open, the aim being to shut as many of them as possible. Each in turn throws two dice, and may shut the box corresponding in number to the total thrown, or the two boxes equivalent to the individual numbers, provided both are open. His turn continues until he either wins by getting all the boxes shut, or makes a throw whose numbers and total are already shut. When the total values of the open boxes amount to six or less, a player throws only one die. At the end of a turn, the total value of any open boxes is added to the player’s penalty score, and if this brings it to 45 or over he withdraws from play. The winner is the first to shut all the boxes, or, if no one does the last remaining in play.”
David Partlett, The Oxford History of Board Games, page 32
Explanation / Answer
#include <iostream.h> // input output stream header file
#include <stdio.h> // standard input output header file
#include <stdlib.h> // standard library header file
//#include <string.h> // header file with string function
// #include <conio.h> // console input output header file
#include <time.h>
class player {
char *name;
int openNumbers[9];
int closedNumbers[9];
char *result; // win, withdraw
int numThrown; // between 1 to 12
int numOfDiesThrowable; // 1 or 2
};
class boxes {
int boxNumber;
char boxPosition[10]; // open or shut
};
int totalAttemptCount = 700; // maximum number of attempts possible in the game
int main() // start main
{
srand(time(NULL));
int count=0, n, seed; // i,j,k : l,m,n
int l,m,n, Die[36];
int i,j,k;
for (count=0; count <= totalAttemptCount ; count++) {
int numRolled = rand()%6;
for (m = 0; m<= 6; m++) {
seed = 1;
srand(seed);
numRolled = rand()%6;
Die[m] = numRolled;
} // end inner for
int flipCount = 6, total = 0;
for (l=1; l<= flipCount; l++) {
total = total + Die[l];
} // end for
} // end outer for
return 0; // exit
} // end of main()