コード例 #1
0
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 ());
    }
}
コード例 #2
0
ファイル: main.cpp プロジェクト: rdavidzhong/myCpp
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;
}
コード例 #3
0
ファイル: bucky55.cpp プロジェクト: redbarron23/OSU
int main()
{

  Ninja n;
  Monster m;

  Enemy *enemy1 = &n;
  Enemy *enemy2 = &m;
  
  enemy1->setAttackPower(29);
  enemy2->setAttackPower(99);
  n.attack();
  m.attack();
}
コード例 #4
0
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();

}
コード例 #5
0
ファイル: game.cpp プロジェクト: Impulsation/sfml
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;
		}
	}	
}
コード例 #6
0
ファイル: Fighter.cpp プロジェクト: Thomqa/Challange
void Fighter::attack(Monster& monster, unsigned long damage)
{
	std::cout << type << " attacks " << monster.getName() << ": ";
	overkillHitpoints += monster.attack(damage);
}
コード例 #7
0
ファイル: main.cpp プロジェクト: MxGavin/CppTutorial
//======================================================================================
//======================================================================================
//======================================================================================
int main()
{
  //  GavinsClass GavinsObject("setting initial");

  //  GavinsObject.setName("I am Gavin");
  //  cout << GavinsObject.getName() <<endl;

  //  GavinsClass go("Sally mcSalad\n");
  //  cout << go.getName();

  //  Burrito bo;

#if 0
    srand(time(0));  //initial the random function
    for(int x=1; x<25;x++){
        cout << 1+(rand()%6) << endl; // no computer can generate real random number
    }
#endif // 0

#ifdef TS_DefualtArguments
    cout << volume();
#endif

#ifdef TS_UnaryScope
    int tuna =20;
    cout << tuna<<endl;
    cout << ::tuna<<endl;       //Global variables
#endif

#ifdef TS_30_FunctionOverloading
    int a = 54;
    float b = 32.45988;
    printNumber(a);
    printNumber(b);
#endif

#ifdef TS_31_Recursion
    cout << factorialFinder(5)<<endl;
#endif


#ifdef TS_32_CreateArrayUsingLoops
    int bucky[9];
    cout <<"Element - Value"<<endl;
    for(int x=0;x<9;x++){
        bucky[x]=99;
        cout << x <<"----------"<<bucky[x]<< endl;
    }
#endif // TS_32_CreateArrayUsingLoops


#ifdef TS_42_ArrowMemberSelectionOperator
    Sally so;
    Sally *sallyPointer = &so;

    so.printCrap();
    sallyPointer->printCrap();
#endif // TS_42_ArrowMemberSelectionOperator

#ifdef TS_44_ConstObject
    const Sally constObj;
    constObj.printConst();
#endif // TS_44_ConstObject

#ifdef TS_45_MemberInitializers
    Sally so(3,87);
    so.print();
#endif // TS_45_MemberInitializers

#ifdef TS_46_Composition
    Birthday birthObject(12,10,1982);
    people GavinObj("Gavin Wong",birthObject);
    GavinObj.printInfo();
#endif // TS_46_Composition

#ifdef TS_47_Friend
    StankFist bob;
    stinkysFriend(bob);
#endif // TS_47_Friend

#ifdef TS_48_This
    Hannah ho(23);
    ho.printCrap();

#endif // TS_48_This

#ifdef TS_49_OperatorOverloading

    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
    Spunky<int> obj1(7);
    Spunky<double> obj2(3.124);
    Spunky<char> obj3('a');

#endif // TS_58_Template

#ifdef TS_62_Exceptions
    try{
        int momsAge = 30;
        int sonsAge = 34;
        if(sonsAge > momsAge){
            throw 99;
        }
    }catch(int x){
        cout <<"son can not be older than mom. ERROR NUMBER: "<< x <<endl;
    }


    try{

        int num1;
        cout << "Enter first number: " << endl;
        cin >> num1;

        int num2;
        cout << "Enter second number: " << endl;
        cin >> num2;

        if(num2==0){
            throw 0;
        }

        cout << num1/num2 << endl;

    }catch(...){
        cout << "you cant divided by 0" << endl;
    }

#endif // TS_62_Exceptions

#ifdef TS_64_WorkingWithFiles
    ofstream buckyFile;
    buckyFile.open("tuna.txt"); //even this file isn't exist

    buckyFile << "I love tuna and tuna loves me!\n";
    buckyFile.close();

    ofstream gavinsFile("butterfly.txt");//even this file isn't exist
 //   ofstream gavinsFile("");//even this file isn't exist

    if(gavinsFile.is_open()){
        cout <<"ok, this file is opened"<<endl;
        gavinsFile << "oi love the beef!\n";
        gavinsFile.close();
    }else{
         cout <<"sorry,you messed up"<<endl;
    }

    ofstream theFile("players.txt");
    cout << "Enters player's ID, Name, and Money" << endl;
    cout << "press Ctrl+Z to quit \n" << endl;

    int idNumber;
    string name;
    double money;

    while(cin>>idNumber>>name>>money){
        theFile << idNumber << " " << name << " " << money << endl;
    }
    theFile.close();

    //Reading custom File structures
    ifstream readFile("players.txt");
    int rdID;
    string reName;
    double reMoney;

    while(readFile >> rdID >> reName >> reMoney){
        cout << rdID << ", " << reName << ", " << reMoney << endl;
    }

#endif // TS_64_WorkingWithFiles

#ifdef TS_68_CoolProgram
    int whatTheyWant;

    whatTheyWant = getWhatTheyWant();

    while(whatTheyWant != 4){
        displayItems(whatTheyWant);
        whatTheyWant = getWhatTheyWant();
    }

#endif // TS_68_CoolProgram

#ifdef TS_71_StringClass

    string s1("hamster ");
    string s2;
    string s3;

    cout << s1.at(3) << endl;
    for(int t=0;t<s1.length();t++){
        cout << s1.at(t) << endl;
    }

    s2 = s1;
    s3.assign(s1);
    cout<< s1 << s2 << s3 << endl;


    string x;
    cout <<"Please enter a string: " << endl;
    getline(cin,x);
    cout << x << endl;

    string bucky;
    cout <<"Please enter a string: " << endl;
    cin >> bucky;
    cout << "the string i entered is " << bucky << endl;
#endif // TS_71_StringClass


#ifdef TS_72_StringSubstringsSwappingFinding

    //substring
    string s1("OMG i think i am preggy!!");
    cout << s1.substr(17,7)<<endl;

    //swapping
    string one("apples ");
    string two("beans ");

    cout << one << two << endl;
    one.swap(two);
    cout << one << two << endl;

    //finding
    string s3("hi my name is gavin ,and ham is spam oh yes i am!");
    cout << s3.find("am") << endl;

    cout << s3 << endl;
    s3.erase(20);
    cout << s3 << endl;
    s3.replace(14,5,"Jianeng");
    cout << s3 << endl;
    s3.insert(14,"Huang ");
    cout << s3 << endl;


#endif // TS_72_StringSubstringsSwappingFinding















    return 0;
}