-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWildPokemon.cpp
224 lines (179 loc) · 4.24 KB
/
WildPokemon.cpp
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
#include "WildPokemon.h"
WildPokemon::WildPokemon(string in_name, double in_attack, double in_health, bool in_variant, int in_id, Point2D in_loc)
:GameObject(in_loc, in_id, 'W')
{
attack = in_attack;
health = in_health;
speed = 3;
variant = in_variant;
in_combat = false;
current_trainer = NULL;
current_location = in_loc;
PokemonStates = IN_ENVIRONMENT;
name = in_name;
}
/*
//destructor
WildPokemon::~WildPokemon()
{
cout << "WildPokemon Object Destructed" << endl;
}
*/
//returns true if the pokemon is a variant
bool WildPokemon::get_variant()
{
return variant;
}
//returns how many attacks the pokemon has left
double WildPokemon::get_attack()
{
return attack;
}
//returns current health of pokemon
double WildPokemon::get_health()
{
return health;
}
//returns combat state
bool WildPokemon::get_in_combat()
{
return in_combat;
}
int WildPokemon::GetPokemonID()
{
return id_num;
}
Point2D WildPokemon::GetLocation()
{
return current_location;
}
//sets the current trainer
void WildPokemon::follow(Trainer* trainer_input)
{
if (trainer_input == nullptr)
{
return;
}
//select trainer, get name
current_trainer = trainer_input;
string trainer_name = current_trainer -> GetName();
//set
Point2D trainer_location = current_trainer -> GetLocation();
if ((trainer_location.x == current_location.x) && (trainer_location.y == current_location.y))
{
PokemonStates = IN_TRAINER;
cout << name << " started following " << trainer_name << endl;
SetupPokemonDestination();
UpdatePokemonLocation();
}
}
//returns true if pokemon dies
bool WildPokemon::IsAlive()
{
if (health == 0)
{
return true;
}
else
{
return false;
}
}
void WildPokemon::SetupPokemonDestination()
{
//set destination to trainer's current location
destination = current_trainer -> GetLocation();
double distance = GetDistanceBetween(destination, location);
if (distance == 0)
{
distance = 1;
}
pokemon_delta = (destination - location) * (speed/distance);
//pokemon_delta = (destination - location) * speed;
}
bool WildPokemon::UpdatePokemonLocation()
{
//get information from Trainer so we can get name
string trainer_name = current_trainer -> GetName();
//if dead, stop output
if (PokemonStates == DEAD)
{
return false;
}
//in all other cases, perform one step of movement
else
{
PokemonStates = IN_TRAINER;
//cout << name << " is following " << trainer_name << endl;
location = location + pokemon_delta;
return false;
}
}
//CHANGE THIS WHEN WE FIGURE OUT HOW TO DO STATE MACHINE
bool WildPokemon::Update()
{
cout << "*******************************************************************" << endl;
cout << name << " Update: " << endl;
cout << "Attacks left: " << attack << endl;
cout << "Health: " << health << endl;
if (current_trainer == nullptr)
{
return false;
}
string trainer_name = current_trainer -> GetName();
//POTENTIALLY UPDATE LATER SO POKEMON IS REMOVED FROM BOARD
if (PokemonStates == DEAD)
{
cout << name << " is dead." << endl;
return true;
}
//IN_ENVIRONMENT
else if (PokemonStates == IN_ENVIRONMENT)
{
cout << name << " is running free through the tall grass." << endl;
return false;
}
//IN_TRAINER
else if (PokemonStates == IN_TRAINER)
{
//update location, perform movement
SetupPokemonDestination();
UpdatePokemonLocation();
if (PokemonStates == DEAD)
{
cout << name << " has died." << endl;
return false;
}
if (health >= 1)
{
//subtract health for both Trainer and Pokemon
health = health - 1;
current_trainer -> ReduceTrainerHealth();
return false;
}
//health is never negative
if (health < 0)
{
health = 0;
PokemonStates = DEAD;
return false;
}
//clause for if pokemon dies while battling
if (health = 0)
{
PokemonStates = DEAD;
cout << name << " has died." << endl;
return false;
}
cout << name << " is following " << trainer_name << endl;
}
return false;
}
void WildPokemon::ShowStatus()
{
cout << "WildPokemon Status: " << endl;
}
bool WildPokemon::ShouldBeVisible()
{
return true;
}