Code:
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
int strikes=0; // to tell the plyers how many wrong guesses
int wordlength; //to tell plyers how long the word is
char guess; //what the players will be defining to play the game
string gameword; //the designated word from the leader
string decision; //string for type of guessing
string answer; //reference to the answer for the player's guess
string lost; //choice by player to play again
int menuchoice; //what type of meanu they want
string success; //to decide if guessed letter is present
string name; //Players Name
string players; //If theres more players
int p; //number of players
int lives=10; //number of lives player has
char astring[30]="-";
system("cls");
cout<<"Choose A Number.\n"; //Displays Menu Text
cout<<"1. Play Game\n";
cout<<"2. Help and Guide\n";
cout<<"3. Exit\n";
cout<<"Choice:";
cin>>menuchoice;
switch ( menuchoice ) //Allows For Menu Option Selection
{
case 1:
GameStart();
break;
case 2:
HelpAndGuide();
break;
case 3:
exit(0);
break;
default:
GameStart();
break;
}
int GameStart();
{ //Labels The Game's Start
cin.get();
system("cls");
p=1;
int PlayerNames();
{ //Labels Area For Player Identification
cout<<"Enter Your Name Here:";
cin>>name;
cout<<"Welcome "<<name<<"!!\nYou Are Player Number"<<p<<"\n";
cout<<"More Players?'y/n'"; //Allows For Multiple Player Notification
cin>>players;
if (players=="y")
{
p=p+1;
PlayerNames();
}
else if(players=="n")
{
system("cls");
cout<<"The Number Of Players Is "<<p<<"\n";
cout<<"Designate A Leader Of This Game Now.\n"; //Tells Players To Choose A Leader
}
}
cin.get();
cout<<"For Game Leader:\nEnter Game Word Here:";
getline(cin,gameword,'\n'); //leader of game enters the word of the game here
system("cls");
wordlength=gameword.length(); //stores the length of the word into "wordlength"
if( wordlength>25)
{
cout<<"The Word You Entered Was Too Long For This Game\n";
cout<<"Please Try Another Word."; //checks to see if word will fit in the string allowed
}
else
{
cout<<"CONGRATULATIONS! You Have Chosen A Valid Word\n";
cout<<"Now You Are Ready To Play The Game\n\n\n"; //tells the leader he/she has chosen a valid word, and it's time to play
}
cout<<"\nFor Players:\nThe Game Word Has A Length Of "<<wordlength<<" Letters\n\n"; //reveals the length of the game word to the players
for (char w=0;w<wordlength;w++)
{
cout<<astring;
}
int PlayerInput();
{ //Designates Time Of Game For Player Interaction
cout<<"\n\nWhat Would You Like To Do?\n";
cout<<"Type 'Answer' To Try And Guess The Word Or Type 'Turn' To Guess A Letter.";//Asks Player To Try Choose Between Guessing A Letter Or The Word
cin>>decision;
if (decision=="turn")//Goes Here If Player Wants To Guess Letters
{
system("cls");
cout<<"Type Your Single Letter Guess Here:";
cin>>guess;
success="n";
for(int i = 0; i < wordlength; i++)//Checks For Players Guess Validity
{
if(gameword[i] == guess)
{
success="y";
cout<<"Letter "<<guess<<" Is In Position "<<i+1<<" In The Game Word\n\n";//Displays Location Of Valid Guess
astring[i]=guess;
for(int i = 0; i < wordlength; i++)
{
if (astring[i]==guess)
{
cout<<astring;
if (astring==gameword)
{
goto Win;
}
}
/*if(astring[i]==guess)
{
cout<<astring;
}
if (astring[i]!=guess)
{
cout<<" ";
}*/
}
}
}
if (success=="n")
{
cout<<"Sorry, The Letter You Have Guessed Was Incorrect.\n";//Tells Player Their Guess Was Not In The Word
strikes=strikes+1;
cout<<"Lives Remaining "<<lives-strikes<<"\n";//Takes Away Srikes From Total Initial Lives
if(strikes==lives)//Check For Loss
{
cout<<"YOU HAVE LOST!\nTry Again?'y/n'";//Reveals Loss
cin>>lost;
if (lost=="y")
{
main(); //Goes To Beginning of Game, If Chosen
}
else
{
exit(0);
}
}
}
}
else if (decision=="answer")//Goes Here If Player Wants To Guess The Word
{
system("cls");
cout<<"What Do You Think The Answer Is?";//Asks Player For The Guess Of What The Word Is
cin>>answer;
if( answer==gameword)
{
Win:
system("cls");
cout<<"CONGRATULATIONS! You Have Found The Word!\nYou Are Now The Game Leader!\n\n\n";//Reveals Victory
cout<<"Hit Enter To Start New Game";
cin.get();
GameStart();
}
else
{
cout<<"Sorry, The Word You Have Guessed Was Incorrect.\n";
strikes=strikes+2;
cout<<"Lives Remaining "<<lives-strikes<<"\n";
if(strikes==lives)
{
cout<<"YOU HAVE LOST!\nTry Again?'y/n'";
cin>>lost;
if (lost=="y")
{
GameStart();
}
else
{
exit(0);
}
}
}
}
}
}
PlayerInput();
int HelpAndGuide();//Goes Here From 2nd Menu Selection And Provides Game Information
system("cls");
cout<<"This Is The Consol Version Of HangMan!\n";
cout<<"You Have A Space Of 25 Letters For The Game Word.\n";
cout<<"When Playing This Game And Taking Guesses, A Wrong Guess Will Result\nIn A Strike.\n";
cout<<"Also When Guessing Letters, The Letter You Type As Your Guess Will.\n";
cout<<"Result In A Number Or Numbers Of Position(s) That The Letter Is.\n";
cout<<"That Number Is A Reference To The Location Inside The Game Word.\n";
cout<<"You Have 10 Chances, Including Both Letter Guesses And Full Word Guesses.\n";
cout<<"Letter Guesses Are Worth 1 Life\n While Word Guesses Are Worth 2 Lives.\n";
cout<<"After 10 Chances Are Gone, You Will Lose.\n";
cout<<"When Typeing Anything In This Game, Type Exclusively In Lowercase.\n\n\n\n\n";
cout<<"Hit Enter";
cin.get();
GameStart();
cin.get();
}
that's what i've done... is it the right idea? cuz it doesn't work right.