This commit is contained in:
Shivan Sivakumaran 2021-10-05 21:58:05 +13:00
commit 944e38ccb3
2 changed files with 7232 additions and 0 deletions

37
main.py Normal file
View File

@ -0,0 +1,37 @@
import json
from rich import print
# dictionary of the rooms
with open("zork1.rooms.json") as fp:
rooms = {room["Name"]: room for room in json.load(fp)}
# game starts here
current_room = rooms["WEST-OF-HOUSE"]
while True:
# game loop
print("")
print(
"[bold magenta]"
+ "".join(current_room["Properties"]["DESC"])
+ "[/bold magenta]"
)
current_room_props = current_room["Properties"]
print("".join(current_room_props.get("LDESC", "")))
print(", ".join(current_room["Exits"].keys()))
while True:
# user input
direction = input("Enter direction (see above): ").upper().strip()
if direction in current_room["Exits"]:
# NEXIT, UEXIT, CEXIT, BREXIT
exit = current_room["Exits"][direction]
exit_type = exit["TYPE"]
if exit_type == "NEXIT":
print(exit["MESSAGE"])
elif exit_type in ["UEXIT", "CEXIT", "DEXIT"]:
current_room = rooms[current_room["Exits"][direction]["TO"]]
break
else:
print("You can't do that!\n")

7195
zork1.rooms.json Normal file

File diff suppressed because it is too large Load Diff