I originally asked this question on programmers.stackexchange.com, because I figured the answers would be too subjective for stackoverflow. However, in the comments Muad'Dib pointed this out:
this would probably be a better fit for StackOverflow ... This is a direct programming problem-related question and discusses programming solutions. One solution may be equal to another where the choice between them is subjective, but the discussion of the overall problem itself is not as some solutions are clearly not applicable. So this question does have one or a few good answers, whereas questions such as "Which is the best text editor?" does not...
So, after pondering the situation a little more (and looking at a few patterns that don't seem to fit), here is my dilemma:
The Set Up
I'm designing a simple combat strategy game.
- Two combatants attack each other for a certain amount of time.
- The winner is the one with the most health after the time is up.
- There is no direct intervention by the players during the fight. Players define some strategies for their combatant before the fight, and the "AI" (term used loosely) determines what the combatants will do.
- The fight consists of an arbitrary timer that "ticks" seconds, and a combatants' attack speed (among other things) determines how often they do something.
- Besides the combatant objects, there is also a "weather" object that can have some random environmental effects on the combatant's abilities.
- The whole thing just loops through each second, environmental effects and attacks are determined and executed, it's all logged, and the log is displayed to the user afterward as a play-by-play.
The Problem
I'm not sure what design pattern would best allow me to accomplish the above. I'm looking for a pattern that will allow me to increase the complexity of the "fight" down the road. Probably by adding more objects to the fight (more combatants, maybe a new environment object, etc.)
At first I thought the Observer pattern would work. I would have a fight object that represents the "observee/subject". It tracks a timer, and as the timer increments, it updates all of the participant observer objects. However, a lot of a defender combatants' parameters can affect actions of an attacker combatant, so the "observers" in that scenario need to be aware of each other, so I'm not sure if it's the right approach.
Finally, I'm not trying to nail a design pattern perfectly. Maybe there is no "best fit." I'm just looking for a solid base to build upon.