-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.cpp
129 lines (109 loc) · 2.09 KB
/
map.cpp
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
#include "map.h"
Map::Map()
= default;
Map::~Map()
= default;
void Map::mapInit()
{
for (int i = 0; i < 26; ++i) // Y坐标
{
for (int j = 0; j < 39; ++j) // X坐标
{
if (i == 0 || i == 25)
myMap[i][j] = 0; // 墙体
else
myMap[i][j] = 1; // 可移动范围
}
}
for (auto& i : myMap)
{
i[0] = 0;
i[38] = 0;
}
// 将rowFull初始化为0
for (auto& i : rowFull)
i = 0;
}
bool Map::checkMap(short x, short y) const
{
if (myMap[y][x]) // 空区域
return true;
return false;
}
void Map::mapChange(short x, short y, bool bl)
{
if (bl)
{
myMap[y][x] = 1; // 可移动区域
}
else
{
myMap[y][x] = 0; // 变为墙
}
}
void Map::printMap() const
{
for (auto& row : myMap)
{
for (auto& col : row)
{
std::cout << col;
}
std::cout << std::endl;
}
}
void Map::rowAdd(short r)
{
++rowFull[r];
// 不可在这里直接检测行是否已满,这样的话会导致部分方块没有被遍历
//consoleSet.setCursor(45,3);
//std::cout<<r<<" "<<rowFull[24];
}
void Map::rowDele(short r)
{
if (rowFull[r] == 37)
{
rowFull[r] = 0; // 清空
scores += 10; // 加分
for (int i = r; i > 1; --i)
{
for (int j = 1; j < 38; ++j)
{
myMap[i][j] = myMap[i - 1][j]; // 不断继承上一层的答案
}
rowFull[i] = rowFull[i - 1]; // 不断继承上一层
}
refreshScore(); // 刷新分数
refreshMap(r); // 刷新地图
}
}
void Map::refreshMap(short r)
{
for (int i = 1; i <= r; ++i)
{
for (int j = 1; j < 38; ++j)
{
if (myMap[i][j] == 0)
{
consoleSet.setCursor(j, i); //x-y 和 i-j 是相反的
std::cout << '*';
}
else
{
consoleSet.setCursor(j, i); //x-y 和 i-j 是相反的
std::cout << ' ';
}
}
}
}
bool Map::rowDead()
{
if (rowFull[1] > 0) // 如果首行有方块,则代表死亡
return true;
return false;
}
void Map::refreshScore()
{
consoleSet.setCursor(44, 3);
std::cout << std::setw(4) << std::setfill('0') << scores;
}