-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path23.cpp
More file actions
106 lines (105 loc) · 2.97 KB
/
Copy path23.cpp
File metadata and controls
106 lines (105 loc) · 2.97 KB
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
#include <fstream>
#include <iostream>
#include <cstdlib>
#include <time.h>
using namespace std;
int main(){
int mistake=0,wrong=0,c1=0,c2=0,tr=0;
while(1){
srand(time(NULL));
ifstream fin ("dict.txt");
string words[30000],word,gap,used="",temp=" ";
char input;
for(int c=0; ;c++){
fin >> words[c];
c2++;
if (fin.eof()) break;
}
word=words[rand()%c2];
for(int c=0;c<word.length();c++){
gap+="_ ";
}
cout << "Hangman Game" << endl;
cin >> tr;
while(mistake<tr){
cout << gap << endl;
cout << "Used: " << used << endl;
cin >> input;
temp[0]=input;
if(used.find(temp)==-1){
used+=temp + " ";
}else{
cout << "Warning: Used letter!" << endl;
continue;
}
for(int c=0;c<word.length();c++){
if(wrong==2){
break;
}
if(word[c]==input){
gap[2*c]=input;
wrong=1;
c1++;
}
}
if(wrong==0){
mistake++;
cout << "You made " << mistake << " mistakes." << endl;
}else if(wrong==1){
cout << "Correct!" << endl;
}
if(mistake== 0 ){
cout << " /-----" << endl;
cout << " | " << endl;
cout << " | " << endl;
cout << " | " << endl;
cout << "_______" << endl;
}
if(mistake== 1 ){
cout << " /-----" << endl;
cout << " | O " << endl;
cout << " | " << endl;
cout << " | " << endl;
cout << "_______" << endl;
}
if(mistake== 2 ){
cout << " /-----" << endl;
cout << " | O " << endl;
cout << " | | " << endl;
cout << " | " << endl;
cout << "_______" << endl;
}
if(mistake== 3 ){
cout << " /-----" << endl;
cout << " | O " << endl;
cout << " | /|\\" << endl;
cout << " | " << endl;
cout << "_______" << endl;
}
if(mistake== 4 ){
cout << " /-----" << endl;
cout << " | O " << endl;
cout << " | /|\\" << endl;
cout << " | / " << endl;
cout << "_______" << endl;
}
if(mistake== 4 ){
cout << " /-----" << endl;
cout << " | O " << endl;
cout << " | /|\\" << endl;
cout << " | / \\" << endl;
cout << "_______" << endl;
}
if(c1==word.length()){
cout << gap << endl;
cout << "You win!" << endl;
break;
}
wrong=0;
}
if(mistake==tr){
cout << gap << endl;
cout << "You lost." << endl << "Answer:" << word << endl;
}
}
}