This repository was archived by the owner on Jan 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsole.cpp
More file actions
61 lines (60 loc) · 1.5 KB
/
Copy pathconsole.cpp
File metadata and controls
61 lines (60 loc) · 1.5 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
#include "console.h"
#include <iostream>
console::console() : width(120),
height(29),
wall(char(219)),
field(' ') {
view_port.clear();
view_port.resize(width * height, field);
for (size_t i = 0; i < width - 1; ++i)
view_port[i] = view_port[i + width * (height - 1)] = wall;
for (size_t j = 0; j < height; ++j)
view_port[j * width] = view_port[j * width + width - 2] = wall;
for (size_t j = 0; j < height; ++j)
view_port[j * width + width - 1] = '\n';
}
console::console(int width_, int height_, char wall_, char field_) : width(width_ + 1),
height(height_), wall(wall_),
field(field_) {
view_port.clear();
view_port.resize(width * height);
for (size_t i = 0; i < width - 1; ++i)
view_port[i] = view_port[i + width * (height - 1)] = wall;
for (size_t j = 0; j < height; ++j)
view_port[j * width] = view_port[j * width + width - 2] = wall;
for (size_t j = 0; j < height; ++j)
view_port[j * width + width - 1] = '\n';
}
void console::print() {
std::cout << view_port;
}
void console::draw(int x, int y, char el) {
if(y*width+x<view_port.length())
if(x<width-2 && x>=1)
if (y >= 1 && y < height - 1) {
view_port[y * width + x] = el;
return;
}
game_over();
}
char console::get_field()
{
return field;
}
int console::get_heigth()
{
return height;
}
int console::get_width()
{
return width;
}
char console::get_el(int x,int y)
{
if (y * width + x < view_port.length())
if (x < width - 2 && x >= 1)
if (y >= 1 && y < height - 1) {
return view_port[y * width + x];
}
game_over();
}