-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHangmanDisplays.cpp
More file actions
140 lines (125 loc) · 3.22 KB
/
HangmanDisplays.cpp
File metadata and controls
140 lines (125 loc) · 3.22 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
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
#include <string>
#include <vector>
#include <stdexcept>
#include "Windows.h"
#include "Hangman.h"
void Hangman::WHeaderText() {
WPrintWSAAtCoord(header_win, "header_text", header_text);
}
void Hangman::WDisplayStage() {
WPrintWSAAtCoord(stage_win,"empty_stage", empty_stage);
}
void Hangman::DrawHangman() {
switch (current_number_of_incorrect_guesses) {
case 7:
WPrintWAtCoord(stage_win, "hangman_head", { 3,1 }, std::string("\\"));
case 6:
WPrintWAtCoord(stage_win, "hangman_head", { 3,-1 }, std::string("/"));
case 5:
WPrintWAtCoord(stage_win, "hangman_head", { 2,0 }, std::string("|"));
case 4:
WPrintWAtCoord(stage_win, "hangman_head", { 1,1 }, std::string("\\"));
case 3:
WPrintWAtCoord(stage_win, "hangman_head", { 1,-1 }, std::string("/"));
case 2:
WPrintWAtCoord(stage_win, "hangman_head", { 1,0 }, std::string("|"));
case 1:
WPrintWAtCoord(stage_win, "hangman_head", std::string("O"));
}
}
void Hangman::WPrintWAtCoord(WINDOW* window, std::string coord_name, std::string line, bool clear_line) {
try {
if (coords.find(coord_name) == coords.end()) {
throw std::invalid_argument(coord_name + " not in coords keys");
}
if (clear_line) {
wmove(
window,
coords[coord_name].at(0),
coords[coord_name].at(1)
);
wclrtoeol(window);
}
mvwprintw(
window,
coords[coord_name].at(0),
coords[coord_name].at(1),
line.c_str()
);
wmove(
window,
coords[coord_name].at(0),
coords[coord_name].at(1) + line.size()
);
}
catch (const std::invalid_argument& e) {
WPrintWAtCoord(text_win, "guess_text", e.what(), true);
getch();
}
}
void Hangman::WPrintWAtCoord(WINDOW* window, std::string coord_name, std::vector<int> offset, std::string line, bool clear_line) {
try {
if (coords.find(coord_name) == coords.end()) {
throw std::invalid_argument(coord_name + " not in coords keys");
}
if (clear_line) {
wmove(
window,
coords[coord_name].at(0) + offset.at(0),
coords[coord_name].at(1) + offset.at(1)
);
wclrtoeol(window);
}
mvwprintw(
window,
coords[coord_name].at(0) + offset.at(0),
coords[coord_name].at(1) + offset.at(1),
line.c_str()
);
wmove(
window,
coords[coord_name].at(0) + offset.at(0),
coords[coord_name].at(1) + offset.at(1) + line.size()
);
}
catch (const std::invalid_argument& e) {
WPrintWAtCoord(text_win, "guess_text", e.what(), true);
getch();
}
}
void Hangman::WPrintWSAAtCoord(WINDOW* window, std::string coord_name, std::vector<std::string> lines) {
try {
if (coords.find(coord_name) == coords.end()) {
throw std::invalid_argument(coord_name + " not in coords keys");
}
mvwprintw_sa(
window,
coords[coord_name].at(0),
coords[coord_name].at(1),
lines
);
wmove(
window,
coords[coord_name].at(0) + lines.size(),
coords[coord_name].at(1) + lines.back().size()
);
}
catch (const std::invalid_argument& e) {
WPrintWAtCoord(text_win, "guess_text", e.what(), true);
getch();
}
}
void Hangman::refresh_wins() {
wrefresh(header_win);
wrefresh(stage_win);
wrefresh(text_win);
}
void Hangman::refresh_wins(std::vector<WINDOW*> wins_to_refresh) {
for (auto win : wins_to_refresh) {
wrefresh(win);
}
}
void Hangman::reset_win(WINDOW* window) {
werase(window);
wrefresh(window);
}