27 Temmuz 2016 Çarşamba

A simple C++ damage calculator.


#include
#include
#include
#include
#include
using std::setw;
using namespace std;
extern int a, b;
extern int c;
extern float f;
void func(void);

static int count = 10; /* Global variable */
int max(int num1, int num2);
#define LENGTH 10
#define WIDTH  5
#define NEWLINE '\n'
int sum(int a, int b=20)
{
  int result;

  result = a + b;

  return (result);
};
class Move
{
public:
    double effectiveness;
    int Base_Power;
    double STAB;
    double type;
    double critical;
    double other;
    int special;
    int physical;
};
class Nature
{
public:
    double Attack;
    double Defense;
    double Special_Attack;
    double Special_Defense;
    double Speed;
};
class EVs
{
    public:
        int HP;
        int Attack;
        int Defense;
        int Special_Attack;
        int Special_Defense;
        int Speed;
};
class IVs
{
    public:
        int HP;
        int Attack;
        int Defense;
        int Special_Attack;
        int Special_Defense;
        int Speed;
};
class Bases
{
    public:
        int HP;
        int Attack;
        int Defense;
        int Special_Attack;
        int Special_Defense;
        int Speed;
};
class Pokemon
{
    public:
        int HP;
        int Attack;
        int Defense;
        int Special_Attack;
        int Special_Defense;
        int Speed;
        int level;
        int user;
        int opponent;
        Nature nature;
        EVs evs;
        IVs ivs;
        Bases bases;

    void statistic()
    {
        HP=((2*bases.HP+ivs.HP+(evs.HP/4))*level)/100+level+10;
        Attack=(((2*bases.Attack+ivs.Attack+(evs.Attack/4))*level)/100+5)*nature.Attack;
        Defense=(((2*bases.Defense+ivs.Defense+(evs.Defense/4))*level)/100+5)*nature.Defense;
        Special_Attack=(((2*bases.Special_Attack+ivs.Special_Attack+(evs.Special_Attack/4))*level)/100+5)*nature.Special_Attack;
        Special_Defense=(((2*bases.Special_Defense+ivs.Special_Defense+(evs.Special_Defense/4))*level)/100+5)*nature.Special_Defense;
        Speed=(((2*bases.Speed+ivs.Speed+(evs.Speed/4))*level)/100+5)*nature.Speed;
    };
};
void IVsadd(Pokemon& Pokemon);
void EVsadd(Pokemon& Pokemon);
void Basesadd(Pokemon& Pokemon);
void Natureadd(Pokemon& Pokemon);
void Moveadd(Move& move);
int damage(Pokemon& user, Pokemon& opponent, Move& move);
int main() {
   
    cout << "Enter the level of the Pokemon: " << endl;
    Pokemon Pokemon1;
    cin>> Pokemon1.level;
    EVsadd(Pokemon1);
    //cout << "Pokemon's base HP is: " << Pokemon1.bases.HP<< endl;
    IVsadd(Pokemon1);
    //cout << "Pokemon's base HP is: " << Pokemon1.bases.HP<< endl;
    Basesadd(Pokemon1);
    cout << "Pokemon's base HP is: " << Pokemon1.bases.HP<< endl;
    Natureadd(Pokemon1);
    //cout << "Pokemon's base HP is: " << Pokemon1.bases.HP<< endl;
    Pokemon1.statistic();
    cout << "Pokemon's base HP is: " << Pokemon1.bases.HP<< endl;
    cout << "Pokemon's HP is: " << Pokemon1.HP<< endl;
    cout << "Pokemon's Attack is: " << Pokemon1.Attack << endl;
    cout << "Pokemon's Defense is: " << Pokemon1.Defense << endl;
    cout << "Pokemon's Special Attack is: " << Pokemon1.Special_Attack << endl;
    cout << "Pokemon's Special Defense is: " << Pokemon1.Special_Defense << endl;
    cout << "Pokemon's Speed is: " << Pokemon1.Speed << endl;
    Pokemon1.user=1;
    Pokemon Pokemon2;
    cout << "Enter the level of the Pokemon: " << endl;
    cin>> Pokemon2.level;
    EVsadd(Pokemon2);
        //cout << "Pokemon's base HP is: " << Pokemon1.bases.HP<< endl;
    IVsadd(Pokemon2);
        //cout << "Pokemon's base HP is: " << Pokemon1.bases.HP<< endl;
    Basesadd(Pokemon2);
    cout << "Pokemon's base HP is: " << Pokemon2.bases.HP<< endl;
    Natureadd(Pokemon2);
        //cout << "Pokemon's base HP is: " << Pokemon1.bases.HP<< endl;
    Pokemon2.statistic();
    cout << "Pokemon's base HP is: " << Pokemon2.bases.HP<< endl;
    cout << "Pokemon's HP is: " << Pokemon2.HP<< endl;
    cout << "Pokemon's Attack is: " << Pokemon2.Attack << endl;
    cout << "Pokemon's Defense is: " << Pokemon2.Defense << endl;
    cout << "Pokemon's Special Attack is: " << Pokemon2.Special_Attack << endl;
    cout << "Pokemon's Special Defense is: " << Pokemon2.Special_Defense << endl;
    cout << "Pokemon's Speed is: " << Pokemon2.Speed << endl;
    Pokemon2.opponent=1;
    Move move;
    Moveadd(move);
    int damage1=damage(Pokemon1, Pokemon2, move);
    cout << "The damage is " << Pokemon2.HP<<"/"<    return 0;
}

