本文整理汇总了C++中Dice::rollDie方法的典型用法代码示例。如果您正苦于以下问题:C++ Dice::rollDie方法的具体用法?C++ Dice::rollDie怎么用?C++ Dice::rollDie使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dice
的用法示例。
在下文中一共展示了Dice::rollDie方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Defend
/*********************************************************************
** Function: Defend()
** Description: Implement Vampire special defend starategey.
** Parameters: Opponent attack points
*********************************************************************/
void Vampire::Defend(int attackPoints) // overrides Creature's Defend functions since it is diffrent
{
Dice charm(2);
int restult = charm.rollDie();
if (restult != 12)
{
Dice dice (defenseDieSides);
int defensePoints = 0;
for (int x = 0; x < nDefenseRolls; x++)
{
defensePoints += dice.rollDie();
}
std::cout << "Defender's total defend points: " << defensePoints << std::endl;
std::cout << "Defender's Armor: " << armor << std::endl;
int damage = 0;
damage = attackPoints - defensePoints - armor;
if (damage < 0)
damage = 0;
if (damage <= 0)
{
strengthPoints = strengthPoints;
}
else
{
strengthPoints = strengthPoints - damage;
}
std::cout << "Damage inflicted: " << damage << std::endl;
std::cout << "Defender's Strength Points: " << strengthPoints << std::endl;
if(strengthPoints <= 0)
{
std::cout << "Defender is Dead!" << std::endl;
alive = false;
}
}
else
{
strengthPoints = strengthPoints;
std::cout << "Vampire charmed the attacker!!! (no points reduced)" << std::endl;
}
}