Jump to content

Pattern suggestions for game battles


genericnumber1

Recommended Posts

I'm making a game and for the battle sequence I need to be able to have completely different targeting for each ability. For example one ability may target one enemy, while a different ability may target all the enemies and one ally.

 

I was thinking of using an ajax request when the ability was selected to decide the available targets, but after the targets are selected and submitted I'm curious of the best way of handling that information.

 

The best thing I could come up with is slightly (and I use that term quite strongly) like the command pattern, where the submitted information is in array form and the array is passed to an information holding class specific to the certain ability, then that class is passed to the ability's class for use in the damage calculations etc...

 

Let me try to pseudo it so it's more clear... (these ability names are of course made up, for fun's sake)

 

Certain abilities are with certain units, but I'm just going to pseudo it as one player that wants to use the ability "throw muffin" (which does damage to two enemies).

 

 

Player selects ability "Throw Muffin"

  • An ajax request is sent to a page with the ability name, and the script replies with available targets (in this case, 2 enemies)
  • The player selects two enemy targets and submits the information in an array, something like

      $ability('name' => 'ThrowMuffin', 'target1' => 'enemy1', 'target2' => 'enemy2')

 

The script receives the ability request

  • The script creates a new class instance of $ability['name'] . 'Info' (ThrowMuffinInfo) and passes it the submitted array
  • "ThrowMuffinInfo" receives the information and assigns it to it's own instance variables, etc, whatever it needs to do to prepare the information to be used by the ability
  • The script passes the instance of the "ThrowMuffinInfo" class to a new "ThrowMuffinAbility" class
  • "ThrowMuffinAbility" does whatever it needs to with the "ThrowMuffinInfo" via an activate() method, or something similar.

 

 

Of course there will be security features and checks to see if the abilities are available, if the info is correct etc... I just didn't see a need to mention that.

 

Unfortunately there are many limitations to doing the script in this way, and I'm curious if anyone can think of a pattern that fits this situation quite easily? Or perhaps a different approach to the problem?

 

I appreciate any suggestions you can give!

Link to comment
Share on other sites

you need to make the abilities instances of an ability that will extend from an abstract ability each ability will be able to hold one target each and the player should be able to use as many abilities whenever they want it should be the responsibility of these objects to accept\deny the request. Also make the abilities modify the stats of the player so other abilities know when to deny their use.

 

Also do not send target1=enemy one do something like targets=one+two+three and explode("+", $_GET['targets']); to get an array of targets then just run them through a loop and validate the data before throwing muffins at the targets

 

I think you have the wrong idea about patterns, but thats a rant for another time.

 

 

Link to comment
Share on other sites

"you need to make the abilities instances of an ability that will extend from an abstract ability each ability will be able to hold one target each and the player should be able to use as many abilities whenever they want it should be the responsibility of these objects to accept\deny the request."

 

Mhm, that's what was planned... I wasn't going to give you a whole UML class model though, that'd just be overkill... I was more wondering what would be better logic decisions.

 

-

"Also make the abilities modify the stats of the player so other abilities know when to deny their use."

 

Could you elaborate on that? The abilities will do something like deplete a "mana" of sorts, if that's what you're saying.

 

-

"Also do not send target1=enemy one do something like targets=one+two+three and explode("+", $_GET['targets']); to get an array of targets then just run them through a loop and validate the data before throwing muffins at the targets"

 

The problem with this is I was planning on doing html selects for targets, and as far as I'm aware it's not possible to turn 3 selects into one submit without combining the strings with javascript before sending. This is why I was going to leave it up to the info classes to parse the information, please correct me if I'm wrong.

 

-

"I think you have the wrong idea about patterns, but thats a rant for another time."

 

Feel free to correct me! Though I don't know what you mean by the wrong idea, before you go on a huge rant try to touch base with me on what you think my idea is :P

 

I hate to feel like I disagree with everything after I ask for help, could you try to be more specific as I'm sure you had points that I missed.

Link to comment
Share on other sites

I wasn't going to give you a whole UML class model though, that'd just be overkill... I was more wondering what would be better logic decisions.

 

And what better way to show us your thoughts than with a class diagram? It is stil early, I am drinking my first cup of coffee, I really do not feel like reading and visualising that big chunk of text you posted.

 

So if you know how to do class diagrams, or even have some code to reverse engineer, save us the trouble of trying to visualize what you are trying to do (and possibly misunderstand). That is why UML exists: to communicate application structures.

 

Maybe then we can see your problem and suggest a fit solution, known pattern or other.

Link to comment
Share on other sites

Hopefully the class diagram will communicate it better then, it's understandable it's hard to picture, especially in the morning. I just hope I didn't botch the UML or the model too much... cut me some slack, it's late ;)

 

battle() is the page that displays the battle form, etc... pretty much where the battle takes place.

 

Feel free to ask questions about what isn't clear! as I'm sure there will be some...

 

Diagram.jpg

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.