Files
ages/agame/__main__.py
Alek Ratzloff c71077a8f3 Move colorization to the display layer
Color output isn't necessarily always going to be a terminal output
thing, and terminals don't always support the same escape codes (e.g. on
Windows). Thus, all colorization efforts are done in the Display rather
than in the Game.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2021-11-28 17:37:37 -08:00

57 lines
1.2 KiB
Python

import argparse
import importlib.util
from pathlib import Path
import sys
from agame.game import Game
# TODO - conditional import for this based on OS
from agame.display import ANSIDisplay
# 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[start_room],
)
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.say()
game.say("Bye.")
game.display.finish()