Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Strategy Game: Communication between code layers


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Telcontar   Members   -  Reputation: 906

Like
2Likes
Like

Posted 08 October 2012 - 10:50 AM

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.

I Create Games to Help Tell Stories | Writing Blog


Sponsor:

#2 greenvertex   Members   -  Reputation: 510

Like
0Likes
Like

Posted 09 October 2012 - 12:41 PM

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?

#3 Telcontar   Members   -  Reputation: 906

Like
0Likes
Like

Posted 10 October 2012 - 09:44 AM

After all, is a city not a game object to be controlled more or less like an army?


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.

I Create Games to Help Tell Stories | Writing Blog





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS