Create nice utility function for the example game

It generates a bunch of variants for "western", "eastern", etc path
directions.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2021-11-20 15:07:18 -08:00
parent dc47b228f0
commit 4cf3608f71

View File

@@ -1,3 +1,4 @@
from typing import Sequence
from agame.action import *
from agame.item import Item
from agame.room import Room
@@ -6,6 +7,39 @@ from . import database
LINEBREAK = "=" * 70
################################################################################
# Utility functions
################################################################################
def create_path_synonyms(direction: str) -> Sequence[str]:
return (
f"path to {direction}",
f"path to the {direction}",
f"path leading {direction}",
f"path leading {direction}ward",
f"{direction}",
f"{direction}ward",
f"{direction}ward path",
f"{direction} path",
f"{direction}ern path",
)
################################################################################
# Utility items
################################################################################
database.add_items(
Item(
id="ambiguous_path",
name="path",
room_desc=None,
triggers={
LOOK: [PrintAction("Which path?")],
USE: [PrintAction("Which path?")],
GO: [PrintAction("Which path?")],
},
),
)
################################################################################
# Prelude
################################################################################
@@ -265,18 +299,7 @@ database.add_items(
Item(
id="cabin_outside_west_path",
name="Western path",
synonyms=(
"path",
"path to west",
"path to the west",
"path leading west",
"path leading westward",
"west",
"westward",
"westward path",
"west path",
"western path",
),
synonyms=create_path_synonyms("west"),
room_desc=(
"A path leads westward, where the sky loses its color and becomes a dark gray. "
"The land becomes more barren in this direction."
@@ -290,8 +313,8 @@ database.add_items(
"former self."
)
],
GO: [PrintAction("You head west."), TeleportAction("western_fork")],
USE: [PrintAction("You head west."), TeleportAction("western_fork")],
GO: [PrintAction("You head west."), TeleportAction("west_fork")],
USE: [PrintAction("You head west."), TeleportAction("west_fork")],
},
),
Item(
@@ -371,28 +394,45 @@ database.add_rooms(
database.add_items(
Item(
id="eastern_path",
id="west_fork_east_path",
name="Eastern path",
room_desc="A path that leads eastward. Your cabin lies in this direction.",
synonyms=(
"path to east",
"path to the east",
"path leading east",
"path leading eastward",
"east",
"eastward",
"eastward path",
"east path",
"eastern path",
room_desc="There is a path that leads eastward. Your cabin lies in this direction.",
synonyms=create_path_synonyms("east"),
triggers={
GO: [
PrintAction("You head east."),
TeleportAction("cabin_outside"),
],
USE: [
PrintAction("You head east."),
TeleportAction("cabin_outside"),
],
},
),
Item(
id="west_fork_south_path",
name="Southern path",
room_desc="There is a path that leads southward. The mountains lie in this direction.",
synonyms=create_path_synonyms("south"),
),
Item(
id="west_fork_west_path",
name="Western path",
room_desc="There is a path that leads westward. A desolate wasteland lies in this direction.",
synonyms=create_path_synonyms("west"),
),
)
)
database.add_rooms(
Room(
id="western_fork",
name="Western fork",
desc="((This is currently the end of the game.)) Thanks for playing!",
items=[],
id="west_fork",
name="West fork",
desc="A fork in the path.",
items=[
database.items["west_fork_east_path"].create_inst(),
database.items["west_fork_west_path"].create_inst(),
database.items["west_fork_south_path"].create_inst(),
database.items["ambiguous_path"].create_inst(),
],
)
)