Update example game some, update engine some
* Add RevealAction/UnrevealAction for revealing/hiding items in a room * Add a lot of checks for items being revealed when it's attempted to be triggered * Implement TeleportAction (mostly) * For all Check* family of actions, the `yes` and `no` values may be just be a single action instead of an array of actions * Change up how room descriptions and stuff work, mostly so that you can specify multiple lines in an array so you can preserve paragraph breaks when displayed. * Example game has some more content Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -57,6 +57,7 @@ class Game:
|
||||
UseTrigger(),
|
||||
PutTrigger(),
|
||||
LookTrigger(),
|
||||
ReadTrigger(),
|
||||
OpenTrigger(),
|
||||
CloseTrigger(),
|
||||
GoTrigger(),
|
||||
@@ -83,24 +84,40 @@ class Game:
|
||||
|
||||
def print_room(self):
|
||||
"Prints this room's description."
|
||||
self.say(self.room.name)
|
||||
self.say()
|
||||
self.say(self.room.desc)
|
||||
self.say(f"(({self.room.name}))")
|
||||
if isinstance(self.room.desc, str):
|
||||
self.say(self.room.desc)
|
||||
else:
|
||||
assert isinstance(
|
||||
self.room.desc, Sequence
|
||||
), f"room.desc is not a list or a string from room id {room.id}"
|
||||
self.say(*self.room.desc)
|
||||
# Look at revealed text
|
||||
for item in self.room.items.values():
|
||||
if not item.revealed or item.room_desc is None:
|
||||
for (index, item) in enumerate(self.room.items.values()):
|
||||
if not item.revealed or item.room_desc is None or item.room_desc == []:
|
||||
continue
|
||||
if item.room_desc == "":
|
||||
# TODO - pluralization, 'a' vs 'an'
|
||||
self.say(f"You see a (({item.name})).")
|
||||
else:
|
||||
self.say(item.room_desc)
|
||||
|
||||
def say(self, message: Optional[str] = None):
|
||||
if index != 0:
|
||||
# Space this out with blank lines
|
||||
self.say()
|
||||
|
||||
if isinstance(item.room_desc, str):
|
||||
self.say(item.room_desc)
|
||||
else:
|
||||
assert isinstance(item.room_desc, Sequence)
|
||||
self.say(*item.room_desc)
|
||||
|
||||
def say(self, *lines: str):
|
||||
"Format, colorize, wrap, and print the message."
|
||||
message = message or ""
|
||||
message = textwrap.fill(message)
|
||||
print(colorize(message))
|
||||
if lines:
|
||||
head = textwrap.fill(lines[0])
|
||||
print(colorize(head))
|
||||
for line in lines[1:]:
|
||||
message = textwrap.fill(line)
|
||||
print()
|
||||
print(colorize(message))
|
||||
else:
|
||||
print()
|
||||
|
||||
@property
|
||||
def rooms(self):
|
||||
|
||||
Reference in New Issue
Block a user