| poridgemaster18 (2) | |
|
Hey all, What is the best way to include a whole bunch of structs into a program. I'm messing around with a pokemon game and I need to have access to their stat data. Something like.. Struct Pikachu { int HP = 20; int attack = 22; int defense = 17; int speed = 25; }; I could write them all in my driver program, but that looks bad and clunky. If a class is the best way to go, do I need a header file and .cpp file if I only want to include structs? Thanks, ~The poridgemaster | |
|
|
|
| Framework (3116) | |||||||
The best option is not to create a structure for each Pokemon, but to create a structure which contains all the data that each Pokemon has in common. For example:
Since each Pokemon has the above traits in common, we can easily avoid making the same data structure multiple times (if I remember rightly, there's ~260 Pokemon?). So when we want to create a new Pokemon, we just instantiate the data structure (creating a new Pokemon):
Then, to access "Pikachu"'s data, we use the member-access operator (.):
[Note: I used to play a lot of Pokemon when I was a toddler] References: Structures: http://www.cplusplus.com/doc/tutorial/structures/ Wazzak | |||||||
|
Last edited on
|
|||||||
| poridgemaster18 (2) | |
|
Good call. Thank you. Now there are like over 500 pokemon I think. I only care about the first 150 for the most part, because the later gen ones are stupid. Thanks again ~The poridgemaster | |
|
|
|