OOP game

Well, Im making a c++ OOP game and I have a character class, and a separate class for every signle character. How can I make a character selection menu?
1
2
3
4
5
int choice;
cout << "Choose a character:" << endl;
cout << "1 - Some character option" << endl;
cout << "2 - Some other option" << endl;
cin >> choice;
I want everything to be structured. So should I make a character selection class and an object to every single char.. or there is a better way.
One of the worst possible ways is to make everything a class. It shows a fundamental misunderstanding of why classes exist and will everything far more complicated than it should be.

Classes exist for your convenience; to make it easier for you to think about how to solve a given problem, and to make it easier for you to think about how to write that solution programatically.

There is no absolute "this MUST be a class and that MUST NOT be". The best I've seen is that if if makes it easier for you to think of something as a discrete object that should take care of its own internals, then it might be sensible to make it a class. If you're going to have lots of different thingies of the same type, then making that type a class would be very sensible.

This is about how you think about solving problems. Sometimes making classes is sensible, sometimes it isn't.

A character is something you can easily think about as a separate, complete object. You will want to make more than one of them. They will have internal values that they need to look after and keep track of. You will need to pass them around functions.

A "character selection" is not something that is easy to think of as an object. You won't want to make lots of them. It won't have internal values to keep track of. It won't need to be passed around; the very idea of somehow passing it around makes no sense.
I don't create or "code" a menu style selection inside the class (where I will create a method for it). Instead, I create those outside the class.. Like I code it in a separate function and just call it from main
Well, I guess will do it "the old way". Thank you all.
A game is a great thing for OOP. A charakter is certainly a class. A level is a class too. Everything that has traits is mostly apt to be a class.

a class 'level' has a list of objects (the traits are the coordinates). if a charakter class inherites from such an object it can apear within that level. An artifact may also apear in that level because it extends the object. A door (to another level) would be another example for a class. You see that designing a game with classes is rather fun and makes it easier.

if you're not sure whether something is a class like that character selection menu do it with functions. It's not wrong to mix both styles.
Topic archived. No new replies allowed.