My Rpg system(Text)

This is a discussion on My Rpg system(Text) within the C++ Programming forums, part of the General Programming Boards category; I'm off, im going to go learn More about Enum, templates, functions, class, object oriented programming. I'll come back in ...

  1. #1
    kevinawad
    Guest
    I'm off, im going to go learn More about Enum, templates, functions, class, object oriented programming. I'll come back in weeks and finish this code finally . Cya!

    Library.h (Version.0.01)
    Code:
    #include <iostream>
    #include <string>
    
    using namespace std;
    main.cpp (Version.0.01)
    Code:
    #include "Player.h"
    #include "Library.h"
    
    
    
    
    int main()
    {
        
        //Player Options
        Player Player;
        
        Player.setGold(200);
        Player.setHp(100);
        Player.setMaxHp(100);
        Player.setMp(60);
        Player.setMaxMp(60);
        
        
    
      
    
        cin.get();
        
      
    }
    Player.h(Version.0.02)
    Code:
    #include "Library.h"
    
    //Player class
    class Player
    {
          //public
          public: 
          //Gold      
          void setGold(int gold);
          void addGold(int addgold);
          void looseGold(int loosegold);
          int getGold();
          //Hp
          void setHp(int hp);
          void addHp(int addhp);
          void looseHp(int loosehp);
          int getHp();
          void setMaxHp(int maxhp);
          void addMaxHp(int addmaxhp);
          void looseMaxHp(int loosemaxhp);
          int getMaxHp();
          //Mp
          void setMp(int mp);
          void addMp(int addmp);
          void looseMp(int loosemp);
          int getMp();
          void setMaxMp(int maxmp);
          void addMaxMp(int addmaxmp);
          void looseMaxMp(int loosemaxmp);
          int getMaxMp();
    	  //Name
    	  void setName(string name);
    	  int getName();
          //private
          private:  
          //gold     
          int maingold;
          //Hp
          int mainhp;
          int mainmaxhp;
          //Mp
          int mainmp;
          int mainmaxmp;
    	  //name
    	  string mainname;
          
    };
    
    //GOLD-Done###############
    
    //read the gold
    int Player::getGold()
    {
         return maingold;
    }
    
    //Loosing gold
    void Player::looseGold(int loosegold)
    {
         maingold = maingold - loosegold;
    }
    
    //set the gold
    void Player::setGold(int gold)
    {  
         maingold = gold;  
    }
    
    //add the gold
    void Player::addGold(int addgold)
    {  
         maingold = maingold + addgold;    
    }
    
    //HP-Done################
    
    //read the hp
    int Player::getHp()
    {
        return mainhp;
    }
    
    //Loose hp
    void Player::looseHp(int loosehp)
    {
         mainhp = mainhp - loosehp;
    }
         
    
    //set the Hp
    void Player::setHp(int hp)
    {
         mainhp = hp;
    }
    
    //add the hp
    void Player::addHp(int addhp)
    {
         mainhp = mainhp + addhp;
    }
    
    
    //Read the max Hp
    int Player::getMaxHp()
    {
        return mainmaxhp;
    }
    
    //Loose max hp
    void Player::looseMaxHp(int loosemaxhp)
    {
         mainmaxhp = mainmaxhp - loosemaxhp;
         
    }
    
    //set the Max Hp
    void Player::setMaxHp(int maxhp)
    {
         mainmaxhp = maxhp;
    }
    
    //add the max hp
    void Player::addMaxHp(int addmaxhp)
    {
         mainmaxhp = mainmaxhp + addmaxhp;
    }
    
    //MP-done###############
    
    //Read The MP
    int Player::getMp()
    {
        return mainmp;
    }
    
    //loose mp
    void Player::looseMp(int loosemp)
    {
         mainmp = mainmp - loosemp;
    }
         
    //set the Mp
    void Player::setMp(int mp)
    {
         mainmp = mp;
    }
    //add the MP
    void Player::addMp(int addmp)
    {
         mainmp = mainmp + addmp;
    }
    
    //Read the MaxMp
    int Player::getMaxMp()
    {
        return mainmaxmp;
    }
    
    //Loose max mp
    void Player::looseMaxMp(int loosemaxmp)
    {
         mainmaxmp = mainmaxmp - loosemaxmp;
    } 
    
    //set the MaxMp
    void Player::setMaxMp(int maxmp)
    {
         mainmaxmp = maxmp;
    }
    //Add max Mp
    void Player::addMaxMp(int addmaxmp)
    {
         mainmaxmp = mainmaxmp + addmaxmp;
    }
    
    //Name - done ##################
    int Player::getName()
    {
    
    
    
    }
    
    void Player::setName(string name)
    {
    	mainname = name;
    }


    I'm off, im going to go learn More about Enum, templates, functions, class, object oriented programming. I'll come back in weeks and finish this code finally . Cya!
    Last edited by kevinawad; 06-25-2008 at 10:54 AM.

  2. #2
    Registered User Terran's Avatar
    Join Date
    May 2008
    Location
    Nashua, NH
    Posts
    106
    Well, it's um. Interesting? I think it's a good start. But you remind me of myself the first time i learned c++. Did you ever program in Basic? lol.

    First thing i noticed, no functions. That would help clear things up first. Second, i think you need to look into using arrays. Cause that would really simplify things. It would get rid of tons of the if..else if's.

    like
    bool isinslot[20];
    string item[20];
    int equipslot[20];


    then you can use for loops to do alot of your work.

    Thirdly, create a character class! That would help clean that up too. Make the player exist!
    Sorry, but i'm a Code::Blocks man now.

  3. #3
    kevinawad
    Guest
    Yes, i know, i know how to do array and stuff..., it's just that im learning more into the inventory system and stuff. Then after , i will make functions. tommorow, ill do another better version of this system.

  4. #4
    Registered User Terran's Avatar
    Join Date
    May 2008
    Location
    Nashua, NH
    Posts
    106
    Quote Originally Posted by kevinawad View Post
    Yes, i know, i know how to do array and stuff..., it's just that im learning more into the inventory system and stuff. Then after , i will make functions. tommorow, ill do another better version of this system.
    Well i think arrays, or if you're ambitious, lists, deques, or vectors are much better then arrays.

    But i'd allso try to make a player class.
    Sorry, but i'm a Code::Blocks man now.

  5. #5
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,162
    Hmm... that's a lot of code to just showcase if, cout and cin
    I however admire your patient.

    Adding to Terran's

    - replace the if...elseif stuctures with switch
    - There's a better way to keep track of inventory locations usage. You can replace all of isinslotx with just one variable. Think about it....
    - Don't use using namespace std at global scope. I know you are not using functions or more than one source file, but get used to at least put it inside the main function in the form of using declarations instead. Even better, get used to write std::. This issue is debatable, but I personally advise against using directives. If anything use using declarations in well contained blocks of code (functions and class definitions).

    Meanwhile,

    Good variable naming (although you may want to train a better system like Camel Case or underscores), correct and consistent code formating (although you may want to get used to use more empty lines in order to better separate logical elements like those if...else if structures) and good overall program logic in my modest opinion. You are going far....
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  6. #6
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,017
    Code:
        bool isinslot1 = false;
        bool isinslot2  = false;
        ...
        bool isinslot19 = false;
        bool isinslot20 = false;
        
        
        //Items
        string item1;
        string item2;
        ...
        string item19;
        string item20;
        
        //equipitems;
        int equipslot1;
        int equipslot2;
        ...
        int equipslot19;
        int equipslot20;
    These calls for arrays.

    Code:
    if (item1 == "")
              {
                 isinslot1 = false;
              }
              else if (item2 == "")
              {
                   isinslot2 = false;
              }   
               else if (item3 == "")
              {
                   isinslot3 = false;
              }  
              ...
               else if (item19 == "")
              {
                   isinslot19 = false;
              }  
               else if (item20 == "")
              {
                   isinslot20 = false;
              }
    That calls for a for-loop. (as well as everything else like this in your code)

    A general mental guideline for a beginner is that, well written code should look "interesting" and not repetitive. Repetition is very bad for maintainability. What if, for example, you later decide to add something to your if-blocks? You will need to add them to every single one. And if you forget or skip one of them, that potentially gives you a very hard to find bug. With a loop, you only need to add it to one place.
    Last edited by cyberfish; 06-24-2008 at 08:07 PM.

  7. #7
    kevinawad
    Guest
    Thank you. I will make a cleaner version tommorow.

    Today, i was doing this to have fun and learn a bit more.

    I never made a bigger program then this. The last program i made was a guess a number. . I was training, then i decided to make this. I didn't make it clean.

    Actually, i woke up this morning, wanted to learn more about inventory system.

    I took a piece of paper, and started to write important things of an inventory system.

    Then , i started to work on it. Then, i was having fun with it, i have done the inventory system without adding anything else, i decided to add a shop, then, i added the stat function, i was going to add the skills but i decided working on the gm commands, finally, i made an unequip system. afte i done it, i made the little guy on the program, and i made that when you equip a weapon, his sword gets bigger. i never got bored and decided to make that when you add stats, you get hp , mp, attack, defense. I was going to make a battle system but it's getting late .

    That's how i came up with this one source file code. i normally use function and stuff.

  8. #8
    Registered User Terran's Avatar
    Join Date
    May 2008
    Location
    Nashua, NH
    Posts
    106
    You're not a real programmer till you get up at like 2am because you can't stop thinking about something in your program!
    Sorry, but i'm a Code::Blocks man now.

  9. #9
    kevinawad
    Guest
    Wrong, everyone who is programming is a real programmer. Sometime, programmers wake up and feel like bs...they don't want to work on their projects, and sometime, they just wake up and want to work badly on their project.

    And by the way, im only 15...Got 15 about a month ago.i wonder how i will be at 19 years old. i think ill get good enough for 3d.

  10. #10
    Registered User Terran's Avatar
    Join Date
    May 2008
    Location
    Nashua, NH
    Posts
    106
    Hey there's no such thing as "only 15" you're capable of doing whatever you set your mind to. But yeah, i get most of my programming done when i should be sleeping.
    Sorry, but i'm a Code::Blocks man now.

  11. #11
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    847
    one of your goals should be to make your programs small. with programming less is more. one of the best ways to accomplish this is object oriented programming

    consider:

    Code:
    class item
    {
        public:
        string Name;
        int weight;
        int value;
    };
    
    class entity
    {
        public:
        string Name;
        int Str;
        int Wis;
        int Dex;
        int Con;
        int Int;
    
        int Gold;
        std::vector<item>Inventory_Items;
        std::map<int,item>Equipped_Items;
    };
    
    class room
    {
        public:
        string desc;
        room *exits;
        std::vector<entity>occupants;
    };

    i just jotted this down, so there are likely some errors, but that should get you thinking a bit about how incredibly useful this programming paradigm is for something like your project

  12. #12
    kevinawad
    Guest
    Thank you M37. Like i said, im a capable of doing that, but i made the program in one source code just to learn a bit more. It's my first inventory system.

    Thank again.

  13. #13
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    903
    Wrong, everyone who is programming is a real programmer. Sometime, programmers wake up and feel like bs...they don't want to work on their projects, and sometime, they just wake up and want to work badly on their project
    Generally, I impose a 2AM curfew on coding. 2AM rolls around, coding stops. My brain is generally mush by then anyways.
    As for waking up and wanting to work, I've never done that, however, I have been known to keep paper/pen close by just in case something strikes me in the night. I write it down, go back to sleep, and wake up in the morning, generally to read it and go, "Really, my IQ drops that much in the middle of the night?"

    And by the way, im only 15...Got 15 about a month ago.i wonder how i will be at 19 years old. i think ill get good enough for 3d.
    I feel oddly qualified to answer this one... I tried 3d a couple of times between 15 & 19. Things worked, to an extent. Learned a lot. More importantly, learned how much I had yet to learn. Some friends & I were considering a 3D project, and I still wonder if I shouldn't go read the textbooks for another three years.

    *reiterates what's been said about functions/arrays/loops/etc*
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  14. #14
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,515
    Wow. Thats the longest main I've ever seen. First step is to definitely break that up into some smaller functions. A little copy and paste and you will have it done in no time.

    Keeping all that straight in one function is actually quite an accomplishment. Breaking it up will be a snap and will help you in future development on this project.
    Arrogance breeds bad code

  15. #15
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    21,163
    Just for the sake of it, since these are fixed arrays, you can try boost::array instead of std::vector.
    Boost is freely downloadable from the web.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

Page 1 of 4 1234 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. here it is again folks...news on my rpg
    By agerealm in forum Game Programming
    Replies: 3
    Last Post: 05-31-2010, 06:58 PM
  2. problem
    By ExDHaos in forum C++ Programming
    Replies: 12
    Last Post: 05-22-2009, 04:50 AM
  3. (dev) C++ Ascii Rpg
    By kevinawad in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 08-10-2008, 11:10 AM
  4. Char Variable Probelm
    By Krak in forum C++ Programming
    Replies: 1
    Last Post: 01-26-2003, 11:34 AM
  5. text rpg
    By c++.prog.newbie in forum Game Programming
    Replies: 48
    Last Post: 12-30-2001, 10:24 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21