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 <alekratz@gmail.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user