Hangman Game in C++ Please follow all the steps and make sure it includes the wa
ID: 3844399 • Letter: H
Question
Hangman Game in C++
Please follow all the steps and make sure it includes the way it prints as requested in the intructions. maximun number of moves should be 8 or 9 please.
thank you in advance.
This programming projects asks you to develop a hangman game which has the following characteristics:
1. It is driven by a while loop from main that allows the user to play the game as many times as they wish.
2. Validates ALL user input. (each character input for the word guess must be an alpha, 'a' is the same as 'A', all blank spaces ignored, 'y' = 'Y' = ' y ', etc)
3. A list of at least 20 words for the game are kept in a file that is read in at the time the program starts. These words are then stored in an array. Use a random number generator to access into the array to select the secret word. Don't repeat words during one run of the program. (What type of C++ structure would best hold this? Parallel arrays? An array of structures?)
4. Once each game begins, show the gallows, and indicate the number of characters in the word, like this:
______
|
|
|
____________ Word : _ _ _ _ _ _ _
That's just a suggestion as to how it may look. Actually, I am sure that you can do better than that.
For each wrong guess, draw a body part on the gallows and show it in a list of incorrect guesses. For each correct guess, fill in one of the blanks in the word.
______
| ( )
|
|
____________ Word : a _ _ _ _ _ Incorrect guesses: p
(this pictures shows 1 wrong guess and 1 correct guess).
5. The maximum number of moves before the person is hung would be 8 or 9, depending on your ability to draw head, neck, body, 2 legs, 2 arms...when the man is hung, the game is over. Or, the game is over when the user correctly guesses each letter in the word.
6. This program must have good modular design - using proper functions.
7. Pseudocode is absolutely required and I hope that you might even use it to design the code.
Explanation / Answer
#include <iostream>
#include <string>
using namespace std;
string pl1,pl2,word,under,guess,usedguess;
int wrong=0;
int main (){
string copy = word;
cout << "*******************Hello! Welcome to the HANGMAN game!*****************" << endl;
cout << "Please type in your name, PLAYER 1" << endl;
cin >> pl1;
cout << "Please type in your name, PLAYER 2" << endl;
cin >> pl2;
cout << "OK " << pl1 << " and " << pl2 << ". Let's start with the game!" << endl;
cout << pl1 << " please input the word you want " << pl2 << " to guess." << endl;
cin >> word;
//space
for (int x=0; x<30; x++){
cout << endl;
}
//UNDERSCORE
while (under.size() != word.size()){
under.push_back('_');}
cout << under << endl;
//MAIN WHILE
while(wrong<12){
cin >> guess;
//IF GUESS ISNT LETTER
if(guess.size() > 1){
if(guess==word){
cout << "Thats the right word." << endl;
break;
}
else{
cout << under << endl;
cout << "Wrong word try again." << endl;
cout << "Used: " << usedguess << endl;
wrong ++;
}
}
if(under == word){
cout << "You win!" << endl;
break;
}
if(wrong==1){
cout << "|" << endl;
}
else if(wrong==2){
cout << "|" << endl;
cout << "|" << endl;
}
else if(wrong==3){
cout << "|" << endl;
cout << "|" << endl;
cout << "|" << endl;
cout << "|" << endl;
}
else if(wrong==4){
cout << "|" << endl;
cout << "|" << endl;
cout << "|" << endl;
cout << "|" << endl;
cout << "|" << endl;
}
else if(wrong==5){
cout << "|===" << endl;
cout << "|" << endl;
cout << "|" << endl;
cout << "|" << endl;
cout << "|" << endl;
}
else if(wrong==6){
cout << "|===" << endl;
cout << "| O" << endl;
cout << "|" << endl;
cout << "|" << endl;
cout << "|" << endl;
}
else if(wrong==7){
cout << "|===" << endl;
cout << "| O" << endl;
cout << "| |" << endl;
cout << "|" << endl;
cout << "|" << endl;
}
else if(wrong==8){
cout << "|===" << endl;
cout << "| O" << endl;
cout << "| -|" << endl;
cout << "|" << endl;
cout << "|" << endl;
}
else if(wrong==9){
cout << "|===" << endl;
cout << "| O" << endl;
cout << "| -|-" << endl;
cout << "|" << endl;
cout << "|" << endl;
}
else if(wrong==10){
cout << "|===" << endl;
cout << "| O" << endl;
cout << "| -|-" << endl;
cout << "| /" << endl;
cout << "|" << endl;
}
else if(wrong==11){
cout << "|===" << endl;
cout << "| O" << endl;
cout << "| -|-" << endl;
cout << "| / /"<< endl;
cout << "| YOU ARE DEAD" << endl;
cout << "Game over! The word was: " << word <<endl;
break;
}
}
}
PLEASE RATE ANSWER THANK YOU.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.