-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathField.cpp
More file actions
133 lines (115 loc) · 2.96 KB
/
Copy pathField.cpp
File metadata and controls
133 lines (115 loc) · 2.96 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
#include "Field.h"
Field::Field(int col, int row)
{
cols = col;
rows = row;
cells.resize(rows);
for (size_t i = 0; i < cells.size(); ++i)
{
cells[i].resize(cols);
}
}
int Field::get_cols()
{
return cols;
}
int Field::get_rows()
{
return rows;
}
void Field::set(int x, int y, char elem)
{
cells[y][x] = elem;
}
bool Field::is_empty(int x, int y)
{
return cells[y][x] == 0 ? true : false;
}
bool Field::can_insert_element(std::shared_ptr<Figure> figure, int cx, int cy)
{
for (std::pair<int, int> pair : figure->get_form())
{
int cc = pair.first + cx;
int rr = pair.second + cy;
// проверяем, что координаты в пределах экрана
if (cc < 0 || cc >= cols)
return false;
if (rr < 0 || rr >= rows)
return false;
if (!is_empty(cc, rr))
return false;
}
return true;
}
void Field::insert_element(std::shared_ptr<Figure> figure, int cx, int cy)
{
for (std::pair<int, int> pair : figure->get_form())
{
set(pair.first + cx, pair.second + cy, 1);
}
}
void Field::erase_element(std::shared_ptr<Figure> figure, int cx, int cy)
{
for (std::pair<int, int> pair : figure->get_form())
{
set(pair.first + cx, pair.second + cy, 0);
}
}
void Field::draw_field()
{
// получаем хэндл консоли
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
// запоминаем результаты
COORD crds{ 35, 0 };
for (int r = 0; r < rows; ++r)
{
crds.Y = r;
// устанавливаем курсор в нужную позицию
SetConsoleCursorPosition(hConsole, crds);
printf("\xB3"); // левая граница стакана
for (int c = 0; c < cols; ++c)
{
if (cells[r][c] == 0)
// выводим пустой квадратик
printf(" ");
else
// выводим заполненный квадратик
printf("\xDB\xDB");
}
printf("\xB3"); // правая граница стакана
}
crds.Y = rows;
// устанавливаем курсор в нужную позицию
SetConsoleCursorPosition(hConsole, crds);
// выводим нижнюю границу
printf("\xC0");
for (int c = 0; c < cols; ++c)
printf("\xC4\xC4");
printf("\xD9");
}
void Field::clear_field()
{
for (int r = 0; r < rows; r++)
for (int c = 0; c < cols; c++)
cells[r][c] = 0;
}
void Field::row_burning_check()//переделать логику --> пропускает некоторые ряды из-за сдвига вниз
{
for (int r = rows - 1; r >= 0; --r) {
//проверяем ряды на заполенность
int z = 0;
for (int c = 0; c < cols; ++c)
if (cells[r][c] == 1)
z++;
//если нашли ряд то сжигаем его и сдвигаем все содержимое вниз
if (z == cols) {
for (int c = 0; c < cols; ++c)
cells[r][c] = 0;
for (int r0 = r; r0 > 0; r0--)
for (int c = 0; c < cols; ++c)
cells[r0][c] = cells[r0 - 1][c];
//вот тут вставленно новое
r++;
}z = 0;
}
}