2021-11-18 12:15:35 -08:00
|
|
|
import argparse
|
|
|
|
|
import importlib.util
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
import sys
|
2021-11-18 20:32:02 -08:00
|
|
|
from agame.color import colorize
|
2021-11-18 11:31:21 -08:00
|
|
|
|
|
|
|
|
|
2021-11-18 12:15:35 -08:00
|
|
|
# Parse args
|
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
|
description="Run a game",
|
2021-11-18 11:31:21 -08:00
|
|
|
)
|
2021-11-18 12:15:35 -08:00
|
|
|
parser.add_argument(
|
|
|
|
|
"PACKAGE", type=str, help="The Python package that contains the game to run."
|
2021-11-18 11:31:21 -08:00
|
|
|
)
|
2021-11-18 12:15:35 -08:00
|
|
|
args = parser.parse_args()
|
2021-11-18 11:31:21 -08:00
|
|
|
|
2021-11-18 12:15:35 -08:00
|
|
|
# Get package to run
|
|
|
|
|
package = args.PACKAGE
|
|
|
|
|
|
|
|
|
|
# Load game module
|
|
|
|
|
game_module = importlib.import_module(package)
|
|
|
|
|
game = game_module.game # type: ignore
|
2021-11-18 11:31:21 -08:00
|
|
|
|
2021-11-18 12:15:35 -08:00
|
|
|
# Run
|
2021-11-18 20:32:02 -08:00
|
|
|
game.say("=" * 70)
|
|
|
|
|
game.say("Type ((help)) for help, or ((quit)) to exit.")
|
|
|
|
|
game.say("=" * 70)
|
|
|
|
|
game.say()
|
|
|
|
|
|
|
|
|
|
game.do_teleport_actions()
|
2021-11-18 11:31:21 -08:00
|
|
|
while True:
|
|
|
|
|
try:
|
|
|
|
|
game.say()
|
2021-11-18 20:32:02 -08:00
|
|
|
line = input(colorize("{{>}} "))
|
|
|
|
|
if line.lower() == "quit":
|
|
|
|
|
break
|
2021-11-18 11:31:21 -08:00
|
|
|
game.say()
|
|
|
|
|
game.run_command(line)
|
|
|
|
|
except (KeyboardInterrupt, EOFError):
|
|
|
|
|
break
|
2021-11-18 18:10:58 -08:00
|
|
|
|
|
|
|
|
game.say()
|
|
|
|
|
game.say("Bye.")
|