lundi 4 mai 2015

Choice of correct design pattern for spell-casting mechanism

I'm new in OOD and I don't really know how to handle the spell-casting mechanism which i want to implement in my game.

  • I want to produce following classesTeam, Actor, Spell and interface SpellEffect
  • Actor can cast spells on other actors however the spell can have different behaviour while being casted on allies and enemies ( ally is an actor from the same team )

I tried this way:

  • I implement SpellEffect in Damaging, Stunning, Healing classes which overrides executeOn(Actor a)
  • In Spell class I have two lists of SpellEffect - one for allies and second for enemies so in the Spell class I need to know is the attacked actor is and ally or enemy of the caster
  • I was thinking about StrategyPattern for spell so I can do something like this:

    actor.setCastingStrategy( new TargetingAllyStrategy() )
    
    
  • Strategies would be then something like:

    execute a spell on the targeted actor using `Spells`'s `allyCast()` method
    
    

However I'm not sure about passing Actor object to the lower level object. Moreover what if not every actor can be stunned? Should I make any inherited class UnstunnableActor ? Or maybe use instanceOf to check implemented interfaces. I'm pretty new in the topic so any help would be great.

Aucun commentaire:

Enregistrer un commentaire