-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhangman practice.cpp
102 lines (101 loc) · 1.83 KB
/
hangman practice.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
#include<iostream>
#include<cstdlib> \\for string matching and also for using rand() function
#include <string>
#include <fstream>
#include <windows.h> \\for interacting with windows for detecting the keypress
#include <conio.h>
using namespace std;
char word[10];
string question(int);
int game();
char choice(){
char choice;
cout<<"\n\n\t\t\t''''''''''''''''BOLLYWOOD''''''''''''''''";
cout<<"\n(1) : Start\n(Q) : Quit\n";
cin>>choice;
return (choice);
}
int question(char choice){
if(choice=='1'){
char a,password[10];
int i=0,flag=0;
cout<<"\nPlayer 2 :enter the WORD,end with '.'\n";
while(flag!=1){
a=getch();
if(a=='.'){
flag=1;
continue;
}
else{
word[i]=a;
i++;
printf("*");}}
}
if((choice== 'Q' || choice=='q')){
return 1;
}
}
int main(){
label:
char choicee;
int flag,result;
while(choicee!='quit'){
choicee=choice();
flag=question(choicee);
if(flag==1)
return 0;
result=game();
if(result==1){
cout<<"\n\nCONGRATULATIONS!!!!\nWANNA PLAY AGAIN?? (Y/N)";
cin>>choicee;
if(choicee=='y')
goto label;
else
return 0;
}
else
cout<<"\n\t\t\t\tOOPS!!!\tThe Word Was ''"<<word<<"''\nWANNA PLAY AGAIN?? (Y/N)";
cin>>choicee;
if(choicee=='y')
goto label;
else
return 0;
}
}
int game(){
int n,i,k=0,guess=3,flag;
string temp=word;
n=temp.length();
char blanks[10],used[27];
for(i=0;i<n;i++)
blanks[i]='_';
while(guess!=0){
cout<<"\n\n\t\t\t\t\t";
for(i=0;i<n;i++)
cout<<" "<<blanks[i];
cout<<"\n Used:";
for(i=1;i<=k;i++)
cout<<used[i]<<",";
flag=0;
for(i=0;i<n;i++){
if(blanks[i]==word[i])
flag++;
}
if(flag==n)
return 1;
flag=0;
cout<<"\n\nYou Have "<<guess<<"Try Left: ";
++k;
cin>>used[k];
for(i=0;i<n;i++){
if(used[k]==word[i]){
blanks[i]=used[k];
flag=1;
}
}
if(flag==0)
guess--;
}
if(guess==0)
return 0;
}