Welcome
Welcome to the forums of AntiRTFM's Absolute N00b Spoonfeed C++ Tutorials!

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. Registration is fast, simple, and absolutely free, so please, <a href="/profile.php?mode=register">join our community today</a>!

World of Warcraft Class Duels ( PART ONE )!

Finished making your own program (thats not part of the practicing forums) ? Show it off here

World of Warcraft Class Duels ( PART ONE )!

Postby morags on Thu Oct 15, 2009 11:39 pm

Hey guys ive basically written this in 4-5 hours so its probably got some problems. basically what it is a text game where you duel with wow classes. atm it only has the druid but i plan on doing all of them. I couldnt fit the whole script the other half is in "World of Warcraft Class Duels ( PART TWO )!".

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;
                }
          }
Last edited by morags on Sat Oct 17, 2009 9:53 pm, edited 3 times in total.
morags
 
Posts: 12
Joined: Tue Sep 01, 2009 4:00 am

Re: World of Warcraft Class Duels ( PART ONE )!

Postby noobgrammer on Fri Oct 16, 2009 7:02 am

Did you try compiling it before you posted it, I got multiple errors. you forgot to put in two headers :oops: . and one of them will clash with another header.
C++ gave me two solutions to this problem the second one I'll show here

Code: Select all
#define NOMINMAX //limits and windows both have a max in their headers so this will fix the problem thanks to C++

#include <limits>
#include <ctime>



I haven't had a chance to look at it yet I thought I would post this so anybody trying to run it will have a fix to it
I need a compiler with a can of RAID built into it

I added a msn messenger just for programming feel free to email or add yourself to it
User avatar
noobgrammer
 
Posts: 198
Joined: Tue Aug 25, 2009 10:44 am
Location: Orlando

Re: World of Warcraft Class Duels ( PART ONE )!

Postby noobgrammer on Fri Oct 16, 2009 7:36 am

alright I looked at it a little bit and here is an idea but you would have to redo a lot and if you did this without doing it it won't compile but its more what the classes are suppose to be used like.

Code: Select all
class Playerstats
{
   public:

      Playerstats(){}//default constructor
      ~Playerstats(){}//destructor

      PlayerStats(int _health, int _maxHealth, unsigned int _mana, unsigned int _maxMana) :
      health(_health),      //this is the initializer list
        maxHealth(_maxHealth),
        mana(_mana),
        maxMana(_maxMana)
      {}   //if you had other stuff to do you would do it in here

      int GetHealth(){return health;}//this is how you would call your private stuff
      int GetMaxHealth(){return maxHealth;}
      int GetMana(){return mana;}
      int GetMaxMana(){return maxMana;}

   private:
                 
        int health;
        int maxHealth;
        unsigned int mana;
        unsigned int maxMana;
};


you would want to make another class for the battle and make member functions to add/subtract or do whats needed with the values
I know its a little vague what I'm saying but to show it I would have to rewrite it and I'm busy working on mine right now

One thing you did with your class is you had made two when one was fine

Code: Select all
Playerstats p1(20000,20000,15000,15000);
Playerstats p2(20000,20000,15000,15000);


I changed the class name to fit better since only one was needed, you don't have to match the values either they are two separate entity's.
sorry if I sound a little gruff I'm not meaning too I have a tendency to be straight to the point so it may sound cold.
just ask if any of this sounds confusing to you.
I need a compiler with a can of RAID built into it

I added a msn messenger just for programming feel free to email or add yourself to it
User avatar
noobgrammer
 
Posts: 198
Joined: Tue Aug 25, 2009 10:44 am
Location: Orlando

Re: World of Warcraft Class Duels ( PART ONE )!

Postby morags on Sat Oct 17, 2009 9:00 pm

.
Last edited by morags on Sat Oct 17, 2009 9:02 pm, edited 1 time in total.
morags
 
Posts: 12
Joined: Tue Sep 01, 2009 4:00 am

Re: World of Warcraft Class Duels ( PART ONE )!

