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:
Eryn Wells 2022-05-07 11:16:17 -07:00
parent 57bbb2c3fc
commit 4002b64640
4 changed files with 153 additions and 36 deletions

View file

@ -2,7 +2,7 @@
# Eryn Wells <eryn@erynwells.me>
import tcod
from .actions import Action, ExitAction, MovePlayerAction, RegenerateRoomsAction
from .actions import Action, ExitAction, RegenerateRoomsAction, BumpAction
from .geometry import Direction
from typing import Optional
@ -16,21 +16,21 @@ class EventHandler(tcod.event.EventDispatch[Action]):
sym = event.sym
if sym == tcod.event.KeySym.b:
action = MovePlayerAction(Direction.SouthWest)
action = BumpAction(Direction.SouthWest)
elif sym == tcod.event.KeySym.h:
action = MovePlayerAction(Direction.West)
action = BumpAction(Direction.West)
elif sym == tcod.event.KeySym.j:
action = MovePlayerAction(Direction.South)
action = BumpAction(Direction.South)
elif sym == tcod.event.KeySym.k:
action = MovePlayerAction(Direction.North)
action = BumpAction(Direction.North)
elif sym == tcod.event.KeySym.l:
action = MovePlayerAction(Direction.East)
action = BumpAction(Direction.East)
elif sym == tcod.event.KeySym.n:
action = MovePlayerAction(Direction.SouthEast)
action = BumpAction(Direction.SouthEast)
elif sym == tcod.event.KeySym.u:
action = MovePlayerAction(Direction.NorthEast)
action = BumpAction(Direction.NorthEast)
elif sym == tcod.event.KeySym.y:
action = MovePlayerAction(Direction.NorthWest)
action = BumpAction(Direction.NorthWest)
elif sym == tcod.event.KeySym.SPACE:
action = RegenerateRoomsAction()