36 lines
666 B
Python
36 lines
666 B
Python
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):
|
|
break
|
|
|
|
game.say()
|
|
game.say("Bye.")
|