1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<ctime>
using namespace std;
int main(){
string words[] =
{ "artistic",
"recreational",
"programmer",
"indistinct",
"sincere",
"pulchritude",
"legendary",
"scientific",
"oblivious",
"tomorrow"
};
string word,unknownword,wordrevelation,playername,usedletters;
int wordlength,numwrongofguesses,i,w,count;
char letter,playagain;
bool letterfound;
cout << "Please enter your name: ";
getline(cin,playername);
cout << endl << endl;
cout << "OKAY " << playername << " HERE WE GO!!!!!!!!!";
cout << endl << endl;
srand(time(0));
w=rand()%10;
word=words[w];
wordrevelation=word;
wordlength=word.size();
for(i=0;i<wordlength;i++){
unknownword[i]=word[i];
word[i]='-';
}
cout << "OKAY HERES THE HIDDEN WORD "<< word << " AND IT IS " << wordlength << " LETTERS LONG" << endl << endl << endl;
numwrongofguesses=8;
count=0;
bool Gameover=false;
while(!Gameover){
cout << "ENTER A LETTER " << playername << " : ";
cin >> letter;
letterfound=false;
for(i=0;i<wordlength;i++){
if(unknownword[i]==letter){
letterfound=true;
word[i]=letter;
count++;
}
}
cout << endl << endl;
if(letterfound==true){
word[i]=letter;
cout << "THE LETTER " << letter << " EXISTS IN THE WORD" << endl << endl << endl;
cout << " ";
for(i=0;i<wordlength;i++){
cout << word[i];
}
cout << endl << endl;
}else{
cout << "SORRY " << playername << ", " << letter << " DOES NOT EXIST IN THIS WORD" << endl << endl << endl;
numwrongofguesses--;
}
if(numwrongofguesses==7){
cout << "------------------" << endl;
cout << "| |" << endl;
cout << endl << endl;
}else if(numwrongofguesses==6){
cout << "------------------" << endl;
cout << "| |" << endl;
cout << "| O" << endl;
cout << endl << endl;
}else if(numwrongofguesses==5){
cout << "------------------" << endl;
cout << "| |" << endl;
cout << "| O" << endl;
cout << "| X" << endl;
cout << endl << endl;
}else if(numwrongofguesses==4){
cout << "------------------" << endl;
cout << "| |" << endl;
cout << "| O" << endl;
cout << "| /X" << endl;
cout << "| /" << endl;
cout << endl << endl;
}else if(numwrongofguesses==3){
cout << "------------------" << endl;
cout << "| |" << endl;
cout << "| O" << endl;
cout << "| /X\\" << endl;
cout << "| / \\" << endl;
cout << endl << endl;
}else if(numwrongofguesses==2){
cout << "------------------" << endl;
cout << "| |" << endl;
cout << "| O" << endl;
cout << "| /X\\" << endl;
cout << "| / | \\" << endl;
cout << endl << endl;
}else if(numwrongofguesses==1){
cout << "------------------" << endl;
cout << "| |" << endl;
cout << "| O" << endl;
cout << "| /X\\" << endl;
cout << "| / | \\" << endl;
cout << "| /" << endl;
cout << "| /" << endl;
cout << endl << endl;
}else if(numwrongofguesses==0){
cout << "------------------" << endl;
cout << "| |" << endl;
cout << "| O" << endl;
cout << "| /X\\" << endl;
cout << "| / | \\" << endl;
cout << "| / \\" << endl;
cout << "| / \\" << endl;
cout << "|----------|" << endl;
cout << "|----------|" << endl;
cout << endl << endl;
cout << " " << playername << " YOU HAVE BEEN HANGED!!!!" << endl << endl << endl;
cout << " THE WORD WAS " << wordrevelation << endl << endl << endl;
Gameover=true;
break;
}
if(numwrongofguesses==7 || numwrongofguesses==6 || numwrongofguesses==5 ||
numwrongofguesses==4 || numwrongofguesses==3 || numwrongofguesses==2 ||
numwrongofguesses==1 || numwrongofguesses==0){
cout << " ";
for(i=0;i<wordlength;i++){
cout << word[i];
}
}
cout << endl << endl;
if(count==wordlength){
cout << "CONGRATULATIONS " << playername << "! YOU GUESSED THE WORD!!! IT'S " << wordrevelation << endl << endl << endl;
Gameover=true;
break;
}
if(Gameover){
cout << playername << " THANKS FOR PLAYING.HOPE TO SEE YOU AGAIN.";
break;
}
}
}
| |