-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameCommand.cpp
191 lines (150 loc) · 4.93 KB
/
GameCommand.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
#include "GameCommand.h"
//redoing with throw/catch
void DoMoveCommand(Model& model, int trainer_id, Point2D p1)
{
Trainer* trainer_ptr = model.GetTrainerPtr(trainer_id);
if (trainer_ptr == nullptr)
{
throw Invalid_Input("Please enter a valid trainer ID");
return;
}
//move trainer if pointer is valid
if (trainer_ptr)
{
trainer_ptr->StartMoving(p1);
cout << "Moving " << (trainer_ptr -> GetName()) << " to (" << p1 << ")." << endl;
return;
}
}
void DoMovePokemonCommand(Model& model, int trainer_id, int pokemon_id)
{
if (model.GetPokemonPtr(pokemon_id) == nullptr)
{
throw Invalid_Input("Please enter a valid PokemonID");
return;
}
if (model.GetTrainerPtr(trainer_id) == nullptr)
{
throw Invalid_Input("Please enter a valid Trainer ID");
return;
}
Trainer* trainer_ptr = model.GetTrainerPtr(trainer_id);
Trainer trainer = *trainer_ptr;
WildPokemon* pokemon_ptr = model.GetPokemonPtr(pokemon_id);
WildPokemon pokemon = *pokemon_ptr;
//pokemon_ptr -> follow(trainer_ptr);
pokemon_ptr -> SetupPokemonDestination();
pokemon_ptr -> UpdatePokemonLocation();
}
void DoMoveToCenterCommand(Model& model, int trainer_id, int center_id)
{
if (model.GetTrainerPtr(trainer_id) == nullptr)
{
throw Invalid_Input("Please enter the ID of an existing Trainer");
return;
}
if (model.GetPokemonCenterPtr(center_id) == nullptr)
{
throw Invalid_Input("Please enter the ID of an existing PokemonCenter");
return;
}
//dereference pointers to get trainer and center objects, then initiate movement
Trainer* trainer_ptr = model.GetTrainerPtr(trainer_id);
PokemonCenter* center_ptr = model.GetPokemonCenterPtr(center_id);
Trainer trainer = *trainer_ptr;
//move trainer to center
trainer_ptr->StartMovingToCenter(center_ptr);
cout << "Moving " << trainer.GetName() << " to PokemonCenter (" << center_id << ")." << endl;
return;
}
void DoMoveToGymCommand(Model& model, int trainer_id, int gym_id)
{
if (model.GetTrainerPtr(trainer_id) == nullptr)
{
throw Invalid_Input("Please enter the ID of an existing Trainer");
return;
}
if (model.GetPokemonGymPtr(gym_id) == nullptr)
{
throw Invalid_Input("Please enter the ID of an existing PokemonGym");
return;
}
//dereference pointers to get trainer and center objects, then initiate movement
Trainer* trainer_ptr = model.GetTrainerPtr(trainer_id);
PokemonGym* gym_ptr = model.GetPokemonGymPtr(gym_id);
Trainer trainer = *trainer_ptr;
///initiate movement
trainer_ptr->StartMovingToGym(gym_ptr);
cout << "Moving " << trainer.GetName() << " to PokemonGym (" << gym_id << ")." << endl;
return;
}
void DoStopCommand(Model& model, int trainer_id)
{
if (model.GetTrainerPtr(trainer_id) == nullptr)
{
throw Invalid_Input("Please enter the ID of an existing Trainer");
return;
}
else
{
//dereference Trainer ptr
Trainer* trainer_ptr = model.GetTrainerPtr(trainer_id);
Trainer trainer = *trainer_ptr;
//stop Trainer
trainer_ptr->Stop();
cout << "Stopping " << trainer.GetName() << endl;
return;
}
}
void DoBattleCommand(Model& model, int trainer_id, unsigned int battles)
{
if (model.GetTrainerPtr(trainer_id) == nullptr)
{
throw Invalid_Input("Please enter the ID of an existing Trainer");
return;
}
else
{
//dereference Trainer ptr
Trainer* trainer_ptr = model.GetTrainerPtr(trainer_id);
Trainer trainer = *trainer_ptr;
//trainer start battling
trainer_ptr->StartBattling(battles);
//figure out what PokemonGym the Trainer is in
PokemonGym* gym_ptr = trainer.GetCurrentGym();
if (gym_ptr == nullptr)
{
throw Invalid_Input("Trainer is not inside of a PokemonGym");
return;
}
//update center's battles_remaining count
gym_ptr -> Battle(battles);
}
}
void DoRecoverInCenterCommand(Model& model, int trainer_id, unsigned int potions_needed)
{
if (model.GetTrainerPtr(trainer_id) == nullptr)
{
throw Invalid_Input("Please enter the ID of an existing Trainer");
return;
}
else
{
//dereference Trainer ptr
Trainer* trainer_ptr = model.GetTrainerPtr(trainer_id);
Trainer trainer = *trainer_ptr;
//trainer start recovering
trainer_ptr->StartRecoveringHealth(potions_needed);
//figure out what PokemonCenter the Trainer is in
PokemonCenter* center_ptr = trainer.GetCurrentCenter();
if (center_ptr == nullptr)
{
throw Invalid_Input("Trainer is not inside of a PokemonCenter");
return;
}
//update that center's potion count
center_ptr -> DistributePotion(potions_needed);
//deduct Trainer's Pokedollar amount based on how much potion they bought
double cost = center_ptr -> GetPokeDollarCost(potions_needed);
}
}