-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHollywood.cpp
147 lines (127 loc) · 4.61 KB
/
Hollywood.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
146
147
#include "MoviesDatabase.h"
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <random>
#include <sstream>
#include <string>
#include <unordered_set>
#include <vector>
int main()
{
int holl_idx = 1;
std::string movie, hollywood;
std::vector<char> good_guesses, bad_guesses, allowed_chars;
std::unordered_set<std::string> movie_prompts;
auto reset_game = [&holl_idx, &movie, &hollywood, &good_guesses, &bad_guesses, &allowed_chars, &movie_prompts]()
{
holl_idx = 1;
hollywood = "HOLLYWOOD";
good_guesses.clear();
bad_guesses.clear();
allowed_chars = { 'A', 'E', 'I', 'O', 'U', ' ', '-', '?', ':', '\'', '.', ',', '!',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '(', ')', '/' };
do
{
std::random_device rand_device; // Obtain a random number from hardware
std::mt19937 generator(rand_device()); // seed the generator
std::uniform_int_distribution<> dist(0, static_cast<int>(k_Movies.size()) - 1); // define the range
movie = k_Movies[dist(generator)];
} while (!movie_prompts.insert(movie).second);
std::transform(movie.begin(), movie.end(), movie.begin(), std::toupper);
if (movie_prompts.size() == k_Movies.size())
movie_prompts.clear();
};
reset_game(); // Initialize
int wins = 0, losses = 0;
do
{
// 1-Blue 2-Green 3-Aqua 4-Red 5-Purple 6-Yellow 7-White 8-Gray 9-Light Blue 0-Black
// A-Light Green B-Light Aqua C-Light Red D-Light Purple E-Light Yellow F-Bright White
system("Color 75"); // Background + text color
system("cls"); // Clear screen
std::cout << "\t\t\t" << hollywood << "\t\tW: " << wins << " L: " << losses << "\n\n\t\t";
if (!good_guesses.empty())
{
std::cout << "Good Guesses: ";
for (auto ch : good_guesses)
std::cout << ch << " ";
std::cout << "\n\n\t\t";
}
if (!bad_guesses.empty())
{
std::cout << "Bad Guesses: ";
for (auto ch : bad_guesses)
std::cout << ch << " ";
std::cout << "\n\n\t\t";
}
//std::cout << movie << "\n\t\t"; // For debugging purpose
int dash_count = 0;
for (auto ch : movie)
{
if (std::find(allowed_chars.begin(), allowed_chars.end(), ch) != allowed_chars.end())
std::cout << ch;
else
{
dash_count++;
std::cout << "_";
}
}
if (dash_count == 0)
{
wins++;
std::cout << "\n\n\t\tSUCCESS!!!\n\nDo you wish to play again? (Y/N) ";
char input_char;
std::cin >> input_char;
if (input_char == 'y' || input_char == 'Y')
{
reset_game();
continue;
}
else
break;
}
std::cout << "\n\nEnter guess: ";
char input_char;
std::cin >> input_char;
input_char = std::toupper(input_char);
if (std::find(allowed_chars.begin(), allowed_chars.end(), input_char) != allowed_chars.end())
continue;
if (movie.find(input_char) != std::string::npos)
{
if (std::find(good_guesses.begin(), good_guesses.end(), input_char) != good_guesses.end())
continue;
allowed_chars.push_back(input_char);
good_guesses.push_back(input_char);
}
else
{
if (std::find(bad_guesses.begin(), bad_guesses.end(), input_char) != bad_guesses.end())
continue;
if (holl_idx == 9)
{
losses++;
std::cout << "\n\nMovie was: " << movie << "\n\n\t\tGAME OVER!!\n\nDo you wish to play again? (Y/N) ";
char input_char;
std::cin >> input_char;
if (input_char == 'y' || input_char == 'Y')
{
reset_game();
continue;
}
else
break;
}
std::string holl_str;
for (auto i = 0; i < holl_idx; i++)
holl_str += "-";
hollywood = holl_str + hollywood.substr(holl_idx++);
bad_guesses.push_back(input_char);
}
} while (true);
system("pause");
return EXIT_SUCCESS;
}