-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWall.cpp
65 lines (61 loc) · 1.52 KB
/
Wall.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
#include"Wall.h"
Wall::Wall(int Color, int Orientation, int Length, int beginx, int beginy) {
m_Color = Color;
deque<int>x;
deque<int>y;
if (Orientation == UP) {
assert(beginy - Length >= 0);
for (int i = 0; i < Length; ++i) {
x.push_back(beginx);
y.push_back(beginy - i);
}
}
else if (Orientation == DOWN) {
assert(beginy + Length < ROW);
for (int i = 0; i < Length; ++i) {
x.push_back(beginx);
y.push_back(beginy + i);
}
}
else if (Orientation == RIGHT) {
assert(beginx + Length < COL);
for (int i = 0; i < Length; ++i) {
x.push_back(beginx + i);
y.push_back(beginy);
}
}
else if (Orientation == LEFT) {
assert(beginx - Length >= 0);
for (int i = 0; i < Length; ++i) {
x.push_back(beginx - i);
y.push_back(beginy);
}
}
m_Position.push_back(x);
m_Position.push_back(y);
m_Length = Length;
}
int Wall::getColor() {
return this->m_Color;
}
bool Wall::BeHit(Snake& s) {
pair<int, int> sp = s.getPositon(0);
for (int i = 0; i < this->m_Length; ++i) {
pair<int, int> wp = this->getPositon(i);
if (wp == sp) {
return true;
}
}
return false;
}
void Wall::DrawWallBody(int x,int y) {
solidrectangle(x * CELL_SIZE + 1, y * CELL_SIZE + (CELL_SIZE)-1, x * CELL_SIZE + CELL_SIZE - 1, y * CELL_SIZE + 1); // 绘制墙体
}
void Wall::DrawWall() {
setfillcolor(this->m_Color);//墙颜色
for (int i = 0; i < this->m_Length; ++i) {
pair<int, int>p;
p = this->getPositon(i);
DrawWallBody(p.first, p.second);
}
}