void func( void )
{
    static int i = 5; // local static variable
    i++;
    std::cout << "i is " << i ;
    std::cout << " and count is " << count << std::endl;
}

int max(int num1, int num2)
{
   // local variable declaration
   int result;

   if (num1 > num2)
      result = num1;
   else
      result = num2;

   return result;
}
void EVsadd(Pokemon& Pokemon)
{
     int hpEV;
     std::cout << "Please enter HP EV:"<< endl;
     std::cin >>hpEV;
     if (hpEV>252)
     {
         std::cout << "EV cannot be higher than 252"<< endl;
     }
     else
     {
         std::cout <<"HP EV is "<< hpEV << endl;
     }
     int atEV;
     std::cout << "Please enter Attack EV:"<< endl;
     std::cin >> atEV;
     if (atEV>252)
     {
         std::cout << "EV cannot be higher than 252"<< endl;
     }
     else
     {
         std::cout <<"Attack EV is "<< atEV << endl;
     }
     int defEV;
     std::cout << "Please enter Defense EV:"<< endl;
     std::cin >> defEV;
     if (defEV>252)
     {
         std::cout << "EV cannot be higher than 252"<< endl;
     }
     else
     {
         std::cout <<"Defense EV is "<< defEV << endl;
     }
     int spatkEV;
     std::cout << "Please enter Special Attack EV:"<< endl;
     std::cin >> spatkEV;
     if (spatkEV>252)
     {
         std::cout << "EV cannot be higher than 252"<< endl;
     }
     else
     {
         std::cout <<"Special Attack EV is "<< spatkEV << endl;
     }
     int spdefEV;
     std::cout << "Please enter Special Defense EV:"<< endl;
     std::cin >> spdefEV;
     if (spdefEV>252)
     {
         std::cout << "EV cannot be higher than 252"<< endl;
     }
     else
     {
         std::cout <<"Special Defense EV is "<< spdefEV << endl;
     }
     int speedEV;
     std::cout << "Please enter Speed EV:"<< endl;
     std::cin >> speedEV;
     if (speedEV>252)
     {
         std::cout << "EV cannot be higher than 252"<< endl;
     }
     else
     {
         std::cout <<"Speed EV is "<< speedEV << endl;
     }
     EVs ev;
     ev.HP=hpEV;
     ev.Attack=atEV;
     ev.Defense=defEV;
     ev.Special_Attack=spatkEV;
     ev.Special_Defense=spdefEV;
     ev.Speed=speedEV;
     Pokemon.evs=ev;

}
void IVsadd(Pokemon& Pokemon)
{
     int hpIV;
     std::cout << "Please enter HP IV:"<< endl;
     std::cin >>hpIV;
     if (hpIV>31)
     {
         std::cout << "IV cannot be higher than 31"<< endl;
     }
     else
     {
         std::cout <<"HP IV is "<< hpIV << endl;
     }
     int atIV;
     std::cout << "Please enter Attack IV:"<< endl;
     std::cin >> atIV;
     if (atIV>31)
     {
         std::cout << "IV cannot be higher than 31"<< endl;
     }
     else
     {
         std::cout <<"Attack IV is "<< atIV << endl;
     }
     int defIV;
     std::cout << "Please enter Defense IV:"<< endl;
     std::cin >> defIV;
     if (defIV>31)
     {
         std::cout << "IV cannot be higher than 31"<< endl;
     }
     else
     {
         std::cout <<"Defense IV is "<< defIV << endl;
     }
     int spatkIV;
     std::cout << "Please enter Special Attack IV:"<< endl;
     std::cin >> spatkIV;
     if (spatkIV>31)
     {
         std::cout << "IV cannot be higher than 31"<< endl;
     }
     else
     {
         std::cout <<"Special Attack IV is "<< spatkIV << endl;
     }
     int spdefIV;
     std::cout << "Please enter Special Defense IV:"<< endl;
     std::cin >> spdefIV;
     if (spdefIV>31)
     {
         std::cout << "IV cannot be higher than 31"<< endl;
     }
     else
     {
         std::cout <<"Special Defense IV is "<< spdefIV << endl;
     }
     int speedIV;
     std::cout << "Please enter Speed IV:"<< endl;
     std::cin >> speedIV;
     if (speedIV>31)
     {
         std::cout << "IV cannot be higher than 31"<< endl;
     }
     else
     {
         std::cout <<"Speed IV is "<< speedIV << endl;
     }
     IVs iv;
     iv.HP=hpIV;
     iv.Attack=atIV;
     iv.Defense=defIV;
     iv.Special_Attack=spatkIV;
     iv.Special_Defense=spdefIV;
     iv.Speed=speedIV;
     Pokemon.ivs=iv;

}

