I have this combat program and if the monsters hitpoints hit 0 or -# on the players swing, it always fires off 1 more monster swing before victory is declared and i cant seem to find whats wrong, ive tried else if, and ive tried adding another tier of if else and still nothing and its driving me nuts lol
Code:
int CombatZombie()
{
mciSendString("stop C:/KingdomOfMythos/Midi/MythosMusic1.mid" ,NULL,0,NULL); // Open Midi Music
mciSendString("stop C:/KingdomOfMythos/Midi/MythosIntro.mid" ,NULL,0,NULL); // Open Midi Music
mciSendString("stop C:/KingdomOfMythos/Midi/MythosInn.mid" ,NULL,0,NULL); // Open Midi Music
mciSendString("play C:/KingdomOfMythos/Midi/MythosCombat1.mid" ,NULL,0,NULL); // Open Midi Music
//Initialize function
int ExperienceCalculator();
// Strings and extra variables
string MonsterName = "Zombie"; // Monster name or type
char NextRound; // Continue to next combat cycle
// Monster variables
int MonsterLevel = 1;
int MonsterHitPoints = 10;
int MonsterAttack = 6;
int MonsterDefense = 3;
int MonsterHitRate = 50;
// Temporary player variables to check for equipment
int TempPlayerAttack = PlayerAttack + PlayerWeapon;
int TempPlayerDefense = PlayerDefense + PlayerArmorShield + PlayerArmorBody + PlayerArmorLegs + PlayerArmorHands + PlayerArmorFeet;
// Monster damage variables using rand
// Also subtracts player defense from monsters damage
int LowMonster = 2;
int HighMonster = MonsterAttack - TempPlayerDefense;
// Player damage variables using rand
// Also subtraces monster defense from players damage
int LowPlayer = 2;
int HighPlayer = TempPlayerAttack - MonsterDefense;
// Variable to see if player or monster land a blow
int PlayerHitCheck = 0;
int MonsterHitCheck = 0;
// Player % chance to hit high and low
int PlayerHitLow = 1;
int PlayerHitHigh = 100;
// Monster % chance to hit high and low
int MonsterHitLow = 1;
int MonsterHitHigh = 100;
// Player & Monster damage results die 1 + die 2
int MonsterDamageResults = 0;
int PlayerDamageResults = 0;
//Variables to hold random values for the first and the second die on each roll.
int first_die, sec_die;
//Declare variable to hold seconds on clock.
time_t seconds;
//Get value from system clock and place in seconds variable.
time(&seconds);
//Convert seconds to a unsigned integer.
srand((unsigned int) seconds);
/// COMBAT SCRIPT BELOW
cout << "You encounter a Level 1 Zombie. Prepare to fight!\n";
cout << "Press <c> and hit enter to continue.\n";
cin >> NextRound;
while ( ( PlayerHitPoints >= 1 ) && ( MonsterHitPoints >= 1 ) )
{
if ( (MonsterHitPoints >= 1) && (PlayerHitPoints >= 1) )
{
cout << "\nStarting combat round between [" << PlayerName <<"] & [" << MonsterName <<"]!\n";
PlayerHitCheck = rand() % (PlayerHitHigh - PlayerHitLow +1) + PlayerHitLow;
MonsterHitCheck = rand() % (MonsterHitHigh - MonsterHitLow +1) + MonsterHitLow;
if (PlayerHitCheck <= 25)
{
cout << "" << PlayerName <<" swing's at the " << MonsterName << " and misses!\n";
cout << "Press <c> and enter to continue to the next combat round.\n";
cin >> NextRound;
}
else
{
cout << "" << PlayerName <<" swing's at the " << MonsterName <<" and lands a blow!\n";
first_die = rand() % (HighPlayer - LowPlayer + 1) + LowPlayer; // Calculate player damage of first dice roll
sec_die = rand() % (HighPlayer - LowPlayer +1) + LowPlayer; // Calculate player damage of second dice roll
cout << "" << PlayerName <<"'s attack is (" << first_die << ", "
<< sec_die << "}\n\n";
PlayerDamageResults = sec_die + first_die; // Calculate total damage done by player
cout << "" << PlayerName << " hits " << MonsterName << " for " << PlayerDamageResults << " damage.\n";
MonsterHitPoints = MonsterHitPoints - PlayerDamageResults; // Subtract damage from monsters hitpoints
cout << "" << PlayerName <<"'s hitpoints are: " << PlayerHitPoints << ".\n";
cout << "" << MonsterName <<"'s hitpoints are: " << MonsterHitPoints << ".\n";
cout << "Press <c> and enter to continue to the next combat round.\n";
cin >> NextRound;
}
if (MonsterHitCheck <= 40)
{
cout << "" << MonsterName <<" swing's at " << PlayerName << " and misses!\n";
cout << "Press <c> and enter to continue to the next combat round.\n";
cin >> NextRound;
}
else
{
cout << "" << MonsterName <<" swing's at " << PlayerName <<" and lands a blow!\n";
first_die = rand() % (HighMonster - LowMonster + 1) + LowMonster; // Calculate monster damage of first dice roll
sec_die = rand() % (HighMonster - LowMonster + 1) + LowMonster; // Calculate monster damage of second dice roll
cout << "" << MonsterName <<"'s attack is (" << first_die << ", "
<< sec_die << "}\n\n";
MonsterDamageResults = sec_die + first_die; // Calculate total damage done by monster
cout << "" << MonsterName <<" hits " << PlayerName <<" for " << MonsterDamageResults << " damage.\n";
PlayerHitPoints = PlayerHitPoints - MonsterDamageResults; // Subtract damage from players hitpoints
cout << "" << PlayerName <<"'s hitpoints are: " << PlayerHitPoints << ".\n";
cout << "" << MonsterName <<"'s hitpoints are: " << MonsterHitPoints << ".\n";
cout << "Press <c> and enter to continue to the next combat round.\n";
cin >> NextRound;
}
}
else
{ // If & Else statements in the event a 1 hit kill blow is scored
if (PlayerHitPoints <= 0)
{
cout << "" << PlayerName <<" has died! [GAME OVER]\n\n";
cout << "Do you wish to reload your saved game? (Currently Unsupported)\n\n";
cin >> NextRound;
}
else
{
cout << "" << MonsterName <<" has died! [VICTORY!]\n\n";
cout << "You find 8 gold pieces on the " << MonsterName <<"!\n";
cout << "You gain 10 experience points!\n";
PlayerGold = PlayerGold + 8; // Award player gold
PlayerExperience = PlayerExperience + 10; // Award player experience
cout << "" << PlayerName <<"'s Current Experience: "<< PlayerExperience <<"\n";
cout << "" << PlayerName <<"'s Total Gold Pieces: "<< PlayerGold <<"\n\n";
cout << "Press <c> and hit enter to continue.\n";
cin >> NextRound;
}
}
} // If & Else statements end of combat cycle
if ( (PlayerHitPoints <=0) && ( MonsterHitPoints >=1) )
{
cout << "" << PlayerName <<" has died! [GAME OVER]\n\n";
cout << "Do you wish to reload your saved game? (Currently Unsupported)\n\n";
cin >> NextRound;
}
else
{
cout << "" << MonsterName <<" has died! [VICTORY!]\n\n";
cout << "You find 8 gold pieces on the " << MonsterName <<"!\n";
cout << "You gain 10 experience points!\n";
PlayerGold = PlayerGold + 8; // Award player gold
PlayerExperience = PlayerExperience + 10; // Award player experience
cout << "" << PlayerName <<"'s Current Experience: "<< PlayerExperience <<"\n";
cout << "" << PlayerName <<"'s Total Gold Pieces: "<< PlayerGold <<"\n\n";
cout << "Press <c> and hit enter to continue.\n";
cin >> NextRound;
}
mciSendString("stop C:/KingdomOfMythos/Midi/MythosCombat1.mid" ,NULL,0,NULL); // Open Midi Music
ExperienceCalculator();
return 0;
}