Files
ages/agame/__main__.py

57 lines
1.2 KiB
Python
Raw Normal View History

import argparse
import importlib.util
from pathlib import Path
import sys
from agame.color import colorize
from agame.display import ANSIDisplay
from agame.game import Game
# Parse args
parser = argparse.ArgumentParser(
description="Run a game",
)
parser.add_argument(
"PACKAGE", type=str, help="The Python package that contains the game to run."
)
args = parser.parse_args()
# Get package to run
package = args.PACKAGE
# Load game module
game_module = importlib.import_module(package)
database = game_module.database # type: ignore
start_room = game_module.start_room # type: ignore
# Build the game state
game = Game(
display=ANSIDisplay(),
database=database,
room=database.rooms["prelude"],
)
try:
# Run
game.say("=" * 70)
game.say("Type ((help)) for help, or ((quit)) to exit.")
game.say("=" * 70)
game.say()
game.do_teleport_actions()
while True:
game.say()
line = game.display.input()
if line.lower() == "quit":
break
game.say()
game.run_command(line)
except (KeyboardInterrupt, EOFError):
# no-op, these are expected events
pass
finally:
game.display.finish()
game.say()
game.say("Bye.")