Question: C++ only!! **PLEASE READ DIRECTIONS BELOW CAREFULLY** I have a code for a pig dice game, but need to split it up into classes and
C++ only!! **PLEASE READ DIRECTIONS BELOW CAREFULLY**
I have a code for a pig dice game, but need to split it up into classes and umsure of how to do it properly.
1) I need a base class "GameRules" with "GameModeA" and "GameModeB" as the derived class of GameRules.
2) I will then need a "Dice" class and a "Player" class.
**.h files must have a .cpp file as well**
Trying to build a pig dice game (6 side die) that will first ask the user to pick between game A or game B. Then will proceed to have players 1 & 2 (HUMAN CONTROLLED, NO CP's) roll (for example, player one will have the option of rolling until they hit a 1 or snake eyes. If they choose to hold, it will go to player 2), while keeping track of the score.
*For game A (one dice game), if player 1 or 2 rolls a 1, their score goes back to 0.
*For game B (two dice game), if player 1 or 2 rolls snake eyes (two 1's) OR a 1, their score goes back to 0. If possible, include pointers for the classes!
*cout statements cannot be in any of the classes, only in main.cpp!
Here is the code I have that needs to be split up into classes:
//Function Prototypes int getRandomNum(); int main() { //Declare Constants And Variables char gameChoice = 'X'; char playerChoice = 'X'; int randInteger = 0; int roll = 0; int score = 0; cout << "What Would You Like To Play Today? A for Game A B for Game B E to EXIT " << endl; cin >> gameChoice; gameChoice = (toupper(gameChoice)); //Game Selection if (gameChoice == 'A') { cout << "\You Have Chosen Game A! Let's Get Started!" << endl; system("pause"); cout << "Game A "; } else if (gameChoice == 'B') { cout << "\You Have Chosen To Game B! Let's Get Started!" << endl; system("pause"); cout << "Game B "; } else if (gameChoice == 'E') { cout << "Thanks For Playing, Let's Play Again Soon!" << endl; system("pause"); return 0; } //End Opening Game Selection Statement //Start Playing Pig while (gameChoice == 'A') { cout << "It Is Your Turn: Roll The Dice (R) or Hold Your Turn (H):"; cin >> playerChoice; playerChoice = (toupper(playerChoice)); if (playerChoice == 'R') { roll = getRandomNum(); cout << "I Rolled a " << roll << endl; score += roll; cout << "My Score is: " << score << endl; } if (roll == 1) { cout << "I Rolled A PIG! Ending Player Turn." << endl; break; } if (playerChoice == 'H') { break; } } system("pause"); return 0; } //End Of Main //*****Function Definitions****** //Get Random Number Function int getRandomNum() { int randInteger; srand(static_cast(time(0))); randInteger = (int)(1 + rand() % (6 - 1 + 1)); return randInteger; } //End of Get Random Number Function
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
