Suggestion for a flex game communication between entities
I'm currently developing a Flex game which is a kind of table and cards game. Thinking about开发者_Go百科 developing other games using entities from this one, I chose for creating my entities decoupled from the game and even from other game entities. As a result, I'm currently using events for communication between my game entities.
Game entities, in my case, refers for example a player hand component which can receive a card, or send a card to another unknown component by a custom requesting and dealing events. For instance, the same can happens to a deck of cards holder component.
This approach appeared to be a good designer in the beginning, but after some time, my game controller class has a lot of event handler functions which started looking bad for me.
My current idea is to create a game event manager coupled with my game controller for handling events and cleaning the controllers code.
Finally, I'm not sure about my design decision exposed above, so I would like to know about you folks which communication design would be indicated for this kind of a game.
I hope this question answers can help others mind too. Thanks in advance.
Can you break it up into several controllers classes? In a tabbed application, I use a spearate controller for each tab. Breaking down your application into sensible pieces won't be as cut and dry, but very possible.
One suggesetion might be:
MainController - Handles the 'shell' of the game, such as application startup, menus, splash screens, etc...
GameController - Handle state changes and user based events like taking turns, checking for win conditions, updating scores, etc...
EntityController - Communication between your game entities (cards, decks, and hands?).
It's hard for me to make too many judgements with such little information about your game, but I hope you get the idea.
Also, if you want to cut down on boilerplate event handling code, I second the idea of using a framework. I've heard good things about robotlegs, and have personally used Swiz on a couple projects. Swiz has great, unobtrusive event mediation swizframework.org.
精彩评论