• Advertisement
Sign in to follow this  

Strategy Game: Communication between code layers

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

What is a good, standard way for the game to respond to actions taken by the player through any particular class?

For instance, in my current project a city can create an army with a few variables set by the player. Right now I have it set up as the City class actually creates the Army object, but passes it to the Game Controller for all the other work (placing it in the army lists for instance). In order to do this I have to have an appropriate function in the Game Controller and pass it to the City object when created (coding in Python). Similarly, I would have to make and pass functions for armies attacking, for trade caravans arriving... Is this overly clunky?

I'm doing my best to enforce seperation and modularity in my code (it being a hobby/learning project, I anticipate ripping it up and rewriting often), and thus I want to keep communication between code layers and objects (game map, playing objects, game controller, etc) as standardized as possible, so I'm looking for a paradigm that can be generalized across the entire project.

Share this post


Link to post
Share on other sites
Advertisement
I have no experience with Python so this may or may not be useful:

If you're creating an object in class A and immediately passing it to class B, why not simply have some interface from B to A to create said object? For example, in your situation, Game Controller clearly takes responsibility for the managing of your Army immediately after creation. It seems reasonable that Game Controller should be able to create armies (or traders, or whatever else it controls) either directly or indirectly via some game object factory.

This doesn't really break a dependency between City and Game Controller. The dependency does get inverted, however, which seems more natural to me. After all, is a city not a game object to be controlled more or less like an army?

Share this post


Link to post
Share on other sites
[quote name='greenvertex' timestamp='1349808061' post='4988428'] After all, is a city not a game object to be controlled more or less like an army?[/quote]

Yep, and because of the way Python treats objects and functions it is relatively simple to do the "work" from anywhere in the code. This may be a case of me thinking too much like an OO C++ programmer and not enough like a Python Programmer (or perhaps overthinking the thing entirely). I suppose it is just a case of "pick a method and stick with it."

I'm now considering binding the create_Army() function in the city (triggered by the player actions) to a create_Army() function in the Game Controller, which just uses the calling object's (city's) variables to act appropriately.

I love Python, but it is capable of such different things than C++ that it can be hard to adapt.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement