Пример #1
0
gk::SceneObject WeaponFactory::create(Weapon &weaponInfos, float x, float y, gk::GameKey key, gk::SceneObject &owner) {
	if(weaponInfos.name() == "swordL1") {
		return SwordFactory::create(x, y, key, owner, weaponInfos);
	}
	else if(weaponInfos.name() == "strengthL1") {
		gk::SceneObject object{"strengthL1", "weapon"};
		object.set<LifetimeComponent>();
		object.set<WeaponComponent>(owner, weaponInfos, key, "Grab");
		return object;
	}
	else {
		return gk::SceneObject{"", "weapon"};
	}
}
Пример #2
0
void displayWeapon(Weapon weapon)
{
  cout<<"\tName    :"<<weapon.name()<<endl
      <<"\tRange   :"<<weapon.range()<<endl
      <<"\tAmmo    :"<<weapon.ammo()<<endl
      <<"\tDelay   :"<<weapon.delay()<<endl
      <<"\tDamage  :"<<weapon.damage()<<endl
      <<"\tVSplashD:"<<weapon.verticalSplashDamage()<<endl
      <<"\tHSplashD:"<<weapon.horizontalSplashDamage()<<endl
      <<"\tHSplashR:"<<weapon.horizontalSplashRadius()<<endl;
}
Пример #3
0
int main(int argc, char** argv){
    int num_objects = 10;
    int num_moving = 5;
    string name;
    int x, y;
    char command;
    int t=1;
	
    Player player("player");
    Player player2("player2");
	
    //If at least one command-line argument was provided, use it as the number of objects to create.
    if (argc > 1) {
        num_objects = atoi(argv[1]);
    }
	
    if (argc > 2) {
        num_moving = atoi(argv[2]);
    }
	
    //Create all the non-moving objects
    for (int i = 0; i < num_objects - num_moving; i++) {
        x = random() % 11;
        y = random() % 11;
        
        name = "random object";
        if (i < 7) {
            name = names[i];
        }
		
        collection.push_back(new Object(name, x, y));
    }
	
    for (int i = 0; i < num_moving; i++) {
        x = random() % 11;
        y = random() % 11;
		
        name = "random moving object";
        if (i < 5) {
            name = moving_names[i];
        }
		
        collection.push_back(new Monster(name,x,y));
    }
		
    //Create weapons.
    for (int i = 0; i < 3; i++) {
        x = random() % 11;
        y = random() % 11;

        name = "weapon";
        if (i < 3) {
            name = weapon_names[i];
        }

        collection.push_back(new Weapon(name,x,y));
    }

    //Create armor.
    for (int i = 0; i < 3; i++) {
        x = random() % 11;
        y = random() % 11;

        name = "armor";
        if (i < 3) {
            name = armor_names[i];
        }

        collection.push_back(new Armor(name,x,y));
    }

    do{ 
		
	
		
	while(t==1){
		cout << "__________________________________________________"<<endl;
		cout << "Player 1" << endl;
		cout << "[" << player.x() << ", " << player.y() << "]" << endl;
		cout << "Your score is: " << player.score() << endl;
		cout << "________________________________________"<<endl;
	        cout << "Enter a command:" << endl;
                cout << "   'i' to move up." << endl;
                cout << "   'm' to move down." << endl;
                cout << "   'j' to move left." << endl;
                cout << "   'k' to move right." << endl;
		cout << "   't' to take an item from this room." << endl;
		cout << "   'a' to attack a monster in this room." << endl;
                cout << "   'q' to quit." << endl;
		cout << "__________________________________________________"<<endl;
		
        //Process command and move player.
        cin >> command;
		
        switch (command) {
            case 'i':
                player.move_up();
                break;
            case 'm':
                player.move_down();
                break;
            case 'j':
                player.move_left();
                break;
            case 'k':
                player.move_right();
                break;
			case 't':
				for (vector<Object*>::iterator i=collection.begin(); i != collection.end(); ) {
					if ((*i)->x() == player.x() && (*i)->y() == player.y()) {
					    Weapon* weap = dynamic_cast<Weapon*>(*i);
					    Armor* arm = dynamic_cast<Armor*>(*i);
					    if (weap){
					        cout << "You inspect the " << weap->name() << "." << endl;
						if (player.get_str() < weap->str()) {
						    player.set_weapon(weap);
						    cout << "You pick up the " << weap->name() << " and equip it." << endl;
						    i = collection.erase(i);
						} else {
						    cout << "You realize the " << weap->name() << " is worse than your " << player.get_weapon() << " so you destory it." << endl;
						    i = collection.erase(i);
						}
                                            }
					    if (arm){
					        cout << "You inspect the " << arm->name() << "." << endl;
						if (player.get_tgh() < arm->tgh()) {
						    player.set_armor(arm);
						    cout << "You pick up the " << arm->name() << " and equip it." << endl;
						    i = collection.erase(i);
						} else {
						    cout << "The " << arm->name() << " is worse than your " << player.get_armor() << " so you destroy it." << endl;
						    i = collection.erase(i);
						  }
                                                }
					    if (player.take_item(*i)) {
					    	cout << "You take a " << (*i)->name() << endl;
						i = collection.erase(i);
					    }
					    else {
						i++;
					    }
					} else {
						i++;
					    
					}
                                        break;
				}
			case 'a':
				for (vector<Object*>::iterator i=collection.begin(); i != collection.end(); ) {
					if ((*i)->x() == player.x() && (*i)->y() == player.y()) {
						Monster* mon = dynamic_cast<Monster*>(*i);
						if (mon){
								cout << "What do you do?" << endl;
								cout << "'a' for a normal attack." << endl;
								cout << "'s' for a special attack." << endl;
								cin >> command;
								switch (command) {
								    case 'a':
								        cout << "You attack " << mon->name() << endl;
								        if (random() % 2 == 0) {
									    cout << mon->name() << " wins!  You lose" << (5 - player.get_tgh()) << "  health." << endl;
									        if (player.hurt_player(5 - player.get_tgh()) == false) {
										    cout << "You have died!" << endl;
										    return 1;
									        }
									    i++;
									
								        }
								        else {
									    cout << "You win!  " << mon->name() << " loses " << (5 + player.get_str()) << " health." << endl;
									    if (mon->hurt_monster(5 + player.get_str()) == false) {
										cout << "You have killed the monster!" << endl;
										i = collection.erase(i);
										player.give_bonus(10);
									    }
								        }
								    case 's':
								        cout << "You use a special attack on " << mon->name() << endl;
								        if (random() % 10 >= 3) {
									    cout << mon->name() << " wins!  You lose " << (5 - player.get_tgh()) << " health." << endl;
									        if (player.hurt_player(5 - player.get_tgh()) == false) {
										    cout << "You have died!" << endl;
										    return 1;
									        }
									    i++;
									
								        }
								        else {
									    cout << "Your special attack hits!  " << mon->name() << " loses " << (10 + player.get_str()) << " health." << endl;
									    if (mon->hurt_monster(10 + player.get_str()) == false) {
										cout << "You have killed the monster!" << endl;
										i = collection.erase(i);
										player.give_bonus(10);
									    }
								        }
								}
							}
						else 
							i++;
						   
											}
					else 
						i++;
					    
						
					
				}
            default:
                break;
		}