-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunifindmap.h
81 lines (77 loc) · 1.74 KB
/
unifindmap.h
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
#ifndef UNIFINDMAP_H
#define UNIFINDMAP_H
#include <QObject>
#include <QPair>
#include <QPoint>
//并查集
using v_type = QPair<size_t,size_t>;
class Set
{
public:
Set():value(v_type(0,0)){}
Set(v_type v) : value(v) {}
Set(v_type v, Set *p) : value(v), father(p) {}
Set(v_type v, Set &p) : value(v), father(&p) {}
v_type getvalue() { return value; }
Set& getroot()
{
auto root = this;
while (root->father != nullptr)
{
auto t = root->father;
root->father = t->father;
root = t;
}
return *root;
}
Set& operator+ (Set &B)
{
Union(this, &B);
return this->getroot();
}
void operator= (v_type val)
{
this->value = val;
}
bool operator== (Set &B)
{
return issame(this, &B);
}
bool operator !=(Set &B)
{
return !issame(this, &B);
}
v_type value;
bool right = false; //这地方是按X垂直向下、Y水平向右的方向写的,和Qt窗口的坐标相反……用的时候记得倒一下
bool down = false;
Set *father = nullptr;
int rank = 0;
friend bool Union(Set *A, Set *B);
friend bool issame(Set *A, Set *B);
};
//并查集地图,负责地图生成和移动判定的逻辑
class UnifindMap : public QObject
{
Q_OBJECT
public:
explicit UnifindMap(QObject *parent = nullptr);
Set map[40][30];
void run()
{
emit initmap(map);
emit moving(player,0);
}
private:
QPoint player = QPoint(30,30);
float speed;
public slots:
void Up();
void Down();
void Left();
void Right();
signals:
void initmap(const Set[][30]);
void moving(QPoint&, int);
void win();
};
#endif // UNIFINDMAP_H