-
Notifications
You must be signed in to change notification settings - Fork 0
/
scene.h
122 lines (97 loc) · 2.3 KB
/
scene.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
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
#ifndef SCENE_H
#define SCENE_H
#include <QGraphicsScene>
#include <QTimer>
#include <QList>
#include "spirit.h"
#include "channel.h"
QT_BEGIN_NAMESPACE
class QGraphicsSceneMouseEvent;
class QKeyEvent;
QT_END_NAMESPACE
struct SpiritInfo;
class AvatarSpirit;
class Scene : public QGraphicsScene
{
Q_OBJECT
public:
Scene(QObject *parent);
~Scene();
enum Tool
{
T_NONE = -1,
T_ERASER,
T_BLOCK,
T_CHEESE,
T_NAIL,
T_BOMB,
T_MOUSE,
T_CAT,
T_ELEPHANT
};
int load(const QString &file);
void save(const QString &file);
void build(int width = -1, int height = -1);
void pause();
void resume();
void setCurTool(Tool);
void speedUp();
void speedDown();
bool empty();
int width();
int height();
void genRandSpirit(int num, const QList<Spirit::SType> &types);
void setTeachSpirit(AvatarSpirit *spt);
void clearTeachSpirit();
QList<SpiritInfo> statistics();
QPoint calGridPos(const QPointF &);
Spirit *getSpiritAt(int grid_x, int grid_y);
bool outOfLimitLine(const QPoint &grid_pos);
signals:
void spiritsNumChanged(int);
void paused();
void resumed();
void currentSpeedLevel(int);
private slots:
void step();
private:
// current tool
Tool cur_tool;
// mice
QList<Spirit *> spirits;
AvatarSpirit *teach_spirit;
int mouse_id;
int cat_id;
int elephant_id;
// control
QTimer *timer;
int timer_interval;
private:
int num_blocks;
int num_cheeses;
int num_nails;
int num_bombs;
int num_mice;
int num_cats;
int num_elephants;
Channel *channel;
int _width;
int _height;
void drawAxis();
void drawLimitLine();
void useToolAt(const QPoint &grid_pos);
void addSpiritAt(Spirit::SType type, const QPoint &grid_pos);
void removeSpiritAt(const QPoint &grid_pos);
QPoint findAvatarNewPos(const QPoint &grid_pos, bool *found);
Spirit *newSpiritAt(Spirit::SType type, const QPoint &grid_pos);
void removeSpirit(Spirit *spt);
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void keyPressEvent(QKeyEvent *keyEvent);
};
struct SpiritInfo
{
QString name;
int num;
};
#endif // SCENE_H