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.action import *
from agame.item import Item from agame.item import Item
from agame.room import Room from agame.room import Room
@@ -6,6 +7,39 @@ from . import database
LINEBREAK = "=" * 70 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 # Prelude
################################################################################ ################################################################################
@@ -265,18 +299,7 @@ database.add_items(
Item( Item(
id="cabin_outside_west_path", id="cabin_outside_west_path",
name="Western path", name="Western path",
synonyms=( synonyms=create_path_synonyms("west"),
"path",
"path to west",
"path to the west",
"path leading west",
"path leading westward",
"west",
"westward",
"westward path",
"west path",
"western path",
),
room_desc=( room_desc=(
"A path leads westward, where the sky loses its color and becomes a dark gray. " "A path leads westward, where the sky loses its color and becomes a dark gray. "
"The land becomes more barren in this direction." "The land becomes more barren in this direction."
@@ -290,8 +313,8 @@ database.add_items(
"former self." "former self."
) )
], ],
GO: [PrintAction("You head west."), TeleportAction("western_fork")], GO: [PrintAction("You head west."), TeleportAction("west_fork")],
USE: [PrintAction("You head west."), TeleportAction("western_fork")], USE: [PrintAction("You head west."), TeleportAction("west_fork")],
}, },
), ),
Item( Item(
@@ -371,28 +394,45 @@ database.add_rooms(
database.add_items( database.add_items(
Item( Item(
id="eastern_path", id="west_fork_east_path",
name="Eastern path", name="Eastern path",
room_desc="A path that leads eastward. Your cabin lies in this direction.", room_desc="There is a path that leads eastward. Your cabin lies in this direction.",
synonyms=( synonyms=create_path_synonyms("east"),
"path to east", triggers={
"path to the east", GO: [
"path leading east", PrintAction("You head east."),
"path leading eastward", TeleportAction("cabin_outside"),
"east", ],
"eastward", USE: [
"eastward path", PrintAction("You head east."),
"east path", TeleportAction("cabin_outside"),
"eastern path", ],
), },
) ),
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( database.add_rooms(
Room( Room(
id="western_fork", id="west_fork",
name="Western fork", name="West fork",
desc="((This is currently the end of the game.)) Thanks for playing!", desc="A fork in the path.",
items=[], 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(),
],
) )
) )