-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plant.h
139 lines (126 loc) · 2.24 KB
/
Plant.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
#pragma once
#include "config.h"
#include <map>
class Plant
{
protected:
PLANT PLANT_ID; //植物id,表示种类,枚举类型
int FULL_HP; //植物满血血量
int ATK; //攻击力
int AS; //攻速
int COLOR; //植物显示颜色
int current_hp; //植物当前血量
bool valid; //是否存活
Pos pos; //植物位置
int status_count; //攻击状态计数,达到等待时间后攻击
int color_count; //颜色变化计数
public:
//构造函数,提供植物类型和坐标
Plant(PLANT pid, int x, int y);
//被吃,返回存活状态
bool beEaten(int atk);
//获取植物坐标
Pos getPos() const;
//获取植物ID
PLANT getID() const;
//获取植物存活状态
bool isValid() const;
//攻击,纯虚函数,在具体的植物类中定义
virtual void hit() = 0;
//显示植物,友元函数,在UI模块定义
friend void showPlant(const Plant& plant);
friend void fixPlant(const Plant& plant);
};
class PlantList
{
private:
std::map<Pos, Plant*, Pos_less> plant_list;
std::map<Pos, Plant*, Pos_less> pumpkin_list;
public:
PlantList();
~PlantList();
void reinit();
// 添加植物,sure参数表示确定覆盖旧植物
bool addPlant(Plant* plant, bool sure = 0);
// 遍历每个植物做一次 hit 函数
void plantsOperate();
Plant* getPlant(int r, int c);
};
class Sunflower : public Plant
{
public:
// 构造函数,传递行列号
Sunflower(int r, int c);
// 向日葵用攻击函数作为产生向日葵的函数
void hit();
};
class PeaShooter : public Plant
{
public:
// 构造函数,传递行列号
PeaShooter(int r, int c);
// 攻击函数
void hit();
};
class DoubleShooter : public Plant
{
private:
int hit_count;
public:
// 构造函数,传递行列号
DoubleShooter(int r, int c);
// 攻击函数
void hit();
};
class Nut : public Plant
{
public:
Nut(int r, int c, PLANT id = PLANT::NUT);
void hit();
};
class Potato : public Plant
{
int is_ready;
int ready_count;
public:
Potato(int r, int c);
void hit();
};
class IceShooter : public Plant
{
int ice_time;
public:
IceShooter(int r, int c);
void hit();
};
class HighNut : public Nut
{
public:
HighNut(int r, int c);
};
class Squash : public Plant
{
int attack;
public:
Squash(int r, int c);
void hit();
};
class Cherry : public Plant
{
int attack;
public:
Cherry(int r, int c);
void hit();
};
class Garlic : public Plant
{
public:
Garlic(int r, int c);
void hit();
};
class Pumpkin : public Plant
{
public:
Pumpkin(int r, int c);
void hit();
};