Files
ages/agame/__main__.py

44 lines
882 B
Python
Raw Normal View History

import argparse
import importlib.util
from pathlib import Path
import sys
from agame.color import colorize
# 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)
game = game_module.game # type: ignore
# 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:
try:
game.say()
line = input(colorize("{{>}} "))
if line.lower() == "quit":
break
game.say()
game.run_command(line)
except (KeyboardInterrupt, EOFError):
break
game.say()
game.say("Bye.")