Well, this is my second try to OOP design a game .I never would have thought this field is so complicated.
It seems I missed a lot.It would have never occured to me to try an idea like hstubb's one.
I guess I'll try for the moment Mussi's first suggestion.
Thanks for the time to reply .
[OOP] Two classes that can acces each other's members
Wouldnt it be worth experimenting with inheritance ?
Make a base class , say Entity ( controls all types of movable objects) , and have Player inherit this Entity class, and your Enemy inherit the class... so both are a Entity, and share the basic structure of an Entity but have special functions related to themselves.
I am not too comfortable with OOP myself, but that would be something I would experiment with as a attempt to see if it solves my issues.
Make a base class , say Entity ( controls all types of movable objects) , and have Player inherit this Entity class, and your Enemy inherit the class... so both are a Entity, and share the basic structure of an Entity but have special functions related to themselves.
I am not too comfortable with OOP myself, but that would be something I would experiment with as a attempt to see if it solves my issues.
You have some freedom in C++ that you shouldn't use if you want to follow correctly the OO paradigm. For example, suggestion A of Madhed said:
A. Make all members public[/quote]
This is very wrong. C++ allows you to do that, but you will create a strong relationship between A and B that may cause you greater problems in the future. Besides, those classes won't be easily reused throughout your code or other projects.
Try looking a little into OO basics and search for some Design Patterns like MVC first.
I'm a beginner and only have experience with Java so far, but accessing another classes members should be as simple as creating a public method that returns the wanted information.
Maybe I don't understand the question properly.
Maybe I don't understand the question properly.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement