Skip to main content
gamedev.net
🔒 Locked

Simple question about class

Started by Hedos May 11, 2003 at 8:16 PM 4 replies 350+ views
Original Post
Hedos
Hedos
Hi, I have a simple question about the use of class. For exemple, in a game, I have a class that represent a monster. There is 3 kind of monsters. The player start how much monsters does he want to have at the start, he must choose a total of 10 monsters, from the 3 kind. Now, I know I will have to use "new" to create my object... But I just don''t know how to use it correctly to have differents name per monsters... I guess I have to use array... But i''m really not sure how to do that... I hope I was clear enough :\ ------------------------- Account: Hedos - Level 2 Programmer
noixtirdoe
noixtirdoe
one thing you might want to do is have a base monster class.
in that base class you might have generic "things" that all the monsters share. then you might have 3 classes that are derived from the base monster class, so the derived classes would have all the attributes of the base class. the derived classes should also include their own variables and functions that differentiate it from the other types of monster.

if you are still having some trouble, you should look up some info on "class inheritence".


-noix-

In this world gone mad, we won''t spank the monkey; the monkey will spank us.
In this world gone mad, we won't spank the monkey; the monkey will spank us.
Sander
Sander
If you are deriving different monsters from the same class as noixtirdoe suggested, store tem in a std::vector and not in an array. You can make a vector as big as you want. No need to reallocate memory. Also, you won''t get object slicing as can happen with arrays.

Sander Maréchal
[Lone Wolves Game Development][RoboBlast][Articles][GD Emporium][Webdesign][E-mail]
Hedos
Hedos
Noixtirdoe: Thanks, but my class are already derived... I''m sorry my question was probably not clear ( my english is too bad, I have difficulty to exprim myself ^^ )

smarchal: Thanks I think it may be what i''m looking for, could you tell me more about std::vector, or maybe refer me to a tutorial or something like that?
I did not find anything in the MSDN..

-------------------------
Account: Hedos - Level 2 Programmer
krez
krez
what is "object slicing"?
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.