Postby morags on Sat Oct 17, 2009 9:01 pm

wait so u mean make a function for playerone which subtracts health and mana and that stuff and one for player 2 so its not all in the one loop?
morags
 
Posts: 12
Joined: Tue Sep 01, 2009 4:00 am

Re: World of Warcraft Class Duels ( PART ONE )!

Postby noobgrammer on Sun Oct 18, 2009 8:23 am

Here is a little example of what I'm saying

//playerstats.h
Code: Select all
#ifndef PLAYERSTATS_H
#define PLAYERSTATS_H

class Playerstats
    {
       public:

          Playerstats(){}//default constructor
          ~Playerstats(){}//destructor

          Playerstats(int , int , unsigned int , unsigned int );
         

          int GetHealth(){return health;}//this is how you would call your private stuff
          int GetMaxHealth(){return maxHealth;}
          int GetMana(){return mana;}
          int GetMaxMana(){return maxMana;}

        void AddHealth(int);//this is how you would add,subttract or whatever is need to you private stuff
        void AddMana(int);
        void SubtractHealth(int);
        void SubtractMana(int);

       private:
                     
            int health;
            int maxHealth;
            unsigned int mana;
            unsigned int maxMana;
    };

#endif

//playerstats.cpp
Code: Select all
#include "playerstats.h"

Playerstats::Playerstats(int _health, int _maxHealth, unsigned int _mana, unsigned int _maxMana) :
          health(_health),      //this is the initializer list
            maxHealth(_maxHealth),
            mana(_mana),
            maxMana(_maxMana)
          {}   //if you had other stuff to do you would do it in here

void Playerstats::AddHealth(int addH)//you must add Playerstats:: to each one so the compiler nows who it belongs to
{
   health += addH;
}
void Playerstats::AddMana(int addM)
{
   mana += addM;
}
void Playerstats::SubtractHealth(int subH)
{
   health -= subH;
}
void Playerstats::SubtractMana(int subM)
{
   mana -= subM;
}

//main
Code: Select all
#include <iostream>
#include "playerstats.h"

int main()
{
   int healthRegen = 1000;
   int attackDamage = 200;

   Playerstats p1(20000,20000,10000,15000);// this passes all to the constructor to initialize
   Playerstats p2(10000,10000,25000,25000);//I changed the stats on this one

   std::cout<< "Player ones health "<< p1.GetHealth()
      << " Player twos health " << p2.GetHealth() << "\n"; //shows they are different

    if ( p1.GetMana() < p1.GetMaxMana() )//these are just examples of how to use them
    {
       std::cout<< p1.GetMana() << "\n";
       p1.AddMana(5000);
       std::cout<< p1.GetMana() << "\n";
    }

    std::cout<< "Player gets attacked\n";
    p2.SubtractHealth(attackDamage * 2);
    std::cout<< "You now have " << p2.GetHealth() << "\n";
    p2.AddHealth(healthRegen);
    std::cout<< "You use mana regen now you have " << p2.GetHealth() << "\n";
}


I try to show you how to call your private stuff and also to show you that your p1 and p2 are different. as you see the functions in playerstats.cpp both p1 and p2 use the same functions but there values are completely different. As you can see to use class in its proper way you would have to do a lot of editing to your project. oh by the way don't forget to put these after your member function calls () I can't tell you how many times I do that and can't figure out why I'm getting errors. VS intelesence doesn't spit them out so I forget to add them.
hope that helps a little if not just ask
I need a compiler with a can of RAID built into it

I added a msn messenger just for programming feel free to email or add yourself to it
User avatar
noobgrammer
 
Posts: 198
Joined: Tue Aug 25, 2009 10:44 am
Location: Orlando

Re: World of Warcraft Class Duels ( PART ONE )!

Postby backlash53 on Sat Oct 31, 2009 12:18 pm

Doesnt even compile for me : /
backlash53
 
Posts: 26
Joined: Wed Feb 04, 2009 1:42 pm


Return to Full programs

Who is online

Users browsing this forum: No registered users and 0 guests