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


C++ Dice::rollDie方法代码示例

本文整理汇总了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;
	}
		
}
开发者ID:edwin03,项目名称:OSU-CS162,代码行数:52,代码来源:Vampire.cpp


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