-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.cpp
98 lines (88 loc) · 2.55 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
#include "map.h"
#include "global_consts.h"
#include <QtDebug>
Map::Map(QGraphicsScene * scene)
: scene(scene)
{
QPen pen;
pen.setWidth(3);
line1 = new QGraphicsLineItem(0, 0, MAP_SIZE_X_FULL, 0);
line1->setPen(pen);
line2 = new QGraphicsLineItem(MAP_SIZE_X_FULL, 0, MAP_SIZE_X_FULL, MAP_SIZE_Y_FULL);
line2->setPen(pen);
line3 = new QGraphicsLineItem(MAP_SIZE_X_FULL, MAP_SIZE_Y_FULL, 0, MAP_SIZE_Y_FULL);
line3->setPen(pen);
line4 = new QGraphicsLineItem(0, MAP_SIZE_Y_FULL, 0, 0);
line4->setPen(pen);
scene->addItem(line1);
scene->addItem(line2);
scene->addItem(line3);
scene->addItem(line4);
vector.resize(MAP_SIZE_X_10+1);
int i = 0;
for (auto it = vector.begin(); it != vector.end(); ++it)
{
(*it).resize(MAP_SIZE_Y_10+1);
int j = 0;
for (auto it2 = (*it).begin(); it2 != (*it).end(); ++it2)
{
(*it2) = new GridElement(i, j);
j++;
}
i++;
}
addBuilding(QPoint(40,28));
addBuilding(QPoint(40,32));
addBuilding(QPoint(6,56));
addBuilding(QPoint(47,28));
addBuilding(QPoint(23,0));
addBuilding(QPoint(56,54));
addBuilding(QPoint(67,9));
addBuilding(QPoint(82,79));
addBuilding(QPoint(98,85));
addBuilding(QPoint(125,12));
addBuilding(QPoint(100,100));
addBuilding(QPoint(63,98));
addBuilding(QPoint(2,60));
addBuilding(QPoint(35,85));
addBuilding(QPoint(52,115));
addBuilding(QPoint(74,96));
addBuilding(QPoint(89,95));
}
QVector<QPointF> neighbours(GridElement * center)
{
QVector<QPointF> n;
if (center->x() - 1 >= 0)
n.append(QPointF(center->x() - 1, center->y()));
if (center->x() + 1 <= MAP_SIZE_X_10)
n.append(QPointF(center->x() + 1, center->y()));
if (center->y() - 1 >= 0)
n.append(QPointF(center->x(), center->y() - 1));
if (center->y() + 1 <= MAP_SIZE_Y_10)
n.append(QPointF(center->x(), center->y() + 1));
return n;
}
void Map::addBuilding(QPointF p)
{
Building * building = new Building();
building->setPos(p.x() * 10, p.y() * 10);
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
vector[p.x() + i][p.y() + j]->toggleTaken();
scene->addItem(building);
}
void Map::addChest(QPointF p)
{
Chest * chest = new Chest();
chest->setPos(p.x() * 10, p.y() * 10);
vector[p.x()][p.y()]->toggleTaken();
vector[p.x()+1][p.y()]->toggleTaken();
scene->addItem(chest);
}
Map::~Map()
{
delete line1;
delete line2;
delete line3;
delete line4;
}