class access

This is a discussion on class access within the Game Programming forums, part of the General Programming Boards category; ok im writing an RPG and just roughing in all the classes I want the main class to be character ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    57

    class access

    ok im writing an RPG and just roughing in all the classes
    I want the main class to be character class
    I think!!
    im not putting this in code tags because like i said its just rough


    class character{
    //this will be the functions
    public:
    int getLife();
    void setLife();

    int getMana(); //leaving out all definitions for now
    void setMana();

    int getWepDam();

    int getMoney();
    void setMoney();

    int getArmorFactor();

    private:

    int life;
    int mana;
    weapon currentWeapon; // trouble here!!
    armor currentArmor;
    int money;
    }

    here is where im having trouble
    I have a weapon class as well as an
    armor class but obviously they will
    change as the game goes on so do
    I set aside the memory for say the
    weapon object and then have
    these point to the slot to obtain the
    current weapon values

    I know its all rough but any help would be appreciated
    thanks
    =@-OmegatronO-@=

  2. #2
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072

    Re: class access

    Originally posted by Megatron

    im not putting this in code tags because like i said its just rough
    I fail to see why code tags are inappropriate in this situation.
    They are always welcome.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    57
    ok then very sorry then

    Code:
    class character{
    //this will be the functions
    public:
    int getLife();
    void setLife();
    
    int getMana(); //leaving out all definitions for now
    void setMana();
    
    int getWepDam();
    
    int getMoney();
    void setMoney();
    
    int getArmorFactor();
    
    private:
    
    int life;
    int mana;
    weapon currentWeapon; // trouble here!!
    armor currentArmor; 
    int money; 
    }
    =@-OmegatronO-@=

  4. #4
    UNBANNED OneStiffRod's Avatar
    Join Date
    Jan 2002
    Posts
    669
    When making a game you should think about that each of your classes will probably be things like characters or objects that you will have to have MANY instances of...

    So, design wise, it's probably more efficient to make your classes just pure data holders, ie. they only contain variables and NO functions. *You can use structs for this also.*

    Then you can create global functions or other classes that hold purely functions to manipulate your data classes.

    Code:
    class character{
    public:
    character(); //constructor
    virtual ~character(); //destructor
    
    int life;
    int mana;
    weapon currentWeapon; // trouble here!!
    armor currentArmor; 
    int money
    };
    Here's the link to the QuakeIII source code:

    http://www.idsoftware.com/business/home/techdownloads/

    NOTICE, how they use structs as pure data holders and then global functions to manipulate those structs.
    My Avatar says: "Stay in School"

    Rocco is the Boy!
    "SHUT YOUR LIPS..."

  5. #5
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    I personally think it's fine to mix functions with variables; I just make a class that is supposed to do something, and have it store the variables that are needed to perform that function. For example:
    Code:
    class Ship
    {
       public:
          void Draw(stufftodrawto drawTo);
          void Move(int direction);
    
       protected:
          PictureData picture;
          int x, y;
    }
    A calling function tells it to move; it then changes the x and y variables. Another calling function tells it to draw, so it draws the picture at the x,y coordinates on the stufftodrawto. Is there anything wrong with that?... I mean, does it really make it more efficient to use a bunch of global functions instead of class functions?
    Last edited by Hunter2; 11-18-2002 at 07:39 PM.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  6. #6
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    I see But just a question, is this HD memory, RAM, or both?
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Visual Studio - Access PictureBox outside Form1 class?
    By andreasleon in forum C# Programming
    Replies: 1
    Last Post: 06-08-2009, 02:55 PM
  2. deriving classes
    By l2u in forum C++ Programming
    Replies: 12
    Last Post: 01-15-2007, 05:01 PM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  4. class access
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 01-24-2002, 08:00 AM
  5. implicit constructor and class access
    By Clarinetster in forum C++ Programming
    Replies: 1
    Last Post: 11-22-2001, 03:59 PM

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