-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.cpp
More file actions
88 lines (82 loc) · 2.75 KB
/
Game.cpp
File metadata and controls
88 lines (82 loc) · 2.75 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
#include <string>
#include "Game.h"
constexpr char ESC = 0x1b;
Game::Game(string _word, unsigned int _maxGuesses) :
word(_word),
wordLength(_word.length()),
maxGuesses(_maxGuesses)
{}
bool Game::confirmGuess(string guess) {
if (guessCount >= maxGuesses) throw "Too many guesses.";
if (guess.length() != wordLength) throw "Incorrect guess length.";
guesses.push_back(guess);
tileColors.push_back(guessColors(guess, word));
keyboard.visit(guess, word);
guessCount++;
return guess == word;
}
void Game::printGame(string partialGuess) {
cout << '\xC9';
for (unsigned int i = 0; i < wordLength; i++) {
cout << "\xCD\xCD\xCD\xCD\xCD\xCD\xCD";
if (i != wordLength - 1) cout << '\xCB';
}
cout << '\xBB' << endl;
for (unsigned int i = 0; i < maxGuesses; i++) {
for (unsigned int j = 0; j < wordLength; j++) {
cout << '\xBA';
if (i < guessCount) setConsoleColors(tileColors[i][j]);
cout << " ";
resetConsoleColors();
}
cout << '\xBA' << endl;
for (unsigned int j = 0; j < wordLength; j++) {
cout << '\xBA';
if (i < guessCount) {
setConsoleColors(tileColors[i][j]);
cout << " " << guesses[i][j] << " ";
resetConsoleColors();
}
else if (i == guessCount) {
cout << " ";
if (j == partialGuess.length() || j == wordLength - 1 && partialGuess.length() == wordLength) {
cout << ESC << "[4m";
}
if (j < partialGuess.length())
cout << partialGuess[j];
else
cout << ' ';
cout << ESC << "[24m";
cout << " ";
}
else {
cout << " ";
}
}
cout << '\xBA' << endl;
for (unsigned int j = 0; j < wordLength; j++) {
cout << '\xBA';
if (i < guessCount) setConsoleColors(tileColors[i][j]);
cout << " ";
resetConsoleColors();
}
cout << '\xBA' << endl;
if (i == maxGuesses - 1) {
cout << '\xC8';
for (unsigned int i = 0; i < wordLength; i++) {
cout << "\xCD\xCD\xCD\xCD\xCD\xCD\xCD";
if (i != wordLength - 1) cout << '\xCA';
}
cout << '\xBC' << endl;
}
else {
cout << '\xCC';
for (unsigned int i = 0; i < wordLength; i++) {
cout << "\xCD\xCD\xCD\xCD\xCD\xCD\xCD";
if (i != wordLength - 1) cout << '\xCE';
}
cout << '\xB9' << endl;
}
}
cout << keyboard;
}