-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhangman.cpp
145 lines (131 loc) · 3.02 KB
/
hangman.cpp
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
#include<bits/stdc++.h>
#include<cstdlib>
using namespace std;
#define debug(x) cout<<#x<< <<x ;
void welcome(){
cout<<"=================WELCOME TO====================";
cout<<"==============HANGMAN THE GAME=================";
}
void lives(int incorrect)
{
if(incorrect==0)
{
cout<<" +---+ \n";
cout<<" | | \n";
cout<<" | \n";
cout<<" | \n";
cout<<" | \n";
cout<<" | \n";
cout<<" ========= \n";
}
else if(incorrect==1)
{
cout<<" +---+ \n";
cout<<" | | \n";
cout<<" O | \n";
cout<<" | \n";
cout<<" | \n";
cout<<" | \n";
cout<<" ========= \n";
}
else if(incorrect==2)
{
cout<<" +---+ \n";
cout<<" | | \n";
cout<<" O | \n";
cout<<" | | \n";
cout<<" | \n";
cout<<" | \n";
cout<<" ========= \n";
}
else if(incorrect==3)
{
cout<<" +---+ \n";
cout<<" | | \n";
cout<<" O | \n";
cout<<" /| | \n";
cout<<" | \n";
cout<<" | \n";
cout<<" ========= \n";
}
else if(incorrect==4)
{
cout<<" +---+ \n";
cout<<" | | \n";
cout<<" O | \n";
cout<<" /| | \n";
cout<<" / | \n";
cout<<" | \n";
cout<<" ========= \n";
}
else if(incorrect==5)
{
cout<<" +---+ \n";
cout<<" | | \n";
cout<<" O | \n";
cout<<" /|\\ | \n";
cout<<" / | \n";
cout<<" | \n";
cout<<" ========= \n";
}
else if(incorrect==6)
{
cout<<" +---+ \n";
cout<<" | | \n";
cout<<" O | \n";
cout<<" /|\\ | \n";
cout<<" / \\ | \n";
cout<<" | \n";
cout<<" ========= \n";
}
}
void status(int incorrect,string answer){
cout<<"INCORRECT WORDS :\n";
cout<<incorrect<<'\n';
cout<<"GUESS THE WORD : \n";
for(int i=0;i<answer.size();i++){
cout<<answer[i];
}cout<<'\n';
}
void ending(string ans,string word){
if(ans==word){
cout<<"CONGRATULATION YOUR FRIEND IS SAVED"<<'\n';
}
else{
cout<<"OHH!! YOU CAN'T SAVE YOUR FREIND"<<'\n';
// cout<<"THE CORRECT ANS IS"<<word;
}
}
int main(){
welcome();
string arr[4] {"codingw","hathway","awesome","courses"};
string word ="awesome";
string ans ="_______";
int incorrect =0;
vector<char> incword;
bool guess = false;
char letter;
while (ans!= word && incorrect<6)
{
lives(incorrect);
status(incorrect,ans);
cout<<"PLEASE ENTER THE LETTER: ";
cin>>letter;
for(int i=0;i<word.size();i++){
if(letter==word[i]){
ans[i]=letter;
guess=true;
}
}
if(guess){
cout<<"WOOH!! IT IS CORRECT"<<"\n";
}
else{
cout<<"NAAH!! IT'S NOT CORRECT"<<"\n";
incorrect++;
}
guess=false;
}
ending(ans,word);
return 0;
}