Skip to content

Commit 8cde744

Browse files
committed
More comments and removal of commented code in Player.h and Pokemon.h
1 parent a4a882d commit 8cde744

File tree

2 files changed

+34
-64
lines changed

2 files changed

+34
-64
lines changed

Player.h

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <vector>
77
#include <fstream>
88
#include "Pokemon.h"
9-
#include "Squirtle.h"
9+
#include "Squirtle.h" // include each specific Pokemon class
1010
#include "Pikachu.h"
1111
#include "Bulbasaur.h"
1212
#include "Charmander.h"
@@ -91,7 +91,7 @@ void Player::Battle(){
9191
//function for adding a new pokemon into players array
9292
void Player::add_pokemon(int PokeNum, int person, int levelDesired){ //person 1 or 0 for player or npc
9393
Pokemon *newPoke_ptr;
94-
switch(PokeNum) {
94+
switch(PokeNum) { // structure to instantiate specific Pokemon class
9595
case 1:
9696
newPoke_ptr = new Rattata;
9797
break;
@@ -177,7 +177,7 @@ int Player::noValid(){
177177
int found = 0;
178178
for(int i = 0; i < myPoke.size(); i++){
179179
if((*myPoke[i]).getKO() == 0){
180-
found = 1;
180+
found = 1; // at least one Pokemon is not KO'd
181181
cout << (*myPoke[i]).getname() << " in position " << i << " is ready to fight" << endl;
182182
}
183183
}
@@ -190,31 +190,31 @@ int Player::noValid_other(){
190190
int found = 0;
191191
for(int i = 0; i < otherPoke.size(); i++){
192192
if((*otherPoke[i]).getKO() == 0){
193-
found = 1;
193+
found = 1; // at least one Pokemon is not KO'd
194194
}
195195
}
196196
if(found)
197197
return 0;
198198
else
199199
return 1; //no valid pokemon
200200
}
201-
void Player::wild_battle(int level_enc){
201+
void Player::wild_battle(int level_enc){ // Wild grass Pokemon battle
202202
otherPoke.clear();
203203
add_pokemon((rand()%16)+1,0,level_enc); // comp rand
204204
op = 0; //opponent poke
205205
cout << endl << "Wild Battle!" << endl;
206206
cout << "A Wild, Level " << (*otherPoke[op]).getlevel() << " " << (*otherPoke[op]).getname() << " appeared!" << endl << endl;
207207
}
208208

209-
void Player::fish_battle(int level_enc){
209+
void Player::fish_battle(int level_enc){ // Water Pokemon battle
210210
otherPoke.clear();
211211
cout << endl << "Fish Battle!" << endl;
212-
add_pokemon(rand_between(9,10),0,level_enc); // comp rand
212+
add_pokemon(rand_between(9,10),0,level_enc); // comp rand, ensures Water type Pokemon
213213
op = 0; //opponent poke
214214
cout << "A Wild, Level " << (*otherPoke[op]).getlevel() << " " << (*otherPoke[op]).getname() << " was hooked!" << endl << endl;
215215
}
216216

217-
void Player::player_battle(int pick, int level_enc){
217+
void Player::player_battle(int pick, int level_enc){ // Battle against a Pokemon trainer
218218
otherPoke.clear(); //clear other so that it can be filled with player pokemon
219219
cout << endl << "Trainer Battle!" << endl;
220220
create_trainer(pick,level_enc);
@@ -223,15 +223,15 @@ void Player::player_battle(int pick, int level_enc){
223223

224224
void Player::pokeCenter(int whiteout){
225225
for(int i = 0; i < myPoke.size(); i++){
226-
(*myPoke[i]).heal();
226+
(*myPoke[i]).heal(); // heal all Pokemon
227227
if(whiteout){
228228
(*myPoke[i]).setexp(0); //clear current experience on whiteout
229229
}
230230
}
231231
}
232232

233233
void Player::create_trainer(int pick, int level_enc){
234-
otherPoke.clear();
234+
otherPoke.clear(); // gives trainers semi-random Pokemon
235235
switch(pick){
236236
case 1: //chick fire and norm
237237
add_pokemon(rand_between(11,12),0,level_enc); //fire
@@ -271,10 +271,10 @@ void Player::create_trainer(int pick, int level_enc){
271271

272272
void Player::save_pokemon_stats(){
273273
ofstream outFile;
274-
outFile.open( "savePoke.txt", ios::out );
274+
outFile.open( "savePoke.txt", ios::out ); // specify file
275275
outFile << myPoke.size() << " "; //how many pokemon
276276
outFile << cp << endl; //current pokemon
277-
for(int i = 0; i < myPoke.size(); i++){
277+
for(int i = 0; i < myPoke.size(); i++){ // save all Pokemon stats
278278
outFile << (*myPoke[i]).getnum() << " ";
279279
outFile << (*myPoke[i]).getmaxHealth() << " ";
280280
outFile << (*myPoke[i]).getcurrHealth() << " ";
@@ -299,13 +299,13 @@ void Player::load_pokemon_stats(){
299299
ifstream inFile;
300300
string inStr;
301301
int inInt, numPoke;
302-
inFile.open( "savePoke.txt",ios::in);
302+
inFile.open( "savePoke.txt",ios::in); // specify file
303303
inFile >> numPoke;
304304
inFile >> cp;
305305
for(int i = 0; i < numPoke; i++){
306306
inFile >> inInt;
307307
add_pokemon(inInt,1,0); //adds certain pokemon in then loads the stats so the moves are saved!
308-
inFile >> inInt;
308+
inFile >> inInt; // set all Pokemon stats
309309
(*myPoke[i]).setmaxHealth(inInt);
310310
inFile >> inInt;
311311
(*myPoke[i]).setcurrHealth(inInt);
@@ -341,7 +341,7 @@ void Player::load_pokemon_stats(){
341341
void Player::learnNewMove(int i){
342342
(*myPoke[i]).learnNewMove(); //teach pokemon i the new move
343343
}
344-
int Player::rand_between(int a, int b){
344+
int Player::rand_between(int a, int b){ // used for semi-randomness
345345
return((rand() % (b - a + 1)) + a);
346346
}
347347
int Player::getNumPoke(){
@@ -350,7 +350,7 @@ int Player::getNumPoke(){
350350
int Player::whatToDo(){
351351
int choice;
352352
cout << "What would you like to do: 1 fight, 2 catch, 3 run";
353-
cin >> choice;
353+
cin >> choice; // uses this to control game flow
354354
}
355355
int Player::fight(int userMove){
356356
cout << "Level " << (*myPoke[cp]).getlevel() << " " <<(*myPoke[cp]).getname() << " attacked with " << (*myPoke[cp]).attackname(userMove-1) << endl;
@@ -364,11 +364,11 @@ int Player::fight(int userMove){
364364
return 0;
365365
}
366366
int Player::catchPoke(){
367-
if(myPoke.size()!=6){
368-
int value = rand()%100;
367+
if(myPoke.size()!=6){ // have room for more Pokemon
368+
int value = rand()%100; // value to compare health fraction to
369369
double max = (*otherPoke[op]).getmaxHealth();
370370
double curr = (*otherPoke[op]).getcurrHealth();
371-
if(value > ((curr/max)*100)){
371+
if(value > ((curr/max)*100)){ // catch Pokemon
372372
cout << "Caught" << endl;
373373
myPoke.push_back(otherPoke[op]);
374374
otherPoke.clear(); //get rid of him

Pokemon.h

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class Pokemon{
7575
int currHealth;
7676
int level;
7777
int exp;
78-
int maxLevelExp;
78+
int maxLevelExp; // experience needed to level up
7979
int maxAttack;
8080
int currAttack;
8181
int maxDef;
@@ -84,8 +84,8 @@ class Pokemon{
8484
int currSpeed;
8585
int KO; // boolean var
8686
int moveLevel; // level at which Pokemon learns fifth move
87-
string type;
88-
string name;
87+
string type; // Pokemon elemental type
88+
string name; // Pokemon name
8989
string weak; // type Pokemon is weak to
9090
vector <string> attackName;//how can we still utilize this given the Moves class?
9191
vector <Moves> myMoves;// then we can use for example myMoves[2].attack()
@@ -95,10 +95,6 @@ Pokemon::Pokemon(){
9595
srand(time(NULL)); // seed rand
9696
maxLevelExp = 50; //genaric maxlevelexp
9797
}
98-
//non-default for loading a pokemon
99-
//Pokemon::Pokemon(int,int,int,int,int,int,int,int,int,int,int,int,string,string,string){ //check if knows 5 move
100-
101-
//}
10298

10399
void Pokemon::setnum(int n) {
104100
num = n;
@@ -120,21 +116,9 @@ void Pokemon::levelUp() {
120116
exp = exp - maxLevelExp; // set exp to the overflow
121117
maxLevelExp+=30; //increase max exp to next level up
122118
maxAttack += (rand() % 4) + 1; // add a random attack stat amount
123-
// Don't increment current attack?
124119
maxDef += (rand() % 4) + 1; // increment defense by a random stat amount
125-
// Don't increment current def?
126120
maxSpeed += (rand() % 4) + 1; // increment speed
127-
// Don't increment current Speed?
128-
// KO does not change
129-
130-
// If necessary, add a new move
131-
/*
132-
myMoves[0] = myMoves[1];
133-
myMoves[1] = myMoves[2];
134-
myMoves[2] = myMoves[3];
135-
myMoves.pop_back(); // remove move from back
136-
myMoves.push_back(newmove); // add new move to the back
137-
*/
121+
138122
if(level == moveLevel){ //at level 5 learn new moves
139123
cout << "Learned new move: " << myMoves[4].display() << " Replaced move: " << myMoves[0].display() << endl;
140124
myMoves[0] = myMoves[1]; // first move is removed
@@ -157,39 +141,24 @@ void Pokemon::setcurrHealth(int h) {
157141
if(h > 0)
158142
currHealth = h; // sets new health
159143
else
160-
currHealth = 0;
144+
currHealth = 0; // fallback value
161145
}
162146

163147
void Pokemon::inccurrHealth(int add) {
164148
currHealth += add; //inc health for potion and other increases
165149
}
166-
/*void Pokemon::attack(int moveNum){ //attack function that calls certain moveNumber
167-
int userNum; //input by user, can be removed
168-
while (userNum != -1){ //just a way to check each attack
169-
cout << "What attack would you like to use (1-4): "; //1-2 right now
170-
cin >> userNum; //user enters attack
171-
if(userNum > 0 && userNum < 5){ //makes sure attack is in vector and 1 - 4
172-
cout << "Move number "<< userNum <<" is " << myMoves[userNum-1].display() << endl;
173-
int damage = myMoves[userNum-1].attack(maxAttack); //calculate damage eventually take into account weaknesses and such
174-
cout << "The attack did " << damage << " damage!" << endl; //display results
175-
subHealth(damage); // subtract health based on damage dealt
176-
}
177-
}
178-
}*/
179150

180151
void Pokemon::attack(int attackNum,Pokemon* poke_damage_ptr){ //attack function that calls certain moveNumber
181-
//cout << "Move number "<< attackNum <<" is " << myMoves[attackNum-1].display() << endl;
182152
int damage = myMoves[attackNum-1].attack(maxAttack); //calculate damage eventually take into account weaknesses and such
183153
cout << "Attack power: " << damage << endl; //display results
184154
(*poke_damage_ptr).subHealth(damage); // subtract health based on damage dealt
185155
}
186156

187157
void Pokemon::subHealth(int dam) {
188-
//cout << "Health was: " << getcurrHealth() << endl;
189158
int damage = dam - currDef; // calculate damage
190-
cout << "Resisted " << getcurrDef() << " damage!" << endl;
159+
cout << "Resisted " << getcurrDef() << " damage!" << endl; // account for defense
191160
if(damage > 0) {
192-
cout << "Actual damage: " << (damage) << endl;
161+
cout << "Actual damage: " << (damage) << endl; // display damage
193162
setcurrHealth((getcurrHealth() - damage)); // reduce current health
194163
}
195164
else {
@@ -200,7 +169,6 @@ void Pokemon::subHealth(int dam) {
200169
KO = 1; // if health falls below 0, Pokemon becomes KO'd
201170
cout << "KO" << endl;
202171
}
203-
//cout << "Health is now: " << getcurrHealth() << endl;
204172
cout << endl;
205173
}
206174

@@ -210,6 +178,8 @@ void Pokemon::addHealth(int add) {
210178
}
211179
}
212180

181+
/* Getters and setters for Pokemon data members */
182+
213183
void Pokemon::setlevel(int lv) {
214184
level = lv;
215185
}
@@ -335,24 +305,24 @@ string Pokemon::attackname(int moveNum){
335305
}
336306

337307
void Pokemon::learnNewMove(){
338-
myMoves[0] = myMoves[1]; // first move is removed
339-
myMoves[1] = myMoves[2];
308+
myMoves[0] = myMoves[1]; // first move is replaced
309+
myMoves[1] = myMoves[2]; // move other moves back one usable spot
340310
myMoves[2] = myMoves[3];
341-
myMoves[3] = myMoves[4];
311+
myMoves[3] = myMoves[4]; // move in fifth slot moved to usable fourth slot
342312
}
343313

344314
void Pokemon::setMoves(int mv1, int mv2, int mv3, int mv4, int mv5) {
345315

346-
Moves move1(mv1), move2(mv2), move3(mv3), move4(mv4), move5(mv5);
316+
Moves move1(mv1), move2(mv2), move3(mv3), move4(mv4), move5(mv5); // assign moves based on enum values
347317

348318
myMoves.push_back(move1); // push moves into myMoves
349319
myMoves.push_back(move2);
350320
myMoves.push_back(move3);
351-
myMoves.push_back(move4);
321+
myMoves.push_back(move4); // last usable move slot
352322
myMoves.push_back(move5); // potential move to learn
353323
}
354324

355-
int Pokemon::getMoveNum(int move) {
325+
int Pokemon::getMoveNum(int move) { // returns enum values of specified move number
356326
switch (move) {
357327
case 0:
358328
return myMoves[0].getmovenum();

0 commit comments

Comments
 (0)