void Game::combat(Hero& newHero,Monster& newMonster) { int playerDamage,monsterDamage; while(true) { playerDamage=newMonster.getDamage()-newHero.getBlock(); cout<<endl<<newMonster.getName()<<" damages you for "<<playerDamage<<" HP...\n"; newHero.takeDamage(playerDamage); if(newHero.getCurHP()<=0) gameEnd(); cout<<newMonster.getName()<<" HP: "<<newMonster.getHP()<<"\t\t"<<newHero.getName()<<" HP: "<<newHero.getCurHP(); _getch(); monsterDamage=newHero.getMeleeDamage(); newMonster.takeDamage(monsterDamage); if(newMonster.getHP()<=0) { cout<<endl<<"You deliver the killing blow to "<<newMonster.getName()<<"\n"; newHero.updateXP(newMonster.getLevel()); return; } cout<<endl<<"You damage "<<newMonster.getName()<<" for "<<monsterDamage<<" HP...\n"; cout<<newMonster.getName()<<" HP: "<<newMonster.getHP()<<"\t\t"<<newHero.getName()<<" HP: "<<newHero.getCurHP(); _getch(); } }
//conducts the battle between player and enemy also increments or decrements gold void battle(KillCount& kMap, Hero<int> &hero, Enemy<int> &e, int &gold){ cout << endl; //show enemy stats and players stats before player chooses weapon cout << "Now battling " << e.getName() << " " << e.getID() << " carrying " << e.getEgold() << " gold" << endl; cout << "Enemy has " << e.getAttk() << " attack" << endl; cout << hero.getName() << " has " << hero.getAttack() << endl; //player attack after the have chosen a weapon int heroBattleAttk = hero.getAttack() + hero.boost(); //show player attack after they have chosen a weapon cout << hero.getName() << " Attack become " << heroBattleAttk << endl; if(e.getAttk() > heroBattleAttk){ //if enemy has more attack player loses gold equal to amount carried by enemy cout << "You have lost battle " << e.getEgold() << " gold lost" << endl; gold -= e.getEgold(); cout << "Gold count now: " << gold << endl; }else if(e.getAttk() < heroBattleAttk){ //if player has more attack than enemy player gains gold gold carried by enemy cout << "You have won battle " << e.getEgold() << " gold gained" << endl; gold += e.getEgold(); kMap.incrementCount(e.getName()); cout << "Gold count now: " << gold << endl; }else{ //if tie no gold won or lost cout << "Battle is a tie no gold gained or lost" << endl; gold +=0; cout << "Gold count now: " << gold << endl; } }
bool DataBase::_insertHero(const Hero &hero) { QSqlQuery query(_db); query.prepare("insert into Heroes (hero_id, name) values(?, ?)"); query.addBindValue(hero.getId()); query.addBindValue(hero.getName()); return query.exec(); }
void PotionShop::EnterShop(Hero& hero) { cout << "Welcome "<< hero.getName()<< ", to the Claimh Solais Potion Shop\n"; PotionShop Potion; Potion.potionShop(hero); //Potion.potionShop(hero); //MainShop *potionShop = &Potion; // calling soldierShop //potionShop->potionShop(hero); }
void ArcherWeapons::EnterShop(Hero& hero) { cout << "Welcome "<< hero.getName()<< ", to the Claimh Solais Bow Shop\n"; ArcherWeapons bow; bow.ArcherShop(hero); //ArcherWeapons Bow; //Bow.ArcherShop(hero); //MainShop *bowShop = &Bow; // calling soldierShop //bowShop->EnterShop(hero); }
void MageArmor::EnterShop(Hero& hero) { cout << "Welcome "<< hero.getName()<< ", to the Claimh Solais Armor Shop\n" << endl; MageArmor armor_soldier; armor_soldier.MageArmor_Shop(hero); //MageArmor Sword; //Sword.MageArmor_Shop(hero); //MainShop *MageArmor = &Sword; // calling MageArmor_Shop //MageArmor->EnterShop(hero); }//Instance automatically deleted here at end of scope
//introduction for the game explains objective and game play void intro(Hero<int> &h, int gold){ cout <<"OK " << h.getName() << " your adventure begins here" << endl; cout << "Your interdimensional transport ship has run out of fuel(gold) in a \n" << "mysterious dimension you must collect at least 35 gold pieces in order \n" << "to make the trip home" << endl; cout << "Collect gold by defeating enemies in the various areas" << endl; cout << "winning gives you their gold losing removes gold equal to what the enemy " << "was carrying" << endl; cout << "your base attack is: " << h.getAttack() << endl; cout << "your base special attack is: " << h.getSpecial() << endl; cout << "you have " << gold << " to start collect at leat 35 to win" << endl; cout << "if no gold remaining you lose" << endl; cout << endl; }
Vector2D GameState::getNextCreaturePos(){ //get current creature Creature* c = plyr.getCreature(); if (!c){ //TODO return any creature cerr << "not set"; return Vector2D(-1,-1); } bool currFound = false; Hero* heros = wrld.getHeros(); for (int i = 0; i < wrld.getHeroSize(); i++){ if (wrld.getStarts()[i] != Vector2D(-1,-1)) continue; Hero h = heros[i]; if (h.getName() == c->getName() && h.getPlayer() == c->getPlayer()){ //found current currFound = true; continue; } if (currFound && h.getPlayer() == plyr.getName()){ //found next return h.getPosition(); } } vector<Monster*>& monsters = wrld.getMonsters(); for (unsigned i = 0; i < monsters.size(); i++){ Monster* m = monsters[i]; if (m->getName() == c->getName() && m->getPlayer() == c->getPlayer()){ //found current currFound = true; continue; } if (currFound && m->getPlayer() == plyr.getName()){ //found next return m->getPosition(); } } for (int i = 0; i < wrld.getHeroSize(); i++){ if (wrld.getStarts()[i] != Vector2D(-1,-1)) continue; Hero h = heros[i]; if (h.getName() == c->getName() && h.getPlayer() == c->getPlayer()){ //found current currFound = true; continue; } if (currFound && h.getPlayer() == plyr.getName()){ //found next return h.getPosition(); } } for (unsigned i = 0; i < monsters.size(); i++){ Monster* m = monsters[i]; if (m->getName() == c->getName() && m->getPlayer() == c->getPlayer()){ //found current currFound = true; continue; } if (currFound && m->getPlayer() == plyr.getName()){ //found next return m->getPosition(); } } //nothing suitable found, so the next is the old return c->getPosition(); }
bool Hero::operator<=(Hero h) { return getName() <= h.getName(); }
bool Hero::operator>=(Hero h) { return getName() >= h.getName(); }
bool Hero::operator!=(Hero h) { return getName() != h.getName(); }
bool Hero::operator==(Hero h) { return getName() == h.getName(); }