#include <iostream>
#include <windows.h>
#include <conio.h>

using namespace std;

int selectHero();
void Str();
void Agi();
void Int();
void Kunkka();
int Item1();
int Item2();
int ChooseI();
void NormalAtk();
void AInormalAtk();
void Choice();
void Attack();
void Skill();
void Defend();
int Run();
void AIchoice();
void AIattack();
void AIskill();
void AIdefend();
int AIrun();
void AIHeal();
void Heal();
int Hp1 = 1803, Hp2 = 1974, Mana1 = 585 , Mana2 = 676, Armr1 = 9, Armr2 = 3, Hp1base=0, Mana1base=0 , Hp2base=0, Mana2base=0;
int Herodmg1 = 120, Herodmg2 = 139, nStr = 85, nAgi = 45, nInt = 52;

int main()
{   
        selectHero();
        cout << "\nPress any key to proceed to shop....";
        getch();
        cout << "\nChoose Item";
        cout << "\nPress [a] to choose vanguard";
        cout << "\nPress [b] to choose Bloodstone";
        cout << "\nEnter Answer: ";
        ChooseI();
        cout << "\nPress any key to proceed to battle";
        getch();
    do
    {
      system("cls");
      cout << "\n\t\t******STATUS******\n";
      cout << "\nYour Hero" << "\t\t" << "Enemy Hero" ;
      cout << "\n Hp: "    << Hp1 << "\t"    << " Hp: "   << Hp2 ;
      cout << "\n Mana: "  <<  Mana1 << "\t" << " Mana: " << Mana2 ;
      cout << "\n Armor: " << Armr1 << "\t"  << " Armor: "     << Armr2 ;
      cout << "\n" ;
      Choice();
      cout << "\n" ;
      AIchoice();
      cout << "\nPress any key to continue";
      getch();
      }
      while( Hp1 !=0 || Hp2 !=0); 
      
      getch();
      return 0;

    
    }
    
int selectHero()
{
     int nChoice;
     char cChoice ;
     cout << "Welcome to Warcraft III";
     cout << "\nSelect the Type of Hero You Want" ;
     cout << "\nPress [a] to Choose Strength(Str) Heroes" ;
     cout << "\nPress [b] to Choose Agility(Agi) Heroes" ;
     cout << "\nPress [c] to Choose Inteligence(Int) Heroes" ;
     cout << "\nEnter Your Answer: " ;
     cin  >> cChoice ;
     
     if ( cChoice == 'a' || cChoice == 'A')
     {
          cChoice = 'a' ;
          }
     
     if ( cChoice == 'b' || cChoice == 'B')
     {
          cChoice = 'b' ;
          }
     
     if ( cChoice == 'c' || cChoice == 'C')
     {
          cChoice = 'c' ;
          }
     
switch ( cChoice )
{
       case 'a' : Str();
                       cout << "\nPlease Pick a Hero";
                       cout << "\nEnter Your Answer: ";
                       cin  >> nChoice;
switch ( nChoice ) 
{
   case 1 : Kunkka();
			break;
        }
        }
     }
     
void Str()
{
     cout << "\nPress [1] Kunkka"                     << "\nPress [2] BeastMaster"              << "\nPress [3] CentaurWarchief"       ;
     }
     
void Kunkka()
{
    cout << "\nYou have chosen Admiral";
    cout << "\nDAMAGE: 111-121";
    cout << "\nHP: "     << Hp1        << "\tSTR: "  << nStr;
    cout << "\nMANA: "   << Mana1      << "\tAGI: "  << nAgi;
    cout << "\nARMOR: "  << Armr1      << "\tINT: "  << nInt;
    cout << "\nSKILLS:";
	cout << "\nTorrent";
	cout << "\nDamage: 300" << "\tManaCost: 120";
    cout << "\nTide Bringer";
   	cout << "\nPassive: +60 damage";
    cout << "\nGhost Ship";
    cout << "\nDamage: 500" << "\tManaCost: 250";
     }
     
int ChooseI()
{
     char cItem;
     cin >> cItem;
     switch ( cItem )
     {
            case 'a':
                 {
                     Hp1base = Item1(); 
                     break;
                 }
            case 'b':
                  {
                  Mana1base = Item2();
                      break;
                  }
            default :
                    {
                 break;
                    }
            return Hp1base;
            return Mana1base;
     }
     
}     
void Attack()
{
     char cAns;
     cout << "\n n to normal attack s to use skills";
     cout << "\nEnter Answer: ";
     cin >> cAns;
     switch ( cAns )
     {
            case 'n':
                 {
                      NormalAtk();
                      break;
                 }
            case 's':
                 {
                      Skill();
                      break;
                 }
            default:
                    {
                            cout << "\n Invalid input.Please input again.";
                            Attack();
                    }
     }
     }
