Files
ages/agame/__main__.py

35 lines
681 B
Python
Raw Normal View History

import argparse
import importlib.util
from pathlib import Path
import sys
# 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.print_room()
while True:
try:
game.say()
line = input("> ")
game.say()
game.run_command(line)
except (KeyboardInterrupt, EOFError):
game.say()
game.say("Bye.")
break