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",
|
"SleepAction",
|
||||||
"PrintAction",
|
"PrintAction",
|
||||||
"TeleportAction",
|
"TeleportAction",
|
||||||
|
"PrintRoomAction",
|
||||||
"GetAction",
|
"GetAction",
|
||||||
"CheckInvItemsAction",
|
"CheckInvItemsAction",
|
||||||
"CheckRoomItemsAction",
|
"CheckRoomItemsAction",
|
||||||
@@ -78,13 +79,31 @@ class TeleportAction(Action):
|
|||||||
Moves the player to another room.
|
Moves the player to another room.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# The room ID to teleport to.
|
||||||
room_id: str
|
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"):
|
def act(self, game: "Game"):
|
||||||
assert (
|
assert (
|
||||||
self.room_id in game.database.rooms
|
self.room_id in game.database.rooms
|
||||||
), f"could not find room with id {self.room_id}"
|
), f"could not find room with id {self.room_id}"
|
||||||
game.room = game.database.rooms[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
|
@dataclasses.dataclass
|
||||||
|
|||||||
Reference in New Issue
Block a user