void Basesadd(Pokemon& Pokemon)
{
    int BaseHP;
    std::cout << "Please enter Base HP"<< endl;
    std::cin >> BaseHP;
    std::cout <<"Base HP is "<< BaseHP << endl;
    int BaseAttack;
    std::cout << "Please enter Base Attack"<< endl;
    std::cin >> BaseAttack;
    std::cout <<"Base Attack is "<< BaseAttack << endl;
    int BaseDefense;
    std::cout << "Please enter Base Defense"<< endl;
    cin >> BaseDefense;
    std::cout <<"Base Defense is "<< BaseDefense << endl;
    int BaseSpecAttack;
    std::cout << "Please enter Base Special Attack"<< endl;
    std::cin >> BaseSpecAttack;
    std::cout <<"Base Special Attack is "<< BaseSpecAttack << endl;
    int BaseSpecDefense;
    std::cout << "Please enter Base Special Defense"<< endl;
    std::cin >> BaseSpecDefense;
    std::cout <<"Base Special Defense is "<< BaseSpecDefense << endl;
    int BaseSpeed;
    std::cout << "Please enter Base Speed"<< endl;
    std::cin >> BaseSpeed;
    std::cout <<"Base Speed is "<< BaseSpeed << endl;
    Bases bs;
    bs.HP=BaseHP;
    bs.Attack=BaseAttack;
    bs.Defense=BaseDefense;
    bs.Special_Attack=BaseSpecAttack;
    bs.Special_Defense=BaseSpecDefense;
    bs.Speed=BaseSpeed;
    Pokemon.bases=bs;
}
void Natureadd(Pokemon& Pokemon)
{
    double nAttack;
    std::cout << "Please enter Nature's Attack"<< endl;
    std::cin >> nAttack;
    std::cout <<"Nature's Attack is "<< nAttack << endl;
    double nDefense;
    std::cout << "Please enter Nature's Defense"<< endl;
    cin >> nDefense;
    std::cout <<"Base Defense is "<< nDefense << endl;
    double nSpecAttack;
    std::cout << "Please enter Nature's Special Attack"<< endl;
    std::cin >> nSpecAttack;
    std::cout <<"Nature's Special Attack is "<< nSpecAttack << endl;
    double nSpecDefense;
    std::cout << "Please enter Nature's Special Defense"<< endl;
    std::cin >> nSpecDefense;
    std::cout <<"Nature's Special Defense is "<< nSpecDefense << endl;
    double nSpeed;
    std::cout << "Please enter Nature's Speed"<< endl;
    std::cin >> nSpeed;
    std::cout <<"Nature's Speed is "<< nSpeed << endl;
    Nature na;
    na.Attack=nAttack;
    na.Defense=nDefense;
    na.Special_Attack=nSpecAttack;
    na.Special_Defense=nSpecDefense;
    na.Speed=nSpeed;
    Pokemon.nature=na;
}
void Moveadd(Move& move)
{
    double type;
    std::cout << "Please enter Type interaction:"<< endl;
    std::cin >> type;
    std::cout <<"Type interaction is "<< type << endl;
    int BP;
    std::cout << "Please enter Base Power:"<< endl;
    std::cin >> BP;
    std::cout <<"Base Power is "<< BP << endl;
    double stab;
    std::cout << "Please enter STAB(double if the Pokémon has Adaptability):"<< endl;
    std::cin >> stab;
    std::cout <<"STAB is "<< stab << endl;
    double critical;
    std::cout << "Please enter critical hit(2.25 if the Pokémon has Sniper):"<< endl;
    std::cin >> critical;
    std::cout <<"Critical is "<< critical << endl;
    double other;
    std::cout << "Please enter other variables:"<< endl;
    std::cin >> other;
    std::cout <<"Other variables are "<< other << endl;
    string status;
    std::cout << "Please enter whether the move is physical or special"<< endl;
    std::cin >> status;
    std::cout <<"The move is "<< status << endl;
    int physical;
    int special;
    if(status.compare("physical")==0)
    {
        physical=1;
        special=0;
    }
    if(status.compare("special")==0)
    {
        physical=0;
        special=1;
    }
    move.type=type;
    move.Base_Power=BP;
    move.STAB=stab;
    move.critical=critical;
    move.other=other;
    move.physical=physical;
    move.special=special;
}
int damage(Pokemon& user, Pokemon& opponent, Move &move)
{
    double damage=0;
    if(move.physical==1)
    {
        double random=(rand()%100+85)/100;
        double Modifier=move.STAB*move.type*move.critical*move.other*random;
        double dmg=((double)(2*user.level+10)/(double)250)*((double)user.Attack/(double)opponent.Defense)*(double)move.Base_Power;
        damage =(dmg+2)*Modifier;
        std::cout << opponent.Attack<< endl;
        std::cout << opponent.Defense<< endl;
        std::cout << (double) (2*user.level+10)<< endl;
        std::cout << (float) ((float)(2*user.level+10)/(float)250)<< endl;
        std::cout << dmg<< endl;
        std::cout << Modifier<< endl;
    }
    else if(move.special==1)
    {
        double random=(rand()%100+85)/100;
        double Modifier=move.STAB*move.type*move.critical*move.other*random;
        double dmg=((2*user.level+10)/250)*(user.Special_Attack/opponent.Special_Defense)*move.Base_Power;
        damage =(dmg+2)*Modifier;
    }
    return damage;
}

Hiç yorum yok:

Yorum Gönder