Public Group

# Help with some basic OOP structuring

This topic is 2271 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have some decent level of programming experience, I've been progessing along nicely (typically outstripping my courses, and being self-taught). I'm by no means anywhere near expert, but somewhere in this dillusional brain, I like to think I've passed some beginner milestones. That being said, I've moved on to my second visual game. The first I did in 6 weeks as a final for my last Programming class. It worked. Honestly it did a lot better than I'd expected, but I know it isn't what I'm really capable of. I think the reason, or one of them, is because I went in with good intentions, and a handful of useful skills, but no knowledge of HOW I should be actually designing my game.

I attempted to implement a main class, whose sole job was to change out states, like the projector operator at a cinema; but where I really feel short was just in the way I structured the game specific objects. The map, the tiles, and the pieces that went on top of that.

Fast forward to today, I've gone from Java to C++ (partially so I can be closer to the SDL libraries, and hopefully OpenGL later on down the line). I'm working on a basis for the game to work off of. I'm attempting to create a more dynamic, cell-based, map model. Something to really breathe life into the towns and surrounding areas that the player might inhabit. The question I have (if you've managed to read this far down my rant ) is on how to setup the couple of classes that I want to work with each other as far as "towns" are concerned. So far, I have a Tile Block, which will receive information on what type of tie it is (water, mountain, hill, etc), and then what sort of environment goes on top of that (forest, desert, etc), and it'll then be able to hold some sort of human inhabitibility, a town or settlement of some form. That part is 'simple'. As for the towns I've seperated Citizens out (I'll work on specializing them later), and then I have a town class, which will do things like manage all of the things that are pertainent, like which of the factors make the town succeusful, and what things it struggles with (i,e, timber if it's in a forest, and having a lack of metals for tools, or viable farm space, etc). Then, on top of that I have a Government class, which will manage things like taxing the Citizens, and maintain the towns strengths (funding a militia, etc). These governments will communicate amoungst one another, and vie for power, etc. I plan on having them being exchangable (i.e. if one town takes another, and installs it's own leader).

With all of that said and done, what I'm looking to find an answer to is how should I structure the couple classes (Citizen, Government, and Town specifically). I want the Government to be able to tax all it's citizens, as well as any governments it's above (i.e. installed ones in controlled towns), but because it might be changeable I don't want to have the problem of "orphaned" towns. So I didn't know whether or not to place the Government at the top, and then just have a retool method (which would change out all of it's members) or set the town on top, and then have the town pass in it's Citizen list whenever the government attempted to run it's collectTaxes. However the problem with that is that it is then decided when it does so from the Town, which doesn't seem right. Does anyone have thoughts or considerations as to what I might be doing right/wrong with this model?

Regards,

WigglesMcMuffin

##### Share on other sites
Since the AI will be the hardest thing, I would start with a basic prototype of the game rules where the entire world's state can be duplicated and simulated. I would have a counter for each type of citizen so that the AI can simulate the game rules much faster when trying to predict the results of different actions. The game will not run fast enough to evolve an arbitrary neural net from scratch but you might be able to use the monte carlo method.

##### Share on other sites

A Town has a Government and a list of Citizens. The government class has a Tax_Citizens(list_of_citizens) method, and the list can be provided by the Town. It follows the object metaphor for how towns actually operate, anyway. The government of a town can be swapped out for another one, but the citizens (unless they move) are always members of that town, regardless of government.

As far as making the Town responsible for government functions, why not just design an interface where every Town has a RunGovernment() method that calls it's local government's run function, where you can define whether it's currently time to tax citizens and any other gov't-specific parameters. Then, when the gov't changes, the new one also has a run function that will handle things according to the new regime's standards. All the Town is saying is "okay, gov't, do your thing at your own pace".

Snippet:
 class Town{ public: Government current_govt; List<Citizen> citizens; public void RunGovernment(){ //gets called once per frame current_govt.run(); //has internal time checks to perform functions at its own rate } }; 

##### Share on other sites

A Town has a Government and a list of Citizens. The government class has a Tax_Citizens(list_of_citizens) method, and the list can be provided by the Town. It follows the object metaphor for how towns actually operate, anyway. The government of a town can be swapped out for another one, but the citizens (unless they move) are always members of that town, regardless of government.

As far as making the Town responsible for government functions, why not just design an interface where every Town has a RunGovernment() method that calls it's local government's run function, where you can define whether it's currently time to tax citizens and any other gov't-specific parameters. Then, when the gov't changes, the new one also has a run function that will handle things according to the new regime's standards. All the Town is saying is "okay, gov't, do your thing at your own pace".

Snippet:
 class Town{ public: Government current_govt; List<Citizen> citizens; public void RunGovernment(){ //gets called once per frame current_govt.run(); //has internal time checks to perform functions at its own rate } }; 

Perfect! That's what I was thinking I might end up doing, I just didn't know if it'd be better to house the Government at the top, so it would be able to call it's own functions when it wanted/needed. Thank you.

Since the AI will be the hardest thing, I would start with a basic prototype of the game rules where the entire world's state can be duplicated and simulated. I would have a counter for each type of citizen so that the AI can simulate the game rules much faster when trying to predict the results of different actions. The game will not run fast enough to evolve an arbitrary neural net from scratch but you might be able to use the monte carlo method.

I've been looking into Neural Networking in general on account of your suggestion. I think it'll be really useful, once I wrap my head around it enough. Thanks for the tip.

1. 1
2. 2
3. 3
4. 4
frob
13
5. 5

• 16
• 13
• 20
• 12
• 19
• ### Forum Statistics

• Total Topics
632169
• Total Posts
3004545

×

## Important Information

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!