-
Notifications
You must be signed in to change notification settings - Fork 1
/
snake.h
50 lines (40 loc) · 1.04 KB
/
snake.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
#ifndef SNAKE_H
#define SNAKE_H
#include <QGraphicsItemGroup>
#include <QObject>
#include <QTimer>
#include <QKeyEvent>
#include <QDebug>
#include <QList>
#include "onebox.h"
//枚举上下左右四个按键状态
enum KEY_STATUS {NOSTATUS,KEYUP,KEYDOWN,KEYLEFT,KEYRIGHT};
class Snake : public QObject
{
Q_OBJECT
public:
explicit Snake(QObject *parent = 0);
QList<OneBox *> getOneBoxList() { return oneboxList;} //返回OneBox列表
void setEatBox(OneBox *box) { eatBox = box;} //设置要吃的OneBox位置
void stop();
signals:
void addandDelBox(OneBox *addbox,OneBox *delBox);
void gameEnd();
void needNewBox();
public slots:
void keyPressEvent(QKeyEvent *event);
void timeout();
private:
bool move(KEY_STATUS status,int xy);
void changedPos(qreal x,qreal y);
void pause();
bool isColliding(KEY_STATUS status);
void addBox();
OneBox *eatBox;
unsigned int msec;
bool isPause;
QList<OneBox *> oneboxList;
QTimer timer;
KEY_STATUS current_key_status;
};
#endif // SNAKE_H