From d3bf9e68dd04363cda07ae08fe3d0b00bce9c035 Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Thu, 18 Nov 2021 17:23:14 -0800 Subject: [PATCH] Add PrintRoomAction and TeleportAction.announce field * PrintRoomAction will print a small header and then the room's text. * TeleportAction now has an announce field (true by default) that will print the room's text after moving the player there. Signed-off-by: Alek Ratzloff --- agame/action.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/agame/action.py b/agame/action.py index 5a4ca99..80b8619 100644 --- a/agame/action.py +++ b/agame/action.py @@ -12,6 +12,7 @@ __all__ = ( "SleepAction", "PrintAction", "TeleportAction", + "PrintRoomAction", "GetAction", "CheckInvItemsAction", "CheckRoomItemsAction", @@ -78,13 +79,31 @@ class TeleportAction(Action): Moves the player to another room. """ + # The room ID to teleport to. room_id: str + # Whether to "announce" the teleportation; i.e., print out the room + # description after teleporting to it. + announce: bool = True + def act(self, game: "Game"): assert ( self.room_id in game.database.rooms ), f"could not find room with id {self.room_id}" game.room = game.database.rooms[self.room_id] + if self.announce: + game.say("", "." * 70, "") + game.print_room() + + +class PrintRoomAction(Action): + """ + Prints the current room. + """ + + def act(self, game: "Game"): + game.say("", "." * 70, "") + game.print_room() @dataclasses.dataclass