Pattern for multiple States



Hi, I posted my questions to comp.patterns, but seeing that the recent posts seem to be spam, I wanted to try posting here. I hope this is not off topic, but I rally would like to discuss this.

I've been reading up on Design patterns from
various sources, including the GoF as well as some web sites and I'm
not sure at all which ones best fit my scenario. I am confused about how to handle multiple States that can be active at the same time. Maybe I'm making this more complicated that it really is, but I want to understand the patterns and how they work.

I'll use an example of a game entity to explain my scenario.
Suppose I have a Creature class. I create a
State called Roam so that a creature object can move around aimlessly. Now suppose the creature becomes Poisoned. The
poison will continue to alter the behavior of the creature over time. So I create a State called Poisoned. I am confused about how to handle
these two states concurrently, because the creature can still Roam while Poisoned. Even more complicated is the fact that eventually the creature could move into a Hunting State. So then it would be Hunting while Poisoned. How is this kind of scenario usually handled? Should Poisoned be a unique State? Or maybe Poisoned falls under a completely different design pattern? Maybe Decorator, or Flyweight, Or could I have nested States? Should my creature class have multiple State pointers to handle these States? Or should I create a RoamWhilePoisoned State and a
HuntingWhilePoisoned State? Or would Poisoned merely be a boolean
property of each State class? I'm really not sure how to proceed.

The more I think about it, the more I am leaning towards a linked-list style of pattern for my States (Decorator?), where each state contains a pointer to the next state. Adding a new state means it gets added to the pointer in the last State in the list. Calling State->Execute() would then run it's own logic and then call nextState->Execute(). Transitions would be tricky, I would have to un-link the state being removed, and link in the new state.

Would that be the way to do it? What are the pros and cons of doing it this way? Is this an actual pattern as defined by the GoF or is this really a combination of patterns?

Thanks,

Jim
.



Relevant Pages

  • Pattern for handlng multiple concurrent States
    ... Maybe I'm making this more complicated that it really is, but I want to understand the patterns and how they work. ... State called Roam so that a creature object can move around aimlessly. ... poison will continue to alter the behavior of the creature over time. ... Is this an actual pattern as defined by the GoF or is this really a combination of patterns? ...
    (comp.software.patterns)
  • Re: Pattern for multiple States
    ... Suppose I have a Creature class. ... The poison will continue to alter the ... completely different design pattern? ... each with its own effect on the creatures behavior, multiple drugs have ...
    (comp.object)
  • Re: Thomas Covenant series
    ... fundamental to life itself. ... This is poison, this is not. ... Many of the patterns we made would ... Facts are important, yes, but remembering bazillions of facts and ...
    (rec.arts.sf.composition)
  • Re: Thomas Covenant series
    ... fundamental to life itself. ... This is poison, this is not. ... Many of the patterns we made would ... Facts are important, yes, but remembering bazillions of facts and ...
    (rec.arts.sf.composition)
  • Re: Pattern for multiple States
    ... Suppose I have a Creature class. ... The poison will continue to alter the ... creature could move into a Hunting State. ...
    (comp.object)