void Defend()
{
     Armr1 = (( Armr1*.5) + Armr1); 
     cout << "\n You chose to defend. Armor is now " << Armr1;
}
int Run()
{
     srand((unsigned)time(0));
     int random_integer;
     for ( int index=0; index<1; index++);
     random_integer = (rand()%100);
     cout << random_integer;
     if ( random_integer <= 30 )
     {
          cout << "\n You have ran away from battle";
          
          return 0;
          }
     else
     {
         cout << "\n You can't escape from battle";
         }
}
void Skill()
{
     char cUsrAns;
     cout << "\n What skill will you use?";
     cout << "\n Skill A: Torrent Damage:300 \n Mana Cost:120";
     cout << "\n Skill B: Ghost Ship Damage:500 \n Mana Cost:250";
     cout << "\nEnter Answer: ";
     cin >> cUsrAns;
     switch ( cUsrAns )
     {
            case 'a':
                 {
                     if ( Mana1 < 119 )
                     {
                          cout <<"\nNot! enough mana";
                          Choice();
                          }
                          else
                          {
                           Mana1 -= 120;
                           Hp2 = Hp2 - 300;
                           }
                     cout << "\n Your mana is now " << Mana1;
                     cout << "\n Enemy Hp is now " << Hp2;
                     break;
                 }
            case 'b':
                 {
                     
                     if ( Mana1 <249 )
                     {
                          cout << "\nNot! enough mana";
                          Choice();
                          }
                          else
                          {
                           Mana1 -= 250;
                           Hp2 = Hp2 - 500;
                           }
                     cout << "\n Your mana is now " << Mana1;
                     cout << "\n Enemy Hp is now " << Hp2;
                     break;
                 }
            default:
                    {
                          cout << "\n Invalid Input";
                          Skill();
                    }
}
}
void Choice()
{
     char cChoice;
     cout << "\n What move will you make?";
     cout << "\n A:Attack" << "\n B:Defend" << "\n C:Run" << "\n D:Heal";
     cout << "\nEnter Answer: ";
     cin >> cChoice;
     switch ( cChoice )
     {
            case 'a':
                 {   
                     Attack();
                     break;
                     }
            case 'b':
                 {
                     Defend();
                     break;
                     }
            case 'c':
                 {
                     Run();
                     break;
                     }
            case 'd':
                 {
                     Heal();
                     break;
                     }
            default:
                    {
                           cout << "\n Invalid Input.Please Input again";
                           Choice();
                           }
                           }
}
void NormalAtk()
{
     Hp2 = Hp2 - ( Herodmg1 - Armr2 );
     cout << "\n You have dealt " << Herodmg1;
     cout << "\n Enemy's HP is now " << Hp2;
}

void AIchoice()
{
     srand((unsigned)time(0));
     int random_integer;
     for ( int index=0; index<1; index++);
     random_integer = (rand()%4+1);
     cout << "\n\nAI will now make its move.";
     cout << "\n 1.Attack" << "\n 2.Defend" << "\n 3.Run" << "\n 4.Heal";
     switch ( random_integer )
     {
            case 1:
                 {   
                     AIattack();
                     break;
                     }
            case 2:
                 {
                     AIdefend();
                     break;
                     }
            case 3:
                 {
                     AIrun();
                     break;
                     }
            case 4:
                 {
                     AIHeal();
                     break;
                     }
            default:
                    {
                           cout << "\n Invalid Input.Please Input again";
                           Choice();
                           }
                           }
     }
void AIattack()
{
     srand((unsigned)time(0));
     int random_integer;
     for ( int index=0; index<1; index++);
     random_integer = (rand()%2+1);
     switch ( random_integer )
     {
            case 1:
                 {
                             AInormalAtk();
                             break;
                 }
            case 2:
                 {
                             AIskill();
                             break;
                 }
            default:
                    {
                             cout << "AI error.";
                             AIattack();
                    }
     }
     }
void AIskill()
{
     cout << "\n Used skill";
     srand((unsigned)time(0));
     int random_integer;
     for ( int index=0; index<1; index++);
     random_integer = (rand()%2+1);
     switch ( random_integer )
     {
            case 1:
                 {
                             cout << "\n AI used Avalanche";
                             Hp1 = Hp1 - 300;
                             cout << "\n Your Hp is now " << Hp1;
                             break;
                 }
            case 2:
                 {
                             cout << "\n AI used Toss";
                             Hp1 = Hp1 - 350;
                             cout << "\n Your Hp is now " << Hp1;
                             break;
                 }
            default:
                    {
                             cout << "\nAI error";
                             AIskill();
                    }
     }
}
void AIdefend()
{
     cout << "\n AI defended";
     Armr2 = ( Armr2 + ( Armr2*.5));
     cout << "\n AI's armor is now " << Armr2;
     }
