-
Notifications
You must be signed in to change notification settings - Fork 0
/
wordle_game.cpp
54 lines (37 loc) · 1.14 KB
/
wordle_game.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
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include "wordlefunc.H"
using namespace std;
int main() {
vector<string> dict = get_dict(); // read in dictionary
assert(!dict.empty());
string answer = rand_word(dict); // generate answer
cout << "Guess the word:" << endl;
int n_guesses = 6; // number of guesses
int round = 1; // game round
while (round <= n_guesses){
// input guess
string guess{};
cin >> guess;
// check that guess is the correct length
if (guess.length() != answer.length()) {
cout << "guesses must be " << answer.length() << " letters long, enter new guess" << endl;
continue;
}
else {
color_string output = compare(guess, answer);
cout << round << " ";
cout << output << endl;
}
if (guess == answer) {
cout << "Congratulations! You found the word" << endl;
break;
}
if (round == n_guesses) {
cout << "Sorry, the word was " << answer << endl;
}
round++;
}
}