This repository was archived by the owner on Jan 26, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCCanvas.cpp
More file actions
63 lines (51 loc) · 1.37 KB
/
CCanvas.cpp
File metadata and controls
63 lines (51 loc) · 1.37 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
#include "CCanvas.h"
const char CCanvas::vertical = '|';
const char CCanvas::horizontal = '-';
const char CCanvas::corner = '+';
const char CCanvas::blank = ' ';
const char CCanvas::border = '~';
const char CCanvas::circleCenter = 'X';
const char CCanvas::circleOut = '*';
const char CCanvas::fill = '#';
int CCanvas::getHeight() const {
return height;
}
int CCanvas::getWidth() const {
return width;
}
CCanvas::CCanvas(int height, int width) : height(height), width(width) {
cv = new std::string*[height];
for (int i = 0; i < height; i++) {
cv[i] = new std::string[width];
for (int j = 0; j < width; j++) {
cv[i][j] = CCanvas::blank;
}
}
}
CCanvas::~CCanvas() {
for (int i = 0; i < height; i++) {
delete[] cv[i];
}
delete[] cv;
}
void CCanvas::render(std::ostream &out) const {
for (int y = height - 1; y > - 1; y--) {
out << CCanvas::border;
for (int x = 0; x < width; x++) {
out << cv[y][x];
}
out << CCanvas::border << '\n';
}
out << std::endl;
}
void CCanvas::clear() {
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
cv[y][x] = CCanvas::blank;
}
}
}
void CCanvas::writeChecked(int x, int y, const std::string &str) {
if (x < 0 || y < 0 || x >= width || y >= height) return;
cv[y][x] = str;
}