-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.h
53 lines (48 loc) · 1.23 KB
/
map.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
#ifndef MAP_H
#define MAP_H
#include <QWidget>
#include <QTimer>
#include <QVector>
#include "snake.h"
#include "foods.h"
#include "walls.h"
#include "aisnake.h"
#include "constants.h"
class Map : public QWidget
{
Q_OBJECT
friend QDataStream& operator<<(QDataStream& out, const Map& map);
friend QDataStream& operator>>(QDataStream& in, Map& map);
public:
explicit Map(QWidget *parent = nullptr);
void init();
void addPlayer(Snake* player);
void pause();
void resume();
void setWallType(WallType type);
void startEditing();
void finishEditing();
void changeEditItem(MapItem item);
void keyPressEvent(QKeyEvent *event) override;
~Map();
protected:
void paintEvent(QPaintEvent *event) override;
void resizeEvent(QResizeEvent *event) override;
void mousePressEvent(QMouseEvent *) override;
private:
QVector<Snake*> players;
Foods *foods;
Walls *walls;
QTimer *timer;
int scale;
bool editing = false;
MapItem editingItem = WALLS;
WallType wallType = NONE;
int selectedFoodIndex = 0;
void initWalls();
void connectFoodsAndWalls();
QPoint convert2MapPoint(int x, int y);
public slots:
void changeFoodType(int foodIndex);
};
#endif // MAP_H