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


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

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


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

示例1: main

int main()
{
	// options of pokemon to choose from
	string Mewtow;
	string Gastly;
	string Rhyhorn;
	string Pikachu;
	string Venomoth;

	string player1; // the pokemon the user chose


	cout << "Hello, are you ready to battle?" << endl;
	cout << "If so, please select a Pokemon you wish to take into battle." << endl;
	cout << endl;
	cout << "Mewtow" << endl;
	cout << "Gastly" << endl;
	cout << "Rhyhorn" << endl;
	cout << "Pikachu" << endl;
	cout << "Venomoth" << endl;
	cout << endl;
	cin >> player1;

	cout << "You selected " << player1 << endl;

	Pokemon p; // declares a pokemon object
	Boss b; // declare boss object
	srand(time(NULL));
	int a = rand() % 1;
	if ((a = 0)) // picks which boss pokemon will be battling
		cout << "and you will be battling Persian!" << endl;
	else
		cout << "and you will be battling Tauros!" << endl;

	cout << endl;

	cout << player1 << " is starting with a health of 300, " <<
		"while the enemy has 400." << endl;
	
	int hp = p.getHealth(), enemyhp = b.getHealth(), attack = p.getAttackPower(), enemyattack = b.getAttackPower();

	int x;

	do
	{
		// ask user if they would like to attack ant then show the impact the attack had on the boss
		cout << "Attack? 1-Yes or 2-No" << endl;
		cin >> x;
		if (x == 1)
		{
			int y;
			cout << "Do you want to: 1-Kick, 2-Punch, 3-Special Power" << endl;
			cin >> y;
			if (y == 1)
			{
				cout << "You kicked the Boss and now he has " << b.showEnemyHp(enemyhp, attack) << "HP left." << endl;
				enemyhp = b.showEnemyHp(enemyhp, attack);
				if (enemyhp == 0) // cout bosses hp and say player wins if it equals 0 or below
				{
					cout << "Congratulations! You beat the Boss!" << endl;
				}
			}
			else if (y == 2)
			{
				cout << "You Punched the Boss and now he has " << b.showEnemyHp(enemyhp, attack) << "HP left." << endl;
				enemyhp = b.showEnemyHp(enemyhp, attack);
				if (enemyhp == 0) // cout bosses hp and say player wins if it equals 0 or below
				{
					cout << "Congratulations! You beat the Boss!" << endl;
				}
			}
			else if (y == 3)
			{
				cout << "You used your Special Power on the Boss and now he has " << b.showEnemyHp(enemyhp, attack) << "HP left." << endl;

				enemyhp = b.showEnemyHp(enemyhp, attack);
				if (enemyhp == 0) // cout bosses hp and say player wins if it equals 0 or below
				{
					cout << "Congratulations! You beat the Boss!" << endl;
				}
			}
			else
			{
				cout << "That is not a valid choice." << endl;
			}
			cout << endl;

			cout << "The Boss hit you back.\n";
			cout << "You now have " << p.showHp(hp, enemyattack) << "HP left.\n\n";
			hp = p.showHp(hp, enemyattack); // declaring hp as the showing of the players health
			if (hp == 0) // determines if player has died or not
			{
				cout << "Oh no you died! Bummer." << endl;
			}
		}
		else if (x == 2)
		{
			cout << "You chose not to hit and was attacked.";
			cout << "You now have " << hp << "HP left.\n\n";
			if (hp == 0) // determines if player has died or not
//.........这里部分代码省略.........
开发者ID:rroegiers17,项目名称:FINAL,代码行数:101,代码来源:main.cpp


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