-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGreedySnakeLayer.h
101 lines (74 loc) · 1.74 KB
/
GreedySnakeLayer.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
//
// GreedySnakeLayer.h
// Game
//
// Created by chenjinpeng on 15/5/9.
//
//
#ifndef __Game__GreedySnakeLayer__
#define __Game__GreedySnakeLayer__
#include "cocos2d.h"
#include "SnakeBody.h"
class GreedySnakeLayer : public cocos2d::Layer
{
private:
int score;
SnakeBody* head;
SnakeBody* food;
cocos2d::Label* label;
cocos2d::Vector<SnakeBody*> bodys;
void move();
void gameLogic(float time);
bool collide();
bool collideBorder();
bool collideSelf();
public:
GreedySnakeLayer();
~GreedySnakeLayer();
static cocos2d::Scene* scene();
virtual bool init() override;
CREATE_FUNC(GreedySnakeLayer);
void backCallback(const cocos2d::Ref* pSender);
inline void updateScore()
{
score += 100;
std::stringstream ss;
ss << "Score: " << score << std::endl;
label->setString(ss.str());
}
inline void setHead(SnakeBody* head)
{
this->head = head;
head->retain();
}
inline void setFood(SnakeBody* food)
{
this->food = food;
food->retain();
}
inline void setLabel(cocos2d::Label* label)
{
this->label = label;
label->retain();
}
inline cocos2d::Label* getLabel()
{
return label;
}
inline SnakeBody* getHead()
{
return head;
}
inline SnakeBody* getFood()
{
return food;
}
inline cocos2d::Vector<SnakeBody*>& getBodys()
{
return bodys;
}
void addNewBody();
void gameover();
bool onTouch(cocos2d::Touch* touch, cocos2d::Event* event);
};
#endif /* defined(__Game__GreedySnakeLayer__) */