I'm writing the core logic of Pokemon Gen I in Java (8), and I am struggling to figure out the best way to implement the turn-based aspect of the game. Right now I have a
Battle class which has two
Players each with a
The idea is that one
Player takes a
Battle has many
Turns), and some action happens, e.g. attack with a
Pokemon, use an
Pokemon, etc. Then, once that single action is taken, it needs to be applied during that turn, and then the other player gets to take their turn.
My original design, which has changed very slightly, looks something like this:
I was planning on implementing an
ActionResult superclass, with subclasses for each of the action types (e.g.
AttackActionResult). But that seems like it would be a bit confusing to use, and responsibility of applying damage, effects, handling Pokemon fainting, etc. all gets stuffed into those subclasses, which seems like a bad idea.
Then I stumbled across the command pattern which seems to fit the bill - "a behavioral design pattern in which an object is used to encapsulate all information needed to perform an action or trigger an event at a later time". Assuming good use of the pattern, I could have good delegation of applying actions, handling results, updating the battle state, etc. without turning classes into God classes.
Is the command pattern a good fit for a turn-based game like Pokemon, or is there something more appropriate?