Attack!!!
Refactor MovePlayerAction into a few different Action subclasses. Move direction to a parent MoveAction, and create three new subclasses of MoveAction: - BumpAction: perform the test that an action can be performed in the given direction - WalkAction, take a step in the given direction - MeleeAction, attack another Entity in the given direction Add an ActionResult class that communicates the result of performing an Action. - ActionResult.succeeded indicates whether the action succeeded. - ActionResult.done indicates if the action is fully complete or requires followup. - ActionResult.alternate specifies the follow-up action to perform. Convert all the key handling actions to BumpActions. In the Engine's event handler method, loop until an action is completed, performing specified alternate actions until the result object indicates the action is done.
This commit is contained in:
parent
57bbb2c3fc
commit
4002b64640
4 changed files with 153 additions and 36 deletions
|
@ -66,7 +66,26 @@ class Engine:
|
|||
if not action:
|
||||
return
|
||||
|
||||
action.perform(self, self.hero)
|
||||
result = action.perform(self, self.hero)
|
||||
LOG.debug('Performed action success=%s done=%s alternate=%s', result.success, result.done, result.alternate)
|
||||
|
||||
while not result.done:
|
||||
alternate = result.alternate
|
||||
assert alternate is not None, f'Action {result.action} incomplete but no alternate action given'
|
||||
|
||||
result = alternate.perform(self, self.hero)
|
||||
LOG.debug('Performed action success=%s done=%s alternate=%s', result.success, result.done, result.alternate)
|
||||
|
||||
if result.success:
|
||||
LOG.info('Action succeded!')
|
||||
break
|
||||
|
||||
if result.done:
|
||||
LOG.info('Action failed!')
|
||||
break
|
||||
|
||||
if not result.success and result.done:
|
||||
return
|
||||
|
||||
directions = list(Direction.all())
|
||||
moved_entities: MutableSet[Entity] = {self.hero}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue