Thread: Need help with concepts for first game

  1. #16
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Quote Originally Posted by blankstare77
    I really want to incorporate the character class and the character name so like if the character was Elf Jim it would be better than just Elf, you know? I tried it with characters but i got a BAJILLION of errors.
    I'm not sure what you mean about the name. Maybe you mean you should have a string in the character class that would be the actual character's name like "Jason" or whatever. That would be fine.

    The code you posted is giving you errors? It should be fine, if you are referring to a different code snippet giving you errors you should post that or elaborate on the problem.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  2. #17
    Registered User
    Join Date
    Sep 2005
    Location
    USA
    Posts
    69
    If you don't want to spend loads of time making the game you should try TADS. They have almost everything already coded and all you have to do is program in the characters and objects. The address is http://www.tads.org/
    Adam

  3. #18
    Banned SniperSAS's Avatar
    Join Date
    Aug 2005
    Posts
    175
    Quote Originally Posted by beanroaster
    If you don't want to spend loads of time making the game you should try TADS. They have almost everything already coded and all you have to do is program in the characters and objects. The address is http://www.tads.org/

    Bah, the whole reason he is doing this is so he can practice c++.

  4. #19
    Registered User
    Join Date
    Sep 2005
    Location
    USA
    Posts
    69
    Quote Originally Posted by SniperSAS
    Bah, the whole reason he is doing this is so he can practice c++.
    You still have to use C++. They just take out the messy details.
    Adam

  5. #20
    Registered User
    Join Date
    Jul 2005
    Posts
    100
    I want to learn it, not take shortcuts. "Hassle" is usually associated with laziness.

  6. #21
    Registered User
    Join Date
    Jul 2005
    Posts
    100
    Code:
    #include <cstdlib> //includes rand() function (an example: when rand() %3 means 
    //means that the answer can be either case/value 0, 1, or 2!
    #include <string> // used for 
    #include <iostream>
    using namespace std;
    
    class Character {
          public:
          short int BaseHitPoints;
          short int BaseStrength;
          short int BaseManaPoints;
          short int BaseAccuracy;
    };
      
    /////////////////////FUNCTION PROTOTYPES//////////////////////////////////////////
    //////Battle Engine
    /*         
    void Attack();
    void Defend();
    void Battle();
    void Experience();*/
                  
    //////Shop Engine
    /*Not implemented in first build*/
      
      
      
      
    int main() {
         
        string CharacterClass;
        int CharacterClassvar;
        int Dwarf;
        int Elf;
        int Human;
         
        cout << "\t\t\tWELCOME TO TEXT RPG v1.0!" << endl;
        cout << "\nYou have just entered the realm of Bazeor and you shall choose your path." << endl;
        system("PAUSE");
        cout << "[D]warves have much skill with the axe and hammer and have much brute strength." << endl;
        cout << "[E]lves are cunning and have high accuracy and agility and are proficient with the bow." << endl;
        cout << "[H]umans are not very special, although they are very well balanced characters." << endl;
        cout << "\n\t\tCHOOSE YOUR PATH young adventurer" << endl;
        cout << "\nYour Character Class: " << endl;
        
        Character Player;
        cin >> CharacterClass;
        for(;;) {
        if (CharacterClass == "d" || "D") {
                           CharacterClassvar = Dwarf;
                           Player.BaseHitPoints = 50;
                           Player.BaseStrength = 6;
                           Player.BaseManaPoints = 10;
                           Player.BaseAccuracy = 2;
                           cout << "Welcome dwarf to the world of Bazeor full of treachery and villany." << endl;
                           };
        if (CharacterClass == "e" || "E") {
                           CharacterClassvar = Elf;
                           Player.BaseHitPoints = 40;
                           Player.BaseStrength = 1;
                           Player.BaseManaPoints = 50;
                           Player.BaseAccuracy = 8;
                           cout << "Welcome elf to the world of Bazeor full of treachery and villany." << endl;
                           };
        if (CharacterClass == "h" || "H") {
                           CharacterClassvar = Human;
                           Player.BaseHitPoints = 45;
                           Player.BaseStrength = 3;
                           Player.BaseManaPoints = 30;
                           Player.BaseAccuracy = 5;
                           cout << "Welcome human to the world of Bazeor full of treachery and villany." << endl;
                           };
        system("PAUSE");
        if (CharacterClassvar == Human || Elf || Dwarf) {
           break; }
    }
    ////////////////////End Character Selection/////////////////////
    
        return 0;
    }
    Okay you guys should compile the code (that's why i included all of it). It has a logical error, like whenever I choose my character class it says all three things even though I nested them. Very confusing indeed.
    Last edited by blankstare77; 09-07-2005 at 03:29 PM.

  7. #22
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Well you don't use if/else if, only if. So it checks each condition even if the previous succeeds. Also your line

    Code:
    (CharacterClass == "e" || "E")
    should read

    Code:
    (CharacterClass == "e" || CharacterClass == "E")
    Otherwise the expression "E" will always evaluate to true.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  8. #23
    Registered User
    Join Date
    Jul 2005
    Posts
    100
    CODE UPDATE:
    Code:
    #include <cstdlib> //includes rand() function (an example: when rand() %3 means 
    //means that the answer can be either case/value 0, 1, or 2!
    #include <string>  
    #include <iostream>
    using namespace std;
    
    class Character {
          public:
          short int BaseExperiencePoints;      //Prefix "curr" means current
          short int CurrExperiencePoints;
          short int BaseHitPoints;
          short int CurrHitPoints;
          short int BaseStrength;
          short int CurrStrength;
          short int BaseManaPoints;
          short int CurrManaPoints;
          short int BaseAccuracy;
          short int CurrAccuracy;
    };
    
    class Monster {
          public:
          short int MaxHitPoints;
          short int Strength;
          short int MaxManaPoints;
          short int Accuracy;
    };
    
    /////////////////////FUNCTION PROTOTYPES//////////////////////////////////////////
    //////Battle Engine
             
    void Attack();
    void Defend();
    void Battle();
    void Run();              
    //////Shop Engine
    /*Not implemented in first build*/
    //////Statistics Functions
    void Experience();  
      
    int main() {
         
        string CharacterClass;
        int CharacterClassvar;
        int Dwarf;
        int Elf;
        int Human;
        ////////Monster Defines
    
        Monster Mouse;
        Monster Rabbit;
        Monster Bird;
        Monster Gnome;
        Monster Lizard;
        
        ///////Monster Attributes
        Mouse.MaxHitPoints = 10;
        Mouse.Strength = 1;
        Mouse.MaxManaPoints = 0;
        Mouse.Accuracy = 1;
        Rabbit.MaxHitPoints = 15;
        Rabbit.Strength = 3;
        Rabbit.MaxManaPoints = 0;
        Rabbit.Accuracy = 3;
        Bird.MaxHitPoints = 22;
        Bird.MaxManaPoints = 0;
        Bird.Strength = 6;
        Bird.Accuracy = 5;
        Lizard.MaxHitPoints = 28;
        Lizard.MaxManaPoints = 0;
        Lizard.Strength = 8;
        Lizard.Accuracy = 5;
        
      
        cout << "\t\t\tWELCOME TO TEXT RPG v1.0!" << endl;
        cout << "\nYou have just entered the realm of Bazeor and you shall choose your path." << endl;
        system("PAUSE");
        cout << "[D]warves have much skill with the axe and hammer and have much brute strength." << endl;
        cout << "[E]lves are cunning and have high accuracy and agility and are proficient with the bow." << endl;
        cout << "[H]umans are not very special, although they are very well balanced characters." << endl;
        cout << "\n\t\tCHOOSE YOUR PATH young adventurer)" << endl;
        cout << "\nYour Character Class: " << endl;
    
        Character Player;
            cin >> CharacterClass;
        for(;;) {
        if (CharacterClass == "d" || CharacterClass == "D") {
                           CharacterClassvar = Dwarf;
                           Player.BaseExperiencePoints = 0;
                           Player.BaseHitPoints = 50;
                           Player.BaseStrength = 7;
                           Player.BaseManaPoints = 10;
                           Player.BaseAccuracy = 2;
                           cout << "Welcome dwarf to the world of Bazeor full of treachery and villany." << endl;
                           };
        if (CharacterClass == "e" || CharacterClass == "E") {
                           CharacterClassvar = Elf;
                           Player.BaseExperiencePoints = 0;
                           Player.BaseHitPoints = 40;
                           Player.BaseStrength = 2;
                           Player.BaseManaPoints = 50;
                           Player.BaseAccuracy = 8;
                           cout << "Welcome elf to the world of Bazeor full of treachery and villany." << endl;
                           };
        if (CharacterClass == "h" || CharacterClass == "H") {
                           CharacterClassvar = Human;
                           Player.BaseExperiencePoints = 0;
                           Player.BaseHitPoints = 45;
                           Player.BaseStrength = 4;
                           Player.BaseManaPoints = 30;
                           Player.BaseAccuracy = 5;
                           cout << "Welcome human to the world of Bazeor full of treachery and villany." << endl;
                           };
        system("PAUSE");
        if (CharacterClassvar == Human || Elf || Dwarf) {
           break; }
    };
    
    ////////////////////Ze Beef of Ze Code///////////////////////
    string Select;
    cout << "Your choices at this moment are: [B]attle." << endl;
    cin >> Select;
    if (Select == "b" || Select == "B") {
        Battle();     
    };
    
        return 0;
    }
    
    
    ////////////////////End Character Selection/////////////////////
    //insert storyline
    
    
    
    
    ///////////////FUNCTIONS////////////////////////////////////////
    string battleSelect;
    void Battle() {
         cout << "An enemy has attacked you! What should you do?!" << endl;
         cout << "[A]ttack!  [R]un!  [D]efend!" << endl;
         if (battleSelect == "a" || battleSelect == "A") {
            Attack();  }
         else if (battleSelect == "r" || battleSelect == "R") {
            Run(); }
         else if (battleSelect == "d" || battleSelect == "D") {
            Defend(); }
         
         
         system("PAUSE");
         };
    
    void Attack() {
         
         };
    void Run() {
         
         };
    void Defend() {
         
         };
    //////////////Player Statistics////////////////////////////////
    Yeah just an update on my system.

  9. #24
    Registered User
    Join Date
    Sep 2005
    Location
    USA
    Posts
    69
    I want to learn it, not take shortcuts. "Hassle" is usually associated with laziness.
    Hey, I didn't mean it like that. I'm just saying that some people like to ease their way in slowly, and some like to dive right in, like the cold pool. Easing in slowly to learn game programming is not being lazy, it's just taking things at a different pace than other people do.
    Adam

  10. #25
    Registered User
    Join Date
    Jul 2005
    Posts
    100
    I'm having trouble.
    I define a
    Code:
    class Monster {
    //yada yada attributes
    }
    
    Monster Rabbit;
    Monster Mouse;
    But it's generating errors. Ugh.

  11. #26
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Quote Originally Posted by blankstare77
    I'm having trouble.
    I define a
    Code:
    class Monster {
    //yada yada attributes
    }
    
    Monster Rabbit;
    Monster Mouse;
    But it's generating errors. Ugh.
    You need a semi-colon after classes and structs, as you seem to know. So what other code is giving the error? what line, is it the code from the previous post?
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  12. #27
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    *double post
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  13. #28
    Registered User
    Join Date
    Jul 2005
    Posts
    100
    EDIT:
    Fixed it. It's because I named a function Monster() and a class Monster so there was confusion. Changed function name to randMonster();.
    Last edited by blankstare77; 09-09-2005 at 06:02 PM.

  14. #29
    Registered User
    Join Date
    Sep 2005
    Posts
    12
    Code:
        Character Player;
            cin >> CharacterClass;
        for(;;) {
        if (CharacterClass == "d" || CharacterClass == "D") {
                           CharacterClassvar = Dwarf;
                           Player.BaseExperiencePoints = 0;
                           Player.BaseHitPoints = 50;
                           Player.BaseStrength = 7;
                           Player.BaseManaPoints = 10;
                           Player.BaseAccuracy = 2;
                           cout << "Welcome dwarf to the world of Bazeor full of treachery and villany." << endl;
                           };
        if (CharacterClass == "e" || CharacterClass == "E") {
                           CharacterClassvar = Elf;
                           Player.BaseExperiencePoints = 0;
                           Player.BaseHitPoints = 40;
                           Player.BaseStrength = 2;
                           Player.BaseManaPoints = 50;
                           Player.BaseAccuracy = 8;
                           cout << "Welcome elf to the world of Bazeor full of treachery and villany." << endl;
                           };
        if (CharacterClass == "h" || CharacterClass == "H") {
                           CharacterClassvar = Human;
                           Player.BaseExperiencePoints = 0;
                           Player.BaseHitPoints = 45;
                           Player.BaseStrength = 4;
                           Player.BaseManaPoints = 30;
                           Player.BaseAccuracy = 5;
                           cout << "Welcome human to the world of Bazeor full of treachery and villany." << endl;
                           };
        system("PAUSE");
        if (CharacterClassvar == Human || Elf || Dwarf) {
           break; }
    };
    Why aren't you using a switch/case here?

    also to streamline this:
    Code:
    cout << "Welcome dwarf to the world of Bazeor full of treachery and villany." << endl;
    Code:
    cout << "Welcome elf to the world of Bazeor full of treachery and villany." << endl;
    Code:
    cout << "Welcome human to the world of Bazeor full of treachery and villany." << endl;
    try this instead:
    Code:
        Character Player;
            cin >> CharacterClass;
        for(;;) {
        if (CharacterClass == "d" || CharacterClass == "D") {
                           CharacterClassvar = Dwarf;
                           Player.BaseExperiencePoints = 0;
                           Player.BaseHitPoints = 50;
                           Player.BaseStrength = 7;
                           Player.BaseManaPoints = 10;
                           Player.BaseAccuracy = 2;
                           };
        if (CharacterClass == "e" || CharacterClass == "E") {
                           CharacterClassvar = Elf;
                           Player.BaseExperiencePoints = 0;
                           Player.BaseHitPoints = 40;
                           Player.BaseStrength = 2;
                           Player.BaseManaPoints = 50;
                           Player.BaseAccuracy = 8;
                           };
        if (CharacterClass == "h" || CharacterClass == "H") {
                           CharacterClassvar = Human;
                           Player.BaseExperiencePoints = 0;
                           Player.BaseHitPoints = 45;
                           Player.BaseStrength = 4;
                           Player.BaseManaPoints = 30;
                           Player.BaseAccuracy = 5;
                           };
        cout << "Welcome "<<tolower(CharacterClassvar)<< " to the world of Bazeor full of treachery and villany." << endl;
        system("PAUSE");
        if (CharacterClassvar == Human || Elf || Dwarf) {
           break; }
    };
    this way you only need to type it once

    So how's the game going?

  15. #30
    Registered User
    Join Date
    Jul 2005
    Posts
    100
    It's going okay except the fact that I have no time to work on it for a long time

    But here's my code anyway:
    Code:
    #include <cstdlib> //includes rand() function (an example: when rand() %3 means 
    //means that the answer can be either case/value 0, 1, or 2!
    #include <string>  
    #include <iostream>
    using namespace std;
    
    class Character {
          public:
          short int BaseExperiencePoints;      //Prefix "curr" means current
          short int CurrExperiencePoints;
          short int Level;
          short int BaseHitPoints;
          short int CurrHitPoints;
          short int BaseStrength;
          short int CurrStrength;
          short int BaseManaPoints;
          short int CurrManaPoints;
          short int BaseAccuracy;
          short int CurrAccuracy;
    };
    
    class Monster {
          public:
          short int MaxHitPoints;
          short int Strength;
          short int MaxManaPoints;
          short int Accuracy;
          void expGive();
    };
    
    /////////////////////FUNCTION PROTOTYPES//////////////////////////////////////////
    //////Battle Engine
             
    void Attack();  
    //Ommitted Defend(); function because of real use  
    void Battle();  //the core of the battle system
    void Run(); 
    void randMonster(); //random monster generator              
    //////Shop Engine
    /*Not implemented in first build*/
    //////Statistics Functions
    void Experience();  
      
    int main() {
         
        string CharacterClass;
        int CharacterClassvar;
        int Dwarf;
        int Elf;
        int Human;
        
        Monster Rabbit;
        Monster Mouse;
        Monster Lizard;
        Monster Gnome;
        Monster Giant;
        
        /*Rabbit.MaxHitPoints =
        Rabbit.Strength = 
        Rabbit.MaxManaPoints = 
        Rabbit.Accuracy = 
    
        Mouse.MaxHitPoints =
        Mouse.Strength = 
        Mouse.MaxManaPoints = 
        Mouse.Accuracy = 
        
        Lizard.MaxHitPoints =
        Lizard.Strength = 
        Lizard.MaxManaPoints = 
        Lizard.Accuracy = 
        
        Gnome.MaxHitPoints =
        Gnome.Strength = 
        Gnome.MaxManaPoints = 
        Gnome.Accuracy = 
    
        Giant.MaxHitPoints =
        Giant.Strength = 
        Giant.MaxManaPoints = 
        Giant.Accuracy =
        */
        
        ///////////////////BEGIN GAME/////////////////////////////////     
        ////////////////Character Selection
        cout << "\t\t\tWELCOME TO TEXT RPG v1.0!" << endl;
        cout << "\nYou have just entered the realm of Bazeor and you shall choose your path." << endl;
        system("PAUSE");
        cout << "[D]warves have much skill with the axe and hammer and have much brute strength." << endl;
        cout << "[E]lves are cunning and have high accuracy and agility and are proficient with the bow." << endl;
        cout << "[H]umans are not very special, although they are very well balanced characters." << endl;
        cout << "\n\t\tCHOOSE YOUR PATH young adventurer)" << endl;
        cout << "\nYour Character Class: " << endl;
    
        Character Player;
            cin >> CharacterClass;
        for(;;) {
        if (CharacterClass == "d" || CharacterClass == "D") {
                           CharacterClassvar = Dwarf;
                           Player.BaseExperiencePoints = 0;
                           Player.BaseHitPoints = 50;
                           Player.BaseStrength = 7;
                           Player.BaseManaPoints = 10;
                           Player.BaseAccuracy = 2;
                           cout << "Welcome dwarf to the world of Bazeor full of treachery and villany." << endl;
                           };
        if (CharacterClass == "e" || CharacterClass == "E") {
                           CharacterClassvar = Elf;
                           Player.BaseExperiencePoints = 0;
                           Player.BaseHitPoints = 40;
                           Player.BaseStrength = 2;
                           Player.BaseManaPoints = 50;
                           Player.BaseAccuracy = 8;
                           cout << "Welcome elf to the world of Bazeor full of treachery and villany." << endl;
                           };
        if (CharacterClass == "h" || CharacterClass == "H") {
                           CharacterClassvar = Human;
                           Player.BaseExperiencePoints = 0;
                           Player.BaseHitPoints = 45;
                           Player.BaseStrength = 4;
                           Player.BaseManaPoints = 30;
                           Player.BaseAccuracy = 5;
                           cout << "Welcome human to the world of Bazeor full of treachery and villany." << endl;
                           };
        system("PAUSE");
        if (CharacterClassvar == Human || Elf || Dwarf) {
           break; }
    };
    
    ////////////////////Ze Beef of Ze Code///////////////////////
    string Select;
    cout << "Your choices at this moment are: [B]attle." << endl;
    cin >> Select;
    if (Select == "b" || Select == "B") {
        Battle();     
    };
    
        return 0;
    };
    
    
    ////////////////////End Character Selection/////////////////////
    //insert storyline
    
    
    
    
    ///////////////FUNCTIONS////////////////////////////////////////
    string battleSelect;
    void Battle() {
         cout << "An enemy has attacked you! What should you do?!" << endl;
         cout << "[A]ttack!  [R]un!  [D]efend!" << endl;
         if (battleSelect == "a" || battleSelect == "A") {
            Attack();  }
         else if (battleSelect == "r" || battleSelect == "R") {
            Run(); }
    } 
    //end battle
    
    
    
    void Attack() {
         cout << "You attack the enemy!" << endl;
    }
    void Run() {
         cout << "You run away!" << endl;
    }
    
    void randMonster() {
         if (Character.Level <= 3) {
         //Rabbit or Mouse
         }
         if (Character.Level >= 7) {
         //Gnome or Lizard
         }
         if (Character.Level >= 10) {
         //Giant...or more
         }
    }
    //////////////Player Statistics////////////////////////////////
    /*void Experience() (
         //continue...
         }*/
    void expGive() {
         //experience give function for monsters inside 
         //monster class...
         }
    Last edited by blankstare77; 10-01-2005 at 08:57 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do the game engine and the api interact?
    By Shadow12345 in forum Game Programming
    Replies: 9
    Last Post: 12-08-2010, 12:08 AM
  2. 2D RPG Online Game Project. 30% Complete. To be released and marketed.
    By drallstars in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 10-28-2006, 12:48 AM
  3. So you want to be a game programmer?
    By dxfoo in forum Game Programming
    Replies: 23
    Last Post: 09-26-2006, 08:38 AM
  4. My Maze Game --- A Few Questions
    By TechWins in forum Game Programming
    Replies: 18
    Last Post: 04-24-2002, 11:00 PM