Thread: Need Help With Classes For A RPG

  1. #1
    Registered User
    Join Date
    Nov 2011

    Need Help With Classes For A RPG

    I know, I know... I can easily find hundreds of tutorials online about making classes in C++ for text-based RPG's, which I have!.. but I really need a better explanation and step-thru than the ones I've been finding..

    First up for my RPG, I need a class for my character.. what would it look like? This is all that I've done for my code... Beware, it looks hidieous, mostly because I have no idea how to set up classes..

    #include <iostream>
    #include <string>
    using namespace std;
    int main()
        class Player {
        int health;
        int attack;
        int defend;
        void move();
        void attackmonster();
        void drinkpotion() { health++;}
    First up, I feel like I do not have the effecient header files needed. Second, I have no idea what to do with the variables in my "public" and "private", I just got it from a forum from another site I found on google, and switched some of the variable names up...

    Can any one walk me through this plsssss =(

    I am so confused ...................

  2. #2
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Copy Paste won't help you much in understanding what is going on.
    This probably will :Classes (I) - C++ Documentation

  3. #3
    Registered User
    Join Date
    Nov 2011
    Can you please explain what is going on during the "Constructor" and "Destructor".. I have read the same article multiple times, but I don't really understand how to use it in a program. Thank you for the reply!

  4. #4
    Join Date
    Oct 2007
    Inside my computer
    Just simply put, constructor is called once the object is first created. The destructor is called once the object goes out of scope. That's all.
    So we use the constructor to make the object ready for use (ie initialize values, attain resources, etc), and the destructor to clean everything up (release any allocated resources).
    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.

  5. #5
    Join Date
    Nov 2004
    tip: move your class out of your main method. In fact you should move it to a separate header and implementation file (1 set per class or closely related group of classes).

    Start organising your code properly at the start, much easier than reorganising it at a later stage

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Conversions between base classes and derived classes
    By tharnier in forum C++ Programming
    Replies: 14
    Last Post: 03-18-2011, 10:50 AM
  2. Classes access other classes local variables
    By parad0x13 in forum C++ Programming
    Replies: 6
    Last Post: 01-14-2010, 04:36 AM
  3. Classes with Other Classes as Member Data
    By njd in forum C++ Programming
    Replies: 2
    Last Post: 09-27-2005, 09:30 AM
  4. Help accessing classes and derived classes
    By hobbes67 in forum C++ Programming
    Replies: 8
    Last Post: 07-14-2005, 02:46 PM
  5. Accessing Classes in Classes
    By GrNxxDaY in forum C++ Programming
    Replies: 18
    Last Post: 07-30-2002, 01:54 PM