-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpokemon.cpp
More file actions
239 lines (219 loc) · 8.41 KB
/
pokemon.cpp
File metadata and controls
239 lines (219 loc) · 8.41 KB
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#include "pokemon.h"
// 获取精灵球信息
PokeBall getPokeBallInfo(PokeBallType type) {
switch (type) {
case PokeBallType::PokeBall:
return {PokeBallType::PokeBall, "精灵球", 1.0f};
case PokeBallType::GreatBall:
return {PokeBallType::GreatBall, "超级球", 1.5f};
case PokeBallType::UltraBall:
return {PokeBallType::UltraBall, "高级球", 2.0f};
case PokeBallType::MasterBall:
return {PokeBallType::MasterBall, "大师球", 5.0f};
default:
return {PokeBallType::PokeBall, "精灵球", 1.0f};
}
}
// 属性名称
std::string getTypeName(Type type) {
switch (type) {
case Type::Normal: return "一般";
case Type::Fire: return "火";
case Type::Water: return "水";
case Type::Grass: return "草";
case Type::Electric: return "电";
case Type::Ice: return "冰";
case Type::Fighting: return "格斗";
case Type::Ground: return "地面";
case Type::Flying: return "飞行";
default: return "未知";
}
}
// 属性克制关系表
float getTypeEffectiveness(Type attackType, Type defendType) {
// 克制关系:攻击属性 vs 防御属性
switch (attackType) {
case Type::Normal:
return 1.0f;
case Type::Fire:
if (defendType == Type::Grass) return 2.0f;
if (defendType == Type::Ice) return 2.0f;
if (defendType == Type::Water) return 0.5f;
if (defendType == Type::Fire) return 0.5f;
return 1.0f;
case Type::Water:
if (defendType == Type::Fire) return 2.0f;
if (defendType == Type::Ground) return 2.0f;
if (defendType == Type::Grass) return 0.5f;
if (defendType == Type::Water) return 0.5f;
return 1.0f;
case Type::Grass:
if (defendType == Type::Water) return 2.0f;
if (defendType == Type::Ground) return 2.0f;
if (defendType == Type::Fire) return 0.5f;
if (defendType == Type::Grass) return 0.5f;
return 1.0f;
case Type::Electric:
if (defendType == Type::Water) return 2.0f;
if (defendType == Type::Flying) return 2.0f;
if (defendType == Type::Grass) return 0.5f;
if (defendType == Type::Electric) return 0.5f;
if (defendType == Type::Ground) return 0.0f; // 无效
return 1.0f;
case Type::Ice:
if (defendType == Type::Grass) return 2.0f;
if (defendType == Type::Ground) return 2.0f;
if (defendType == Type::Flying) return 2.0f;
if (defendType == Type::Fire) return 0.5f;
if (defendType == Type::Ice) return 0.5f;
return 1.0f;
case Type::Fighting:
if (defendType == Type::Normal) return 2.0f;
if (defendType == Type::Ice) return 2.0f;
if (defendType == Type::Flying) return 0.5f;
return 1.0f;
case Type::Ground:
if (defendType == Type::Fire) return 2.0f;
if (defendType == Type::Electric) return 2.0f;
if (defendType == Type::Grass) return 0.5f;
if (defendType == Type::Flying) return 0.0f; // 无效
return 1.0f;
case Type::Flying:
if (defendType == Type::Grass) return 2.0f;
if (defendType == Type::Fighting) return 2.0f;
if (defendType == Type::Electric) return 0.5f;
if (defendType == Type::Ice) return 0.5f;
return 1.0f;
default:
return 1.0f;
}
}
Pokemon::Pokemon() : level(1), exp(0), maxExp(100), type(Type::Normal) {}
Pokemon::Pokemon(const std::string& sp, int lvl)
: species(sp), level(lvl), exp(0), maxExp(100) {
name = sp;
initStats();
initMoves();
}
void Pokemon::initStats() {
if (species == "小火龙") {
type = Type::Fire;
stats = {30, 30, 10, 8, 10};
} else if (species == "杰尼龟") {
type = Type::Water;
stats = {32, 32, 9, 10, 7};
} else if (species == "妙蛙种子") {
type = Type::Grass;
stats = {31, 31, 10, 9, 8};
} else if (species == "小拉达") {
type = Type::Normal;
stats = {25, 25, 9, 7, 11};
} else if (species == "波波") {
type = Type::Flying;
stats = {26, 26, 8, 8, 10};
} else if (species == "绿毛虫") {
type = Type::Grass;
stats = {24, 24, 7, 7, 7};
} else if (species == "小雀蜂") {
type = Type::Flying;
stats = {23, 23, 8, 7, 9};
} else if (species == "独角虫") {
type = Type::Grass;
stats = {24, 24, 7, 7, 7};
} else if (species == "派拉斯") {
type = Type::Grass;
stats = {27, 27, 9, 8, 6};
} else if (species == "皮卡丘") {
type = Type::Electric;
stats = {26, 26, 10, 7, 12};
} else if (species == "可达鸭") {
type = Type::Water;
stats = {28, 28, 9, 9, 7};
} else if (species == "小海狮") {
type = Type::Ice;
stats = {27, 27, 8, 8, 8};
} else if (species == "角金鱼") {
type = Type::Water;
stats = {26, 26, 9, 8, 9};
} else if (species == "小拳石") {
type = Type::Ground;
stats = {30, 30, 10, 11, 5};
} else if (species == "大岩蛇") {
type = Type::Ground;
stats = {35, 35, 9, 13, 6};
} else if (species == "超音蝠") {
type = Type::Flying;
stats = {25, 25, 8, 7, 11};
} else if (species == "腕力") {
type = Type::Fighting;
stats = {30, 30, 11, 8, 6};
} else if (species == "地鼠") {
type = Type::Ground;
stats = {26, 26, 9, 8, 10};
} else {
type = Type::Normal;
stats = {25, 25, 9, 9, 9};
}
stats.maxHp += level * 3;
stats.hp = stats.maxHp;
stats.attack += level;
stats.defense += level;
stats.speed += level;
}
void Pokemon::initMoves() {
moves.clear();
// 共同技能:所有宝可梦都会的技能
Move tackle = {"撞击", Type::Normal, 40, 100, false};
Move growl = {"叫声", Type::Normal, 0, 100, false}; // 0 威力为变化技能
moves.push_back(tackle);
moves.push_back(growl);
// 根据属性添加第二个共同技能
if (type == Type::Fire) {
Move ember = {"火花", Type::Fire, 40, 100, false};
moves.push_back(ember);
} else if (type == Type::Water) {
Move watergun = {"水枪", Type::Water, 40, 100, false};
moves.push_back(watergun);
} else if (type == Type::Grass) {
Move vinewhip = {"藤鞭", Type::Grass, 45, 100, false};
moves.push_back(vinewhip);
} else if (type == Type::Electric) {
Move thundershock = {"电击", Type::Electric, 40, 100, false};
moves.push_back(thundershock);
} else if (type == Type::Ice) {
Move powdersnow = {"粉末雪", Type::Ice, 40, 100, false};
moves.push_back(powdersnow);
} else if (type == Type::Fighting) {
Move lowkick = {"踢倒", Type::Fighting, 50, 100, false};
moves.push_back(lowkick);
} else if (type == Type::Ground) {
Move mudslap = {"掷泥", Type::Ground, 20, 100, false};
moves.push_back(mudslap);
} else if (type == Type::Flying) {
Move gust = {"起风", Type::Flying, 40, 100, false};
moves.push_back(gust);
}
// 专属技能(根据物种)
if (species == "小火龙") {
Move flamethrower = {"喷射火焰", Type::Fire, 90, 100, true};
moves.push_back(flamethrower);
} else if (species == "杰尼龟") {
Move hydropump = {"水炮", Type::Water, 110, 80, true};
moves.push_back(hydropump);
} else if (species == "妙蛙种子") {
Move solarbeam = {"日光束", Type::Grass, 120, 100, true};
moves.push_back(solarbeam);
} else if (species == "皮卡丘") {
Move thunderbolt = {"十万伏特", Type::Electric, 90, 100, true};
moves.push_back(thunderbolt);
} else if (species == "波波") {
Move whirlwind = {"暴风", Type::Flying, 110, 70, true};
moves.push_back(whirlwind);
} else if (species == "腕力") {
Move crosschop = {"十字劈", Type::Fighting, 100, 80, true};
moves.push_back(crosschop);
}
}
bool Pokemon::isFainted() const {
return stats.hp <= 0;
}