Please give me some feedback and tips. =D
fixed why it wasnt compiling. i read on some site that max is defined as a macro in <windows.h>. it said to replace
- cin.ignore(numeric_limits<streamsize>::max(), '\n';
with
- cin.ignore((numeric_limits<streamsize>::max)(), '\n');
- Code: Select all
#include "stdafx.h"
#include <limits>
#include <ctime>
#include <string>
#include <windows.h>
#include <iostream>
using namespace std;
bool playGameFunc();
void repeatGame();
string playerOneName();
string playerTwoName();
void loadingGame();
void playerOneTurnIntro();
void playerTwoTurnIntro();
void playerOneWin();
void playerTwoWin();
void playerDraw();
bool criticalHit();
void error();
class playerOneStats
{
public:
int health;
int maxHealth;
unsigned int mana;
unsigned int maxMana;
};
class playerTwoStats
{
public:
int health;
int maxHealth;
unsigned int mana;
unsigned int maxMana;
};
bool playGame = true;
int main()
{
system("TITLE Class Duels 1.5 - Morags");
srand((unsigned)time(0));
string playerOne = playerOneName();
string playerTwo = playerTwoName();
playerOneStats p1;
playerTwoStats p2;
p1.health = 20000;
p1.maxHealth = 20000;
p1.mana = 15000;
p1.maxMana = 15000;
p2.health = 20000;
p2.maxHealth = 20000;
p2.mana = 15000;
p2.maxMana = 15000;
const int attackMana = 0;
const int moonfireMana = 1000;
const int wrathMana = 2000;
const int starfireMana = 3000;
const int healingtouchMana = 4000;
const int cycloneMana = 4000;
const int manaRegen = 500;
const int attackDamage = 1000;
const int moonfireDamage = 2000;
const int wrathDamage = 3000;
const int starfireDamage = 4000;
const int healingtouchDamage = 5000;
const int cycloneHeal = 2000;
bool playerOneTurn = true;
bool playerOneWinGame = false;
bool playerTwoWinGame = false;
bool loading = true;
int playerChoice = 0;
if ( loading == true )
{
loadingGame();
loading = false;
}
while ( playerOneWinGame != true && playerTwoWinGame != true && playGame == true )
{
if ( p1.mana != p1.maxMana )
{
( p1.mana += manaRegen );
system("cls");
cout << "\n\n\t" << playerOne
<< "\t\t\t\t\t" << playerTwo
<< "\n\n\tHealth: " << p1.health << " / " << p1.maxHealth
<< "\t\t\tHealth: " << p2.health << " / " << p2.maxHealth
<< "\n\tMana: " << p1.mana << "/ " << p1.maxMana
<< "\t\t\tMana: " << p2.mana << " / " << p2.maxMana;
cout << "\n\n\n\t" << playerOne << " regenerates " << manaRegen << " mana.";
Sleep(1500);
}
if ( p2.mana != p2.maxMana )
{
( p2.mana += manaRegen );
system("cls");
cout << "\n\n\t" << playerOne
<< "\t\t\t\t\t" << playerTwo
<< "\n\n\tHealth: " << p1.health << " / " << p1.maxHealth
<< "\t\t\tHealth: " << p2.health << " / " << p2.maxHealth
<< "\n\tMana: " << p1.mana << " / " << p1.maxMana
<< "\t\t\tMana: " << p2.mana << " / " << p2.maxMana;
cout << "\n\n\n\t" << playerTwo << " regenerates " << manaRegen << " mana.";
Sleep(1500);
}
system("cls");
while ( playerOneTurn == true )
{
if ( p1.mana <= 0 )
{
p1.mana = 0;
}
if ( p1.health > 0 && p2.health <= 0 )
{
playerOneWinGame = true;
playerTwoWinGame = false;
break;
}
if ( p1.health <= 0 && p2.health > 0 )
{
playerOneWinGame = false;
playerTwoWinGame = true;
break;
}
if ( p1.health <= 0 && p2.health <= 0 )
{
playerOneWinGame = true;
playerTwoWinGame = true;
break;
}
playerOneTurnIntro();
system("cls");
cout << "\n\n\t" << playerOne
<< "\t\t\t\t\t" << playerTwo
<< "\n\n\tHealth: " << p1.health << " / " << p1.maxHealth
<< "\t\t\tHealth: " << p2.health << " / " << p2.maxHealth
<< "\n\tMana: " << p1.mana << " / " << p1.maxMana
<< "\t\t\tMana: " << p2.mana << " / " << p2.maxMana;
cout << "\n\n\n\tWhat would you like to do?"
<< "\n\n\t[1] Attack - Deals " << attackDamage << " damage."
<< "\n\n\t[2] Moonfire - Deals " << moonfireDamage << " damage, Costs " << moonfireMana << " mana."
<< "\n\n\t[3] Wrath - Deals " << wrathDamage << " damage, Costs " << wrathMana << " mana."
<< "\n\n\t[4] Starfire - Deals " << starfireDamage << " damage, Costs " << starfireMana << " mana."
<< "\n\n\t[5] Healing Touch - Heals " << healingtouchDamage << " health, Costs " << healingtouchMana << " mana."
<< "\n\n\t[6] Cyclone - Skips P2's turn, heals for " << cycloneHeal << ", Costs " << cycloneMana << " mana."
<< "\n\n\tChoice: ";
if (!( cin >> playerChoice ))
{
error();
continue;
}
if ( playerChoice != 1 && playerChoice != 2 && playerChoice != 3 && playerChoice != 4 && playerChoice != 5 && playerChoice != 6 )
{
error();
continue;
}
if ( playerChoice == 1 && p1.mana >= attackMana )
{
if ( criticalHit() == true )
{
( p2.health -= ( attackDamage * 2 ));
( p1.mana -= ( attackMana ));
system("cls");
cout << "\n\n\t" << playerOne
<< "\t\t\t\t\t" << playerTwo
<< "\n\n\tHealth: " << p1.health << " / " << p1.maxHealth
<< "\t\t\tHealth: " << p2.health << " / " << p2.maxHealth
<< "\n\tMana: " << p1.mana << " / " << p1.maxMana
<< "\t\t\tMana: " << p2.mana << " / " << p2.maxMana
<< "\n\n\n\t" << playerOne << "'s Attack critically hits " << playerTwo << " for " << ( attackDamage * 2 ) << " damage.";
Sleep(2000);
playerOneTurn = false;
break;
}
else
{
( p2.health -= attackDamage );
( p1.mana -= ( attackMana ));
system("cls");
cout << "\n\n\t" << playerOne
<< "\t\t\t\t\t" << playerTwo
<< "\n\n\tHealth: " << p1.health << " / " << p1.maxHealth
<< "\t\t\tHealth: " << p2.health << " / " << p2.maxHealth
<< "\n\tMana: " << p1.mana << " / " << p1.maxMana
<< "\t\t\tMana: " << p2.mana << " / " << p2.maxMana
<< "\n\n\n\t" << playerOne << "'s Attack hits " << playerTwo << " for " << attackDamage << " damage.";
Sleep(2000);
playerOneTurn = false;
break;
}
}
if ( playerChoice == 2 && p1.mana >= moonfireMana )
{
if ( criticalHit() == true )
{
( p2.health -= ( moonfireDamage * 2 ));
( p1.mana -= moonfireMana );
system("cls");
cout << "\n\n\t" << playerOne
<< "\t\t\t\t\t" << playerTwo
<< "\n\n\tHealth: " << p1.health << " / " << p1.maxHealth
<< "\t\t\tHealth: " << p2.health << " / " << p2.maxHealth
<< "\n\tMana: " << p1.mana << " / " << p1.maxMana
<< "\t\t\tMana: " << p2.mana << " / " << p2.maxMana
<< "\n\n\n\t" << playerOne << "'s Moonfire critically hits " << playerTwo << " for " << ( moonfireDamage * 2 ) << " damage.";
Sleep(2000);
playerOneTurn = false;
break;
}
else
{
( p2.health -= moonfireDamage );
( p1.mana -= moonfireMana );
system("cls");
cout << "\n\n\t" << playerOne
<< "\t\t\t\t\t" << playerTwo
<< "\n\n\tHealth: " << p1.health << " / " << p1.maxHealth
<< "\t\t\tHealth: " << p2.health << " / " << p2.maxHealth
<< "\n\tMana: " << p1.mana << " / " << p1.maxMana
<< "\t\t\tMana: " << p2.mana << " / " << p2.maxMana
<< "\n\n\n\t" << playerOne << "'s Moonfire hits " << playerTwo << " for " << moonfireDamage << " damage.";
Sleep(2000);
playerOneTurn = false;
break;
}
}
if ( playerChoice == 3 && p1.mana >= wrathMana )
{
if ( criticalHit() == true )
{
( p2.health -= ( wrathDamage * 2 ));
( p1.mana -= wrathMana );
system("cls");
cout << "\n\n\t" << playerOne
<< "\t\t\t\t\t" << playerTwo
<< "\n\n\tHealth: " << p1.health << " / " << p1.maxHealth
<< "\t\t\tHealth: " << p2.health << " / " << p2.maxHealth
<< "\n\tMana: " << p1.mana << " / " << p1.maxMana
<< "\t\t\tMana: " << p2.mana << " / " << p2.maxMana
<< "\n\n\n\t" << playerOne << "'s Wrath critically hits " << playerTwo << " for " << ( wrathDamage * 2 ) << " damage.";
Sleep(2000);
playerOneTurn = false;
break;
}
else
{
( p2.health -= wrathDamage );
( p1.mana -= wrathMana );
system("cls");
cout << "\n\n\t" << playerOne
<< "\t\t\t\t\t" << playerTwo
<< "\n\n\tHealth: " << p1.health << " / " << p1.maxHealth
<< "\t\t\tHealth: " << p2.health << " / " << p2.maxHealth
<< "\n\tMana: " << p1.mana << " / " << p1.maxMana
<< "\t\t\tMana: " << p2.mana << " / " << p2.maxMana
<< "\n\n\n\t" << playerOne << "'s Wrath hits " << playerTwo << " for " << wrathDamage << " damage.";
Sleep(2000);
playerOneTurn = false;
break;
}
}
if ( playerChoice == 4 && p1.mana >= starfireMana )
{
if ( criticalHit() == true )
{
( p2.health -= ( starfireDamage * 2 ));
( p1.mana -= starfireMana );
system("cls");
cout << "\n\n\t" << playerOne
<< "\t\t\t\t\t" << playerTwo
<< "\n\n\tHealth: " << p1.health << " / " << p1.maxHealth
<< "\t\t\tHealth: " << p2.health << " / " << p2.maxHealth
<< "\n\tMana: " << p1.mana << " / " << p1.maxMana
<< "\t\t\tMana: " << p2.mana << " / " << p2.maxMana
<< "\n\n\n\t" << playerOne << "'s Starfire critically hits " << playerTwo << " for " << ( starfireDamage * 2 ) << " damage.";
Sleep(2000);
playerOneTurn = false;
break;
}
else
{
( p2.health -= starfireDamage );
( p1.mana -= starfireMana );
system("cls");
cout << "\n\n\t" << playerOne
<< "\t\t\t\t\t" << playerTwo
<< "\n\n\tHealth: " << p1.health << " / " << p1.maxHealth
<< "\t\t\tHealth: " << p2.health << " / " << p2.maxHealth
<< "\n\tMana: " << p1.mana << " / " << p1.maxMana
<< "\t\t\tMana: " << p2.mana << " / " << p2.maxMana
<< "\n\n\n\t" << playerOne << "'s Starfire hits " << playerTwo << " for " << starfireDamage << " damage.";
Sleep(2000);
playerOneTurn = false;
break;
}
}
if ( playerChoice == 5 && p1.mana >= healingtouchMana && p1.health != p1.maxHealth && p1.health <= ( p1.maxHealth - healingtouchDamage ))
{
if ( criticalHit() == true )
{
( p1.health += ( healingtouchDamage * 2 ));
( p1.mana -= healingtouchMana );
system("cls");
cout << "\n\n\t" << playerOne
<< "\t\t\t\t\t" << playerTwo
<< "\n\n\tHealth: " << p1.health << " / " << p1.maxHealth
<< "\t\t\tHealth: " << p2.health << " / " << p2.maxHealth
<< "\n\tMana: " << p1.mana << " / " << p1.maxMana
<< "\t\t\tMana: " << p2.mana << " / " << p2.maxMana
<< "\n\n\n\t" << playerOne << "'s Healing Touch critically heals for " << ( healingtouchDamage * 2 ) << ".";
Sleep(2000);
playerOneTurn = false;
break;
}
else
{
( p1.health += healingtouchDamage );
( p1.mana -= healingtouchMana );
system("cls");
cout << "\n\n\t" << playerOne
<< "\t\t\t\t\t" << playerTwo
<< "\n\n\tHealth: " << p1.health << " / " << p1.maxHealth
<< "\t\t\tHealth: " << p2.health << " / " << p2.maxHealth
<< "\n\tMana: " << p1.mana << " / " << p1.maxMana
<< "\t\t\tMana: " << p2.mana << " / " << p2.maxMana
<< "\n\n\n\t" << playerOne << "'s Healing Touch heals for " << healingtouchDamage << ".";
Sleep(2000);
playerOneTurn = false;
break;
}
}
if ( playerChoice == 5 && p1.mana >= healingtouchMana && p1.health == p1.maxHealth )
{
system("cls");
cout << "\n\n\t" << playerOne
<< "\t\t\t\t\t" << playerTwo
<< "\n\n\tHealth: " << p1.health << " / " << p1.maxHealth
<< "\t\t\tHealth: " << p2.health << " / " << p2.maxHealth
<< "\n\tMana: " << p1.mana << " / " << p1.maxMana
<< "\t\t\tMana: " << p2.mana << " / " << p2.maxMana
<< "\n\n\n\tYour health is already full.";
Sleep(2000);
continue;
}
if ( playerChoice == 5 && p1.mana >= healingtouchMana && p1.health > ( p1.maxHealth - healingtouchDamage ))
{
int totalHeal = ( p1.maxHealth - p1.health );
( p1.health += totalHeal );
( p1.mana -= healingtouchMana );
system("cls");
cout << "\n\n\t" << playerOne
<< "\t\t\t\t\t" << playerTwo
<< "\n\n\tHealth: " << p1.health << " / " << p1.maxHealth
<< "\t\t\tHealth: " << p2.health << " / " << p2.maxHealth
<< "\n\tMana: " << p1.mana << " / " << p1.maxMana
<< "\t\t\tMana: " << p2.mana << " / " << p2.maxMana
<< "\n\n\n\t" << playerOne << "'s Healing Touch heals for " << totalHeal << ".";
Sleep(2000);
playerOneTurn = false;
break;
}
if ( playerChoice == 6 && p1.mana >= cycloneMana && p1.health != p1.maxHealth && p1.health <= ( p1.maxHealth - cycloneHeal ))
{
( p1.health += cycloneHeal );
( p1.mana -= cycloneMana );
system("cls");
cout << "\n\n\t" << playerOne
<< "\t\t\t\t\t" << playerTwo
<< "\n\n\tHealth: " << p1.health << " / " << p1.maxHealth
<< "\t\t\tHealth: " << p2.health << " / " << p2.maxHealth
<< "\n\tMana: " << p1.mana << " / " << p1.maxMana
<< "\t\t\tMana: " << p2.mana << " / " << p2.maxMana
<< "\n\n\n\t" << playerOne << "'s Cyclone heals for " << cycloneHeal << ".";
Sleep(2000);
system("cls");
cout << "\n\n\t" << playerOne
<< "\t\t\t\t\t" << playerTwo
<< "\n\n\tHealth: " << p1.health << " / " << p1.maxHealth
<< "\t\t\tHealth: " << p2.health << " / " << p2.maxHealth
<< "\n\tMana: " << p1.mana << " / " << p1.maxMana
<< "\t\t\tMana: " << p2.mana << " / " << p2.maxMana
<< "\n\n\n\t" << playerTwo << "'s Turn is missed due to the cyclone.";
Sleep(2000);
continue;
}
if ( playerChoice == 6 && p1.mana >= cycloneMana && p1.health != p1.maxHealth && p1.health > ( p1.maxHealth - cycloneHeal ))
{
int totalHealCyclone = ( p1.maxHealth - p1.health );
( p1.health += totalHealCyclone );
( p1.mana -= cycloneMana );
system("cls");
cout << "\n\n\t" << playerOne
<< "\t\t\t\t\t" << playerTwo
<< "\n\n\tHealth: " << p1.health << " / " << p1.maxHealth
<< "\t\t\tHealth: " << p2.health << " / " << p2.maxHealth
<< "\n\tMana: " << p1.mana << " / " << p1.maxMana
<< "\t\t\tMana: " << p2.mana << " / " << p2.maxMana
<< "\n\n\n\t" << playerOne << "'s Cyclone heals for " << totalHealCyclone << ".";
Sleep(2000);
system("cls");
cout << "\n\n\t" << playerOne
<< "\t\t\t\t\t" << playerTwo
<< "\n\n\tHealth: " << p1.health << " / " << p1.maxHealth
<< "\t\t\tHealth: " << p2.health << " / " << p2.maxHealth
<< "\n\tMana: " << p1.mana << " / " << p1.maxMana
<< "\t\t\tMana: " << p2.mana << " / " << p2.maxMana
<< "\n\n\n\t" << playerTwo << "'s Turn is missed due to the cyclone.";
Sleep(2000);
continue;
}
if ( playerChoice == 6 && p1.mana >= cycloneMana && p1.health == p1.maxHealth )
{
system("cls");
cout << "\n\n\t" << playerOne
<< "\t\t\t\t\t" << playerTwo
<< "\n\n\tHealth: " << p1.health << " / " << p1.maxHealth
<< "\t\t\tHealth: " << p2.health << " / " << p2.maxHealth
<< "\n\tMana: " << p1.mana << " / " << p1.maxMana
<< "\t\t\tMana: " << p2.mana << " / " << p2.maxMana
<< "\n\n\n\tYour health is already full.";
Sleep(2000);
continue;
}
if ( p1.mana < attackMana || p1.mana < moonfireMana || p1.mana < wrathMana || p1.mana < starfireMana || p1.mana < healingtouchMana && p1.mana < cycloneMana )
{
system("cls");
cout << "\n\n\t" << playerOne
<< "\t\t\t\t\t" << playerTwo
<< "\n\n\tHealth: " << p1.health << " / " << p1.maxHealth
<< "\t\t\tHealth: " << p2.health << " / " << p2.maxHealth
<< "\n\tMana: " << p1.mana << " / " << p1.maxMana
<< "\t\t\tMana: " << p2.mana << " / " << p2.maxMana
<< "\n\n\n\tYou do not have enough mana to cast that spell.";
Sleep(1000);
continue;
}
}
