-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgame.h
159 lines (134 loc) · 4.41 KB
/
game.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#ifndef GAME_H
#define GAME_H
#include "field.h"
#include "snake.h"
#include <ctime>
#include <string>
enum GameMode {TIMELIMIT=0, TIMEFREE, KILLSNAKE};
enum PlayMode {Normal=0};
class Game
{
public:
Game(GameMode game_mode, int height, int width, std::vector<int> info);
Game(Field* state, GameMode game_mode, std::vector<int> info);
void setBeginTime(clock_t);
// 核心运行, 包含 [一轮时钟周期里] 对 [一条蛇] 的全部操作
bool snakeAction(Snake*);
// 核心运行, 包含 [对时钟的控制] [接收决策信号] [对每条蛇的 snakeAction() 的调用]
short runGame();
virtual bool createFood() { return false; }
virtual bool createSnake() { return false; }
// 用来给图形界面初始化信息
virtual void initializeGame(int level);
// 全局陨石掉落信息
void countDown();
bool isFall();
bool isWarning();
//地图载入
bool loadMap(std::string map_path);
//判断游戏是否结束
short reachTarget();
Field* getState();
int getTargetTime();
int getTargetScore();
GameMode getMode();
protected:
int target_score = 0;
//游戏难度
int level = 1;
int target_time = 0;
GameMode game_mode;
int aerolite_counting = 2;
clock_t begin = 0;
// state 里面有: [地图] [Item] [snakes]
Field* state;
};
class Level1: public Game
{
public:
Level1(GameMode game_mode, int height, int width, std::vector<int> info);
Level1(Field* state, GameMode game_mode, std::vector<int> info);
virtual void initializeGame(int level);
virtual bool createFood() { return true; }
};
class Level2: public Game
{
public:
Level2(GameMode game_mode, int height, int width, std::vector<int> info);
Level2(Field* state, GameMode game_mode, std::vector<int> info);
virtual void initializeGame(int level);
virtual bool createFood() { return true; }
};
class Level3: public Game
{
public:
Level3(GameMode game_mode, int height, int width, std::vector<int> info);
Level3(Field* state, GameMode game_mode, std::vector<int> info);
virtual void initializeGame(int level);
};
class Level4: public Game
{
public:
Level4(GameMode game_mode, int height, int width, std::vector<int> info);
Level4(Field* state, GameMode game_mode, std::vector<int> info);
virtual void initializeGame(int level);
};
class Level5: public Game
{
public:
Level5(GameMode game_mode, int height, int width, std::vector<int> info);
Level5(Field* state, GameMode game_mode, std::vector<int> info);
virtual void initializeGame(int level);
};
class Level6: public Game
{
public:
Level6(GameMode game_mode, int height, int width, std::vector<int> info);
Level6(Field* state, GameMode game_mode, std::vector<int> info);
virtual void initializeGame(int level);
};
class Level7: public Game
{
public:
Level7(GameMode game_mode, int height, int width, std::vector<int> info);
Level7(Field* state, GameMode game_mode, std::vector<int> info);
virtual void initializeGame(int level);
};
class Level8: public Game
{
public:
Level8(GameMode game_mode, int height, int width, std::vector<int> info);
Level8(Field* state, GameMode game_mode, std::vector<int> info);
virtual void initializeGame(int level);
};
class Level9: public Game
{
public:
Level9(GameMode game_mode, int height, int width, std::vector<int> info);
Level9(Field* state, GameMode game_mode, std::vector<int> info);
virtual void initializeGame(int level);
};
class Level10: public Game
{
public:
Level10(GameMode game_mode, int height, int width, std::vector<int> info);
Level10(Field* state, GameMode game_mode, std::vector<int> info);
virtual void initializeGame(int level);
};
class Level11: public Game
{
public:
Level11(GameMode game_mode, int height, int width, std::vector<int> info);
Level11(Field* state, GameMode game_mode, std::vector<int> info);
virtual void initializeGame(int level);
};
class Greedy : public Game
{
public:
Greedy(GameMode game_mode, int height, int width, std::vector<int> info);
Greedy(Field* state, GameMode game_mode, std::vector<int> info);
virtual void initializeGame(int level);
virtual bool createSnake() { return true; }
virtual bool createFood() { return true; }
};
#endif // GAME_H