1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
while (choice != -1)
{
choice = 0;
//Choose a random enemy and set it inside vector, if we dont do this
//A random enemy will be chosen for each call in the fight, we want
//the same eney for the duration of the fight.
Enemy randomEnemy{ enemyContainer[RandomNumber(generator, 0, enemyContainer.size() -1)] };
Item randomItem{ itemList[RandomNumber(generator, 0, itemList.size() -1)] };
//Randomly generate a reward and set it for this fight, then re-randomize it
//for the next fight.
randomEnemy.GiveMoney(RandomNumber(generator, 10, 100));
randomEnemy.XpToGive(RandomNumber(generator, 10, 60));
//This makes it so most attacks have a 90% chance to hit.
cout << "Monster Fight Version 0.20.1-W.3 - 937 Lines of Code\n" << endl;
cout << "What would you like to do?\n" << endl;
cout << "1) Fight" << endl;
cout << "2) Quit" << endl;
cout << "\n> ";
cin >> choice;
switch (choice)
{
case 1:
cin.ignore(numeric_limits<streamsize>::max(), '\n');
//Initial encounter
cout << "\n" << Hero.GetName() << " encountered a " << randomEnemy.GetName() << "!" << endl;
cout << "It has " << randomEnemy.GetHealth() << " Health!\n" << endl;
turn = 1;
while (Hero.GetHealth() > 0)
{
cout << "\n################################################################" << endl;
cout << "##" << " MONSTER FIGHT ##" << endl;
cout << "################################################################" << endl;
//============================================
//Player chooses Attack
//============================================
int counter{ 1 };
int attackChoice{ 0 };
cout << "\nUse what attack?\n" << endl;
for (auto& i : Hero.GetAttackList())
{
if (Hero.GetAttackList().empty())
{
cout << Hero.GetName() << "'s attack list is empty!" << endl;
}
else
{
cout << counter++ << ") " << i << endl;
}
}
cin >> attackChoice;
//Call generator to re-randomize
generator();
if(RandomNumber(generator, 0, attackHitChance) == 0)
{
cout << Hero.GetName() << "'s attack missed!\n" << endl;
}
else
{
cout << "\nACTION------------------------------------------------------------------" << endl;
cout << Hero.GetName() << " used " << Hero.GetAttackList()[attackChoice -1].GetName()
<< " against the " << randomEnemy.GetName() << ", it does " << Hero.GetAttackList()[attackChoice -1].GetPower() << " damage." << endl;
randomEnemy.TakeDamage(Hero.GetAttackList()[attackChoice -1].GetPower());
}
//============================================
//Check to see if enemy is dead and if so
//then give player money, xp, and items
//============================================
if (randomEnemy.GetHealth() <= 0)
{
cout << Hero.GetName() << " defeated " << randomEnemy.GetName();
cout << " and got " << randomEnemy.GetMoney() << " gold and ";
Hero.GiveExperience(randomEnemy.GetXpToGive());
cout << randomEnemy.GetXpToGive() << " experience.\n" << endl;
Hero.LevelUp();
Hero.GiveMoney(randomEnemy.GetMoney());
cout << randomEnemy.GetName() << " dropped " << RandomNumber(generator, 1, 3) << " " << randomItem.GetName() << "'s." << endl;
Hero.AddItemToInventory(randomItem, RandomNumber(generator, 1, 3));
battles++;
Hero.IncrememntKillCounter();
cout << "\n================================================================\n" << endl;
break;
}
//============================================
//Randomly Choose enemy Attack
//============================================
/*ISSUE
* Something im wondering, if i call generator to randomize attack hit chance
* will it randomize the enemy name and attack and attack power? it doesnt
* seem to, it seems to choose one enemy and attack power and attack and
* use it, however i am unsure.
*/
generator();
if(RandomNumber(generator, 0, attackHitChance) == 0)
{
cout << randomEnemy.GetName() << "'s attack missed!" << endl;
}
else
{
/*BUG
* Having an issue here specifically with randomEnemy.GetAttackList().size()
* causing an issue with the randomizer.
*/
cout << "ENEMY ATTACK LIST SIZE: " << randomEnemy.GetAttackList().size() << endl;//Debug
cout << "HERO ATTACK LIST SIZE: " << Hero.GetAttackList().size() << endl;//Debug
if (randomEnemy.GetAttackList().size() == 0)
{
cout << "ERROR: Enemy attack list vector is empty." << endl;
}
else
{
cout << randomEnemy.GetName() << " uses " << randomEnemy.GetAttackList()[RandomNumber(generator, 0, randomEnemy.GetAttackList().size() - 1)].GetName();
cout << " against " << Hero.GetName() << ", and it does ";
cout << randomEnemy.GetAttackList()[RandomNumber(generator, 0, randomEnemy.GetAttackList().size() - 1)].GetPower() << " damage!\n" << endl;
Hero.TakeDamage(randomEnemy.GetAttackList()[RandomNumber(generator, 0, randomEnemy.GetAttackList().size() - 1)].GetPower());
}
}
|