当前位置: 首页>>代码示例>>C++>>正文


C++ Pokemon::get_hp方法代码示例

本文整理汇总了C++中Pokemon::get_hp方法的典型用法代码示例。如果您正苦于以下问题:C++ Pokemon::get_hp方法的具体用法?C++ Pokemon::get_hp怎么用?C++ Pokemon::get_hp使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Pokemon的用法示例。


在下文中一共展示了Pokemon::get_hp方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: userBuild

void Colosseum::userBuild(Pokemon& p) //function used to build Pokemon
{
    cout << "Please name your Pokemon:" << endl;
     string name;
     p.set_name(name);
     cout << "How many hit points will it have? (1-50):" << endl;
     int hp;
     p.set_hp(hp);
     int hp1=p.get_hp();
     while(hp1>50 || hp1<1)
     {
         cout << "Sorry. The hit points should be between (1-50)" << endl;
         p.set_hp(hp);
         hp1=p.get_hp();
     }
     cout << "Split fifty points between attack level and defense level" << endl;
     cout << "Enter your attack level (1-49):" << endl;
     int att;
     p.set_attackLvl(att);
     int att1=p.get_attackLevel();

     while(att1>49 || att1<1)
     {
         cout << "Sorry. The attack level must be between 1 and 49)" << endl;
         p.set_attackLvl(att);
         att1=p.get_attackLevel();

     }
     int g=49-att1;
     cout << "Give a defense level (from 1 to " << g << "): " << endl;
     int def;
     p.set_deflvl(def);
     int def1=p.get_defLevel();
     while(g<def1 || def1<1)
     {
         cout << "Sorry. The defense level must be between 1 and " << g << ": " << endl;
         p.set_deflvl(def);
         def1=p.get_defLevel();
     }

}
开发者ID:santosh500,项目名称:Cplusplus_Projects,代码行数:41,代码来源:Colosseum.cpp

示例2: attack

bool Colosseum::attack(const Pokemon& attacker, Pokemon& defender) //function that deals with attacks and lowers hit points if hit
{
    bool returnValue=false;
    cout << attacker.get_name() << " is attacking " << defender.get_name() << endl;
    int attbonus=d20.roll();
    int defbonus=d20.roll();
    cout << attacker.get_name() << " rolls an attack bonus of " << attbonus << endl;
    cout << defender.get_name() << " rolls an defense bonus of " << defbonus << endl;
    int total_att=attbonus+attacker.get_attackLevel();
    int total_def=defbonus+defender.get_defLevel();
    int damage;
    if(total_att>total_def)
    {
        int roll1=d6.roll();
        int roll2=d6.roll();
        int roll3=d6.roll();
        damage=roll1+roll2+roll3;
        cout << "The attack hits dealing 3-D6 damage!" << endl;
        cout << "The rolls are: " << roll1 << " " << roll2 << " " << roll3 << " totalling: " << damage << " damage!" << endl;
        defender.reduceHP(damage);
        if(defender.get_hp() <=0 )
        {
            returnValue=true;
        }
        else
        {
            returnValue=false;
            cout << defender.get_name() << " has " << defender.get_hp() << " hit points left." << endl;
        }

    }
    else
    {
        damage=0;
        cout << "The attack is missed!" << endl;
    }
    return returnValue;

}
开发者ID:santosh500,项目名称:Cplusplus_Projects,代码行数:39,代码来源:Colosseum.cpp


注:本文中的Pokemon::get_hp方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。