You will implement the program for playing a modified Wheel of Fortune. The game
ID: 3667242 • Letter: Y
Question
You will implement the program for playing a modified Wheel of Fortune. The game must allow a user to enter the number of rounds to play and a new secret message (possibly containing blanks) with each round, and print the number of dashes/slots for the message (spaces do not get dashes, just the space) The game can play with 1-3 players, and it continues a round, until someone solves the puzzle correctly. A new puzzle is given with each round. In this Wheel of Fortune, you won't win as much or any prizes, but you might go bankrupt or lose a turn!!! Your random numbers are only from 0-21, with 0 being bankrupt, 1-20 being the dollar amount earned per letter found in the puzzle, and 21 is lose a turn. The game begins by asking the first player if he/she wants to spin the wheel, buy a vowel, or solve the puzzle. On a player's first turn, it might not make sense to choose anything other than spinning the wheel, but a player is given these three choices at all times during their turn, until they guess an incorrect non-vowel letter, incorrectly solve the puzzle, or spin a 0 or 21 If the player chooses to spin and the spin is >0 and = $10, which is the one-time amount paid for each vowel guess, regardless of whether the vowel is found The player who has the most money after N rounds is the winner!Explanation / Answer
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <fstream>
#include <string>
#include <iomanip>
#include <cctype>
#include <cstring>
#include <string.h>
using namespace std;
//Declare Global Variables
const int WHEEL_SIZE = 15;
const int PHRASE_SIZE = 81;
const int NUM_PLAYERS = 3;
const int BANKRUPT = 0;
const int LOSE_TURN = 1;
const int VOWEL_COST = 250;
const string BLANK = " ";
const char ASTERISK = '*';
//Declare Global Array
const int wheel[WHEEL_SIZE] =
{ 50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 1000, 1500,
2500, BANKRUPT, LOSE_TURN };
//Functions
void printHeader();
//void arrayReadIn (string&, string&, ifstream&);//
void scoreTracker(const int*);
bool inGame(string&, string&);
void player1(int*, string *puzzle, string *phrase, const int count);
void player2(int*, string *puzzle, string *phrase, const int count);
void player3(int*, string *puzzle, string *phrase, const int count);
void print_puzzle(string*, const int);
int spin_wheel(const int*);
int chose_letter(const int count, string*, string*);
bool isVowel(char);
void solve_puzzle();
void buy_vowel();
int main()
{
//Declare Variables
string fileName;
bool game;
char ch;
int count = 0;
//Initialize Array: Phrase
string phrase[PHRASE_SIZE];
//Initialize Array: Puzzle
string puzzle[PHRASE_SIZE];
//Initialize Array: playerScores
int playerScores[NUM_PLAYERS] = { 0, 0 ,0 };
//Print Header
printHeader();
//Ask user for file input
//cout << "Enter the name of the file containing the secret phrase -> ";
//cin >> fileName;
//cout << endl;
ifstream inFile;
inFile.open("1.txt");
//Error check for bad fileName
while (!inFile)
{
//Reset failed openFile
inFile.clear();
//Prompt the user for the fileName...again
cout << "Please re-enter using a valid filename: ";
cin >> fileName;
inFile.open(fileName.c_str());
}
//Begin reading file into the array
inFile.get(ch);
while (inFile)
{
if (!isalpha(ch))
puzzle[count] = ch;
else
puzzle[count] = ASTERISK;
phrase[count] = ch;
inFile.get(ch);
count++;
}
//test for array print
for (int precount = 0; precount < count; precount++)
cout << phrase[precount];
//Print playerScores table and start the players off with
// 0 points.
scoreTracker(playerScores);
//This loop will check to see if the game is still running
//i.e. no one has completed the puzzle and will also
//Keep the players turn in order.
game = inGame(*phrase, *puzzle);
player1(playerScores, puzzle, phrase, count);
return (0);
}
void printHeader()
//This function simply prints the header for the program
//Called by: main
{
cout << setw(10) << BLANK << "-----------------------------------------------------"
<< endl << endl;
cout << setw(10) << BLANK << "Over 50,000 in cash and prizes just waiting to be won"
<< endl;
cout << setw(20) << BLANK << "Here on Wheel ... of ... Fortune!" << endl;
cout << setw(22) << BLANK << "(loud drum roll and music...)" << endl;
cout << setw(10) << BLANK << "-----------------------------------------------------"
<< endl << endl;
cout << "NOTE: This program assumes all alphabetic letters" << endl
<< "used in phrases and guesses are LOWER CASE!!!" << endl << endl;
}
void scoreTracker(const int *playerScores)
//This function will store and print the players score per turn.
//Called by: main
{
cout << setw(7) << BLANK << "Player 1"
<< setw(7) << BLANK << "Player 2"
<< setw(7) << BLANK << "Player 3"
<< endl;
cout << setw(7) << BLANK << "========"
<< setw(7) << BLANK << "========"
<< setw(7) << BLANK << "========"
<< endl;
cout << setw(10) << BLANK << playerScores[0]
<< setw(14) << BLANK << playerScores[1]
<< setw(15) << BLANK << playerScores[2]
<< endl << endl;
}
bool inGame(string &puzzle, string &phrase)
//This function will check to see if the game is stillrunning
//by comparing the arrays. When both arrays match, when the
//puzzle is complete, the function will return false.
//Called by:
{
if (puzzle == phrase)
return(false);
else
return(true);
}
void player1(int *playerScores, string *puzzle, string *phrase, const int count)
//Begin player 1 turn. It will go through the process of
//spinning the wheel and offer the player a variety
//of choices during the game, etc etc.
//Called by: main
{
//Declare variables
char choice;
int reward;
int charNum;
cout << "Player 1 it's your turn." << endl << endl;
//Print puzzle
print_puzzle(puzzle, count);
//Ask the user what s/he wants to do.
cout << "(s)pin, s(o)lve or (b)uy a vowel -> ";
cin >> choice;
while (!(choice == 's') && !(choice == 'o') && !(choice == 'b'))
{
cout << "Incorrect choice entered." << endl
<< "You have only three choices." << endl
<< "Player 1, re-enter what you want to do?" << endl << endl;
cout << "(s)pin, s(o)lve or (b)uy a vowel -> ";
cin >> choice;
}
if (choice == 's')
{
cout << "You chose to spin the wheel!" << endl << endl;
reward = spin_wheel(wheel);
cout << "You spun " << reward << endl << endl;
charNum = chose_letter(count, phrase, puzzle);
}
else if (choice == 'o')
{
cout << "You chose to solve the puzzle!" << endl << endl;
}
else if (choice == 'b')
{
}
}
void player2(int *playerScores, string *puzzle, string *phrase, const int count)
{
}
void player3(int *playerScores, string *puzzle, string *phrase, const int count)
{
}
void print_puzzle(string *puzzle, const int count)
//This function prints the puzzle as the contestants
//guess the correct letters.
//called by: player1, player2, player3
{
//Declare variables
cout << "===============================" << endl;
cout << setw(14) << BLANK << "Puzzle" << endl;
cout << "===============================" << endl;
for (int n = 0; n < count; n++)
cout << puzzle[n];
cout << endl;
cout << "===============================" << endl << endl;;
}
int spin_wheel(const int *wheel)
//This function will create a pseudo random number and
//spin the ever magical and majestic wheel of fortune.
//Called by: player1, player2, player3
{
//Declare variables
int spin;
int prize;
//Get the system time
unsigned seed = time(0);
//Seed the random number generator
srand(seed);
//limit the random number to WHEEL_SIZE and obtain the random number
spin = 1 + rand() % WHEEL_SIZE;
//Spin the wheel to receive prize...haha...
prize = wheel[spin];
//print out what the user spun.
if (prize == 0)
cout << "Bankrupt!";
else if (prize == 1)
cout << "Lose a turn!";
return (prize);
}
int chose_letter(const int count, string *phrase, string *puzzle)
//This function runs right after spin_wheel to determine if the character
//that the user inputs is not a vowel and is part of the puzzle.
//It will also replace puzzle with the correct letter.
//Called by: player1, player2, player3
{
//Declare variable
char char1;
int lettercount = 0;
string word = "test";
cout << "Pick a letter -> ";
cin >> char1;
while (isVowel(char1))
{
cout << "You did not buy a vowel!" << endl
<< "Please enter a consonant not on the board -> ";
cin >> char1;
}
cout << word << endl;
/* for (int n = 0; n < count; n++)
{
if (char1 == word[1])
{
lettercount++;
puzzle[n] = phrase[n];
}
}*/
return(0);
}
bool isVowel(char ch)
//This function tests to see whether the input is a vowel or not
//fml, this is getting ridicously long.
//Called by:chose_letter
{
if ('A' == ch || 'a' == ch || 'E' == ch || 'e' == ch || 'I' == ch ||
'i' == ch || 'O' == ch || 'o' == ch || 'U' == ch || 'u' == ch)
{
return true;
}
else return false;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.