-
Notifications
You must be signed in to change notification settings - Fork 0
/
map3.cpp
74 lines (56 loc) · 1.82 KB
/
map3.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
/*!
* @file map3.h v1.0
* @Copyright © 2018 Kazushi Kurasawa
* @date 2018.11.16
*
* Released under the MIT license.
* see https://opensource.org/licenses/MIT
*/
#include "map3.h"
Map3::Map3(uint8_t x_size, uint8_t y_size) {
_x_size = x_size;
_y_size = y_size;
_block = new Block* [x_size];
for (int i = 0; i < x_size; ++i) {
_block[i] = new Block[y_size]; // for(i < x_size) で _block[i] = new Block[y_size] では?
}
map_init();
}
Map3::~Map3() {
for (int i = 0; i < _y_size; ++i) {
delete _block[i];
}
delete [] _block;
}
void Map3::map_init() {
_block[0][0].set_wall(EAST_MASK + SOUTH_MASK + WEST_MASK);
_block[1][0].set_wall(WEST_MASK);
for(int i = 0; i < _x_size; i++){
_block[_x_size-1][i].set_wall(EAST_MASK);
_block[0][i].set_wall(WEST_MASK);
}
for(int i = 0; i < _y_size; i++){
_block[i][0].set_wall(SOUTH_MASK);
_block[i][_y_size-1].set_wall(NORTH_MASK);
}
}
void Map3::set_block(Block block, Point<uint8_t> point) {
_block[point.x][point.y].walk_cnt=block.walk_cnt;
_block[point.x][point.y].set_searched();
_block[point.x][point.y].set_wall(block.get_wall());
if(((block.get_wall()&NORTH_MASK) == NORTH_MASK) && (point.y < _y_size-1)) {
_block[point.x][point.y + 1].set_wall(SOUTH_MASK);
}
if(((block.get_wall()&WEST_MASK) == WEST_MASK) && (0 < point.x)) {
_block[point.x - 1][point.y].set_wall(EAST_MASK);
}
if(((block.get_wall()&EAST_MASK) == EAST_MASK) && (point.x < _x_size-1)) {
_block[point.x + 1][point.y].set_wall(WEST_MASK);
}
if(((block.get_wall()&SOUTH_MASK) == SOUTH_MASK) && (0 < point.y)) {
_block[point.x][point.y - 1].set_wall(NORTH_MASK);
}
}
Block& Map3::at(Point<uint8_t> point) {
return _block[point.x][point.y];
}