int AIrun()
{
     srand((unsigned)time(0));
     int random_integer;
     for ( int index=0; index<1; index++);
     random_integer = (rand()%100);
     if ( random_integer <= 30 )
     {
          cout << "\n AI have ran away from battle";
          return 0;
          }
     else
     {
         cout << "\n AI can't escape from battle";
         }
     }
void AInormalAtk()
{
     cout << "\n AI attacked.";
     Hp1 = Hp1 - ( Herodmg2 - Armr1 );
     cout << "\n AI dealt " << Herodmg2 << " damage";
     cout << "\n Your health is now " << Hp1;
}
void Heal()
{
     if ( Hp1base > Hp1 )
     {
          Hp1base = Hp1;
          }
          else
          {
              Hp1base = Hp1base + 100;
              }
     if ( Mana1base > Mana1 )
     {
        Mana1base = Mana1;
        }
     else
     {
         Mana1base = Mana1base + 50;
         } 
}
void AIHeal()
{
     Hp2 += 100;
     if ( Hp2base > Hp2 )
     {
          Hp2base = Hp2;
          }
     Mana2 += 50;
     if ( Mana2base > Mana2 )
     {
          Mana2base = Mana2;
          }
     cout << "\n AI has replenished his health and mana.";
}
int Item2()
{
    cout << "\nItem #2";
    cout << "\n Bloodstone";
    cout << "\nHp + 500 Mana + 400";
    Hp1 += 500;
    Mana1 += 400;
}
int Item1()
{
     cout << "\nItem #1";
     cout << "\nVanguard";
     cout << "\nHp + 275" ;
     Hp1 = Hp1 + 275;
     return Hp1;
     }

my problem is when i heal at full health,it is not supposed to heal because it is full.but still,when i choose heal,hp and mana still replenishes.help anyone?

Please help me.When i use heal,and im at full health and mana,it will not replenish.

The order of the tests is reversed; you want to increment the base amount first, then check whether it is over the maximum after the values have been increased.

void Heal()
{
     Hp1base += 100;
     // if the increase goes over the HP max, adjust to the max
     if ( Hp1base > Hp1 )
     {
          Hp1base = Hp1;
     }

     Mana1base += 50;
     // if the increase goes over the Mana max, adjust to the max 
     if ( Mana1base > Mana1 )
     {
        Mana1base = Mana1;
     }
}

I don't know how advanced you are in C++ yet, but I would suggest making a Hero class, which you can then instantiate for the individual characters, rather than repeating (more or less) the same code for the player's hero and the AI hero.

As an aside, you might want to change the name of the game to something that isn't already copyrighted :P

Thanks

Still not solved. Hm..

sorry if i used the name of heroes in warcraft.we'll change it because our project is text-based dota

Still not solved. Hm..

How is it behaving now? What is it doing wrong, or not doing right?

sorry if i used the name of heroes in warcraft.we'll change it because our project is text-based dota

Hey, I figure that's between you and Blizzard. I just found it amusing.

sorry if i used the name of heroes in warcraft.we'll change it because our project is text-based dota

The problem isn't your hero class it's the program name "Warcraft...". If Blizzard gets hold of your program, you can be sued for violating their copyright(s).

Can you describe the behavior you're expecting and how the behavior you're getting differs from it? Without a clear explanation of your problem, all we can do is take shots in the dark.

I just notice that Hp1 and Hp1base are reversed in all of those cases.

void Heal()
{
    Hp1 += 100;
    // if the increase goes over the HP max, adjust to the max
    if ( Hp1 > Hp1base )
    {
        Hp1 = Hp1base;
    }

    Mana1 += 50;
    // if the increase goes over the Mana max, adjust to the max
    if ( Mana1 > Mana1base )
    {
        Mana1 = Mana1base;
    }
}

I'll also repeat my earlier suggestion of making a class to represent the Hero characters in the abstract, rather than having a separate AI Hero with completely different, redundant functions. A simple sketch of the class definition might be:

class Hero
{
public:
    Hero(string name, int str, int intel, int agil, int hp, int mana, int armor);

    //
    void NormalAttack();
    void Choice();
    void Attack();
    void Skill();
    void Defend();
    int Run();
    void Heal();
    
    // accessors
    int getStrength();
    int getIntelligence();
    int getAgility();

private:
    unsigned strength, intelligence, agility;
    int currentHp, baseHp;
    int currentMana, baseMana;
    int currentArmor, baseArmor;
};

The program purposed is so long and somewhat difficult please make it some short and easy so that everyone can try it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.