1. Jason R. Coombs
  2. adventure


Brandon Rhodes  committed 15493c3

Gave "python -m adventure" a real argparse command line, that can take a
savefile filename to restore; previously there was no way for someone
using plain console mode to restore a saved game.

  • Participants
  • Parent commits 11edbb9
  • Branches default

Comments (0)

Files changed (1)

File adventure/__main__.py

View file
 """Offer Adventure at a custom command prompt."""
+import argparse
+import os
 import re
-from sys import stdout
+from sys import executable, stdout
 from time import sleep
 from . import load_advent_dat
 from .game import Game
 def loop():
-    game = Game()
-    load_advent_dat(game)
-    game.start()
-    baudout(game.output)
+    parser = argparse.ArgumentParser(
+        description='Adventure into the Colossal Caves.',
+        prog='{} -m adventure'.format(os.path.basename(executable)))
+    parser.add_argument(
+        'savefile', nargs='?', help='The filename of game you have saved.')
+    args = parser.parse_args()
+    if args.savefile is None:
+        game = Game()
+        load_advent_dat(game)
+        game.start()
+        baudout(game.output)
+    else:
+        game = Game.resume(args.savefile)
+        baudout('GAME RESTORED\n')
     while not game.is_finished:
         line = input('> ')