Here is my even further updated combat routine, im always refining stuff lol.
Code:
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();
// Variable for next combat round
char NextRound; // Continue to next combat cycle
// 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);
HANDLE hConsole; // Code for colored text
hConsole = GetStdHandle(STD_OUTPUT_HANDLE); // Code for colored text
{
SetConsoleTextAttribute(hConsole, 12); // Colored Text Red
}
cout << "\nYou encounter a Level " << MonsterLevel << " " << MonsterName <<" Prepare to fight!\n\n";
{
SetConsoleTextAttribute(hConsole, 15); // Colored Text White
}
cout << "Press <c> and hit enter to continue.\n";
cin >> NextRound;
while ( (MonsterHitPoints >= 1) && (PlayerHitPoints >= 1) )
if ( (MonsterHitPoints >= 1) && (PlayerHitPoints >= 1) )
{
{
SetConsoleTextAttribute(hConsole, 12); // Colored Text Red
}
cout << "\nStarting combat round between [" << PlayerName <<"] & [" << MonsterName <<"]!\n\n";
{
SetConsoleTextAttribute(hConsole, 15); // Colored Text White
}
if ( (MonsterHitPoints >= 1) && (PlayerHitPoints >= 1) )
{
PlayerHitCheck = rand() % (PlayerLevel * 2) + PlayerHitHigh;
if (PlayerHitCheck >= 50)
{
{
SetConsoleTextAttribute(hConsole, 10); // Colored Text Green
}
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
{
SetConsoleTextAttribute(hConsole, 14); // Colored Text Yellow
}
cout << "------------------------------\n";
cout << "" << PlayerName <<"'s hitpoints are: " << PlayerHitPoints << ".\n";
cout << "" << MonsterName <<"'s hitpoints are: " << MonsterHitPoints << ".\n";
cout << "------------------------------\n\n";
{
SetConsoleTextAttribute(hConsole, 15); // Colored Text White
}
cout << "Press <c> and hit enter to continue.\n";
cin >> NextRound;
PLAYERMISS:
if ( (MonsterHitPoints >= 1) && (PlayerHitPoints >= 1) )
{
MonsterHitCheck = rand() % (MonsterLevel * 2) + MonsterHitHigh;
if (MonsterHitCheck >= 50)
{
{
SetConsoleTextAttribute(hConsole, 11); // Colored Text Blue
}
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
{
SetConsoleTextAttribute(hConsole, 14); // Colored Text Yellow
}
cout << "------------------------------\n";
cout << "" << PlayerName <<"'s hitpoints are: " << PlayerHitPoints << ".\n";
cout << "" << MonsterName <<"'s hitpoints are: " << MonsterHitPoints << ".\n";
cout << "------------------------------\n\n";
{
SetConsoleTextAttribute(hConsole, 15); // Colored Text White
}
cout << "Press <c> and hit enter to continue to the next combat round.\n";
cin >> NextRound;
}
else
{
{
SetConsoleTextAttribute(hConsole, 11); // Colored Text Blue
}
cout << "\n" << MonsterName <<" swing's at " << PlayerName << " and misses!\n\n";
{
SetConsoleTextAttribute(hConsole, 15); // Colored Text White
}
cout << "Press <c> and hit enter to continue to the next combat round.\n";
cin >> NextRound;
}
}
else
{
if (MonsterHitPoints >= 1)
{
cout << "\n" << PlayerName <<" has died! [GAME OVER]\n\n";
goto COMBATEND;
}
else
{
cout << "\n" << MonsterName <<" has died! [VICTORY!]\n\n";
cout << "You find " << MonsterGold <<" gold pieces!\n";
cout << "You gain " << MonsterExperience <<" experience!\n";
PlayerGold = PlayerGold + MonsterGold; // Award player gold
PlayerExperience = PlayerExperience + MonsterExperience; // 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;
goto COMBATEND;
}
}
}
else
{
{
SetConsoleTextAttribute(hConsole, 10); // Colored Text Green
}
cout << "\n" << PlayerName <<" swing's at the " << MonsterName << " and misses!\n\n";
{
SetConsoleTextAttribute(hConsole, 15); // Colored Text White
}
cout << "Press <c> and hit enter to continue.\n";
cin >> NextRound;
goto PLAYERMISS;
}
}
else
{
if (MonsterHitPoints >= 1)
{
cout << "\n" << PlayerName <<" has died! [GAME OVER]\n\n";
goto COMBATEND;
}
else
{
cout << "\n" << MonsterName <<" has died! [VICTORY!]\n\n";
cout << "You find " << MonsterGold <<" gold pieces!\n";
cout << "You gain " << MonsterExperience <<" experience!\n";
PlayerGold = PlayerGold + MonsterGold; // Award player gold
PlayerExperience = PlayerExperience + MonsterExperience; // 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;
goto COMBATEND;
}
}
}
else
{
cout << "Error: [Player or Monster HP <= 0] This should never occur. Contact developer!";
cin >> NextRound;
}
if (PlayerHitPoints >=1)
{
cout << "\n" << MonsterName <<" has died! [VICTORY!]\n\n";
cout << "You find " << MonsterGold <<" gold pieces!\n";
cout << "You gain " << MonsterExperience <<" experience!\n";
PlayerGold = PlayerGold + MonsterGold; // Award player gold
PlayerExperience = PlayerExperience + MonsterExperience; // 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;
}
else
{
cout << "\n" << PlayerName <<" has died! [GAME OVER]\n\n";
goto COMBATEND;
}
COMBATEND:
mciSendString("stop C:/KingdomOfMythos/Midi/MythosCombat1.mid" ,NULL,0,NULL); // Close Midi Music
if (PlayerHitPoints >= 1)
{
ExperienceCalculator();
}
else
{
{
SetConsoleTextAttribute(hConsole, 15); // Colored Text White
}
cout << "\n[";
{
SetConsoleTextAttribute(hConsole, 12); // Colored Text Red
}
cout << " SYSTEM MESSAGE: ";
{
SetConsoleTextAttribute(hConsole, 15); // Colored Text White
}
cout << "Player Death ]\n";
cout << "\nExiting combat because player has died.\n\n";
}
return 0;
}