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
|
//#include"stdafx.h"
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Attack
{
public:
//constructor for attack taking all the information
Attack(string atkName, int atkPower, int atkPp, int atkAcc, string atkType): //this is used post c++ 11 to initialize the member variable and behaves identical to
name(atkName), //name == atkName
power(atkPower), //power == atkPower
pp(atkPp), //etc.
accuracy(atkAcc),
type(atkType)
{
}
//accessor methods. Returns the value of the member variable.
string getName()
{
return name;
}
//if you need a public way to change a member variable create the setter
//void setName(string newName)
//{
// name = newName;
//}
int getPower()
{
return power;
}
int getPp()
{
return pp;
}
int getAccuray()
{
return accuracy;
}
string getType()
{
return type;
}
private:
string name;
int power;
int pp;
int accuracy;
string type;
};
class Pokemon
{
public:
//constructor with all the needed information to create a pokemon
Pokemon(string pokeName, string typ1, string typ2, int hpStat, int atkStat, int defStat, int speedStat, vector<Attack> &attacks):
name(pokeName),
type1(typ1),
type2(typ2),
HP(hpStat),
Atk(atkStat),
Def(defStat),
Speed(speedStat),
attackList(attacks)
{}
//prints out the stats for your pokemon
void statPg()
{
cout << "#################################################################\n";
cout << name << ": " << type1 << "/" << type2 << " type\n"
<< "\t" << HP << " HP\n"
<< "\t" << Atk << " ATK\n"
<< "\t" << Def << " DEF\n"
<< "\t" << Speed << " Speed\n\n";
//loops through the vector and prints out each attack information
for(auto iter = attackList.begin(); iter != attackList.end(); iter++)
{
cout << iter->getName() << " | " << iter->getPp() << " pp\n";
}
cout << "#################################################################\n";
}
private:
string name;
string type1;
string type2;
int HP;
int Atk;
int Def;
int Speed;
vector<Attack> attackList; //vector of attacks
};
int main()
{
//create attacks directly no need to inherit and create a new struct
Attack ember("Ember",40,30,95,"Fire");
Attack hydropump("HydroPump",120,5,75,"Water");
Attack tbolt("Thunderbolt",100,10,100,"Electric");
Attack electroball("Electro Ball",150,10,100,"Elecric");
Attack fireblast("Fireblast",150,5,80,"Fire");
//create your attack lists for the pokemon
vector<Attack> golemAttack{ember,fireblast,tbolt,electroball};
vector<Attack> ShedinjaAttack{hydropump,tbolt,ember,fireblast};
//Pokemon!
Pokemon Shedninja("Shedninja","Ghost","Bug",1,0,0,100,ShedinjaAttack);
Pokemon Golem("Golem","Rock","Ground",126,102,200,78,golemAttack );
//show pokemon stats
Shedninja.statPg();
Golem.statPg();
}
|