1
\$\begingroup\$

I am writing a turn based rpg game, the fighting process is sent by server which can not change by player. The data of fighting process is an array of round info. Each round info contain what happens in this round in order such as unit A attack unit B.

When client get fighting process data, it needs play animation according to this data. I am try use "action sequence"(a concept in cocos2d, which put all actions in an array, so actions will be executed in their order in that array) to implement this, for example, I make a action let unit move to a point, add it to array, then make a action of target unit be attack, add it to array... after the sequence construct complete, run it. But I found generate the action sequence code is too complex and hard to maintain.

So I want ask is there better way to do this? I also consider add timer in each unit, but it seems hard to calculate the time point of each animation playing.

\$\endgroup\$
1
\$\begingroup\$

You could try to segment your work to make it easier to understand and manage. Like make a RoundAction interface that holds an action and then have a RoundData class that holds all your round actions .

then simply execute an action clientside and RoundData.add(new RoundAction(){unit b attack unit a}) and then have it put it in a list in the order that you want and send that baby through. and then have the receiving client decipher the data and play it out accordingly.

\$\endgroup\$
  • \$\begingroup\$ I think refactoring code doesn't help too much because for a complex requirement, the code is about 300 lines with high couple. The best way is moving each unit action into their own class, say, unit class. When the time come, unit just do things what it should do. But the difficult point is how to get these action execution time \$\endgroup\$ – jean Nov 19 '13 at 7:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.