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


C++ Monster::attack方法代码示例

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


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

示例1: update

void MonsterAttackingState::update(Monster &monster)
{
    Heroine* target = (Heroine*)monster.getTarget();
    
    if (target == nullptr) return;
    
    if (monster.isInDis(target, monster.getAttackDis()))
    {
        if (target->getHp () > 0.0f)
        {
            monster.attack(target);
        }
        else
        {
            //TODO monster change to die state
            target->removeFromParent();
            for (int i = 0; i < monster.parent->children.size (); i++)
            {
                if (((Monster*)(monster.parent->children[i]))->getTarget() == target)
                {
                    ((Monster*)(monster.parent->children[i]))->setTarget(nullptr);
                    ((Monster*)(monster.parent->children[i]))->changeState(new MonsterMovingState ());
                }
            }
        }
    }
    else
    {
        monster.changeState(new MonsterMovingState ());
    }
}
开发者ID:mycmessia,项目名称:SDLGameTD,代码行数:31,代码来源:MonsterAttackingState.cpp

示例2: main

int main(int argc, const char * argv[]) {
    Ninja n;
    Monster m;
    Enemy *enemy1 = &n;
    Enemy *enemy2 = &m;

    enemy1->setAttackPower(20);
    enemy2->setAttackPower(30);

    n.attack();
    m.attack();

    return 0;
}
开发者ID:rdavidzhong,项目名称:myCpp,代码行数:14,代码来源:main.cpp

示例3: main

int main()
{

  Ninja n;
  Monster m;

  Enemy *enemy1 = &n;
  Enemy *enemy2 = &m;
  
  enemy1->setAttackPower(29);
  enemy2->setAttackPower(99);
  n.attack();
  m.attack();
}
开发者ID:redbarron23,项目名称:OSU,代码行数:14,代码来源:bucky55.cpp

示例4: main

int main(){


	Ninja n;
	Monster m;
	//REMEMBER ALL NINJAS ARE ENEMIES SO ARE MONSTERS
	//SO THE ADDRESS OF NINJA, IS ALSO A ENEMY PTR
	//ANYTHING AN ENEMY CAN DO A NINJA CAN DO
	Enemy *enemy1 = &n;
	Enemy *enemy2 = &m;
	
	//NINJA GETS 29 ATTACK POWER
	enemy1->setAttackPower(29);
	enemy2->setAttackPower(99);
	
	n.attack();
	m.attack();

}
开发者ID:yfjd01,项目名称:PolymorphismCppTut,代码行数:19,代码来源:polymorphism.cpp

示例5: main

int main()
{
	srand( time(0) );

	Map gameMap;

	Player mainPlayer;

	mainPlayer.createClass();

	// Begin adventure.
	bool done = false;
	while( !done )
	{
		// Each loop cycly we output the player position and 
		// a selection menu.

		gameMap.printPlayerPos();
	
		int selection = 1;
		cout << "1) Move, 2) Rest, 3) View Stats, 4) Quit: ";
		cin >> selection;

		Monster* monster = 0;
		switch( selection )
		{
		case 1:
			gameMap.movePlayer();

			// Check for a random encounter.  This function
			// returns a null pointer if no monsters are
			// encountered.
			monster = gameMap.checkRandomEncounter();

			// 'monster' not null, run combat simulation.
			if( monster != 0 )
			{
				// Loop until a 'break' statement.
				while( true )
				{
					// Display hitpoints.
					mainPlayer.displayHitPoints();
					monster->displayHitPoints();
					cout << endl;

					// Player's turn to attack first.
					bool runAway = mainPlayer.attack(*monster);

					if( runAway )
						break;

					if( monster->isDead() )
					{
						mainPlayer.victory(monster->getXPReward());
						mainPlayer.levelUp();
						break;
					}

					monster->attack(mainPlayer);

					if( mainPlayer.isDead() )
					{
						mainPlayer.gameover();
						done = true;
						break;
					}
				}

				// The pointer to a monster returned from
				// checkRandomEncounter was allocated with
				// 'new', so we must delete it to avoid
				// memory leaks.
				delete monster;
				monster = 0;
			}

			break;
		case 2:
			mainPlayer.rest();
			break;
		case 3:
			mainPlayer.viewStats();
			break;
		case 4:
			done = true;
			break;
		}
	}	
}
开发者ID:Impulsation,项目名称:sfml,代码行数:89,代码来源:game.cpp

示例6: attack

void Fighter::attack(Monster& monster, unsigned long damage)
{
	std::cout << type << " attacks " << monster.getName() << ": ";
	overkillHitpoints += monster.attack(damage);
}
开发者ID:Thomqa,项目名称:Challange,代码行数:5,代码来源:Fighter.cpp

示例7: main


//.........这里部分代码省略.........

    OverLoad a(34);
    OverLoad b(21);
    OverLoad c;

    c = a+b;
    cout << c.OverNum <<endl;
#endif // TS_49_OperatorOverloading

#ifdef TS_52_Inheritance
    Son Ethan;
    Ethan.sayName();
#endif // TS_52_Inheritance

#ifdef TS_53_ProtectedMembers
    Daughter tina;
    tina.doSomething();
#endif // TS_53_ProtectedMembers

#ifdef TS_54_DerivedClassConstructor
  //  Mother mom;
    Daughter tina;
#endif // TS_54_DerivedClassConstructor

#ifdef TS_55_Polymorphism
    Ninja n;
    Monster m;
    Enemy *enemy1 = &n;     //because ninja is of type enemy,this is valid
    Enemy *enemy2 = &m;     //anything that an enemy can do,monster can do

    enemy1->setAttackPower(4);  //ninja is just a more specific type of enemy
    enemy2->setAttackPower(26); //every enemy has setAttackPower

    n.attack();             //can't use enemy1 because its type enemy
    m.attack();             //Enemy class does not have attack
                            //virtual members make this even easier
#endif // TS_55_Polymorphism


#ifdef TS_56_VirtualFunctions
    Ninja n;
    Monster m;
    Enemy *enemy1 = &n;
    Enemy *enemy2 = &m;

    enemy1->setAttackPower(4);  //ninja is just a more specific type of enemy
    enemy2->setAttackPower(26); //every enemy has setAttackPower
    enemy1->attack();
    enemy2->attack();

#endif // TS_56_VirtualFunctions

#ifdef TS_58_Template
    double  x=7.0,y=43.235,z;
    z =addCrap(x,y);
    cout << z << endl;

    int t = 89;
    double q = 56.78;
    cout << smaller(t,q) << endl;

    // 60_ClassTemplate
    Ethan <int>eo(69,105);
    cout << eo.bigger() << endl;

    // 61_Template Specializations
开发者ID:MxGavin,项目名称:CppTutorial,代码行数:67,代码来源:main.cpp


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