| 1 |
"""The Adventure game. |
| 2 |
|
| 3 |
Copyright 2010-2015 Brandon Rhodes. Licensed as free software under the |
| 4 |
Apache License, Version 2.0 as detailed in the accompanying README.txt. |
| 5 |
|
| 6 |
""" |
| 7 |
import sys |
| 8 |
|
| 9 |
if sys.version_info <= (3,): |
| 10 |
raise RuntimeError('Alas, Adventure requires Python 3 or later') |
| 11 |
|
| 12 |
def load_advent_dat(data): |
| 13 |
import os |
| 14 |
from .data import parse |
| 15 |
|
| 16 |
datapath = os.path.join(os.path.dirname(__file__), 'advent.dat') |
| 17 |
with open(datapath, 'r', encoding='ascii') as datafile: |
| 18 |
parse(data, datafile) |
| 19 |
|
| 20 |
def play(seed=None): |
| 21 |
"""Turn the Python prompt into an Adventure game. |
| 22 |
|
| 23 |
With optional the `seed` argument the caller can supply an integer |
| 24 |
to start the Python random number generator at a known state. |
| 25 |
|
| 26 |
""" |
| 27 |
global _game |
| 28 |
|
| 29 |
from .game import Game |
| 30 |
from .prompt import install_words |
| 31 |
|
| 32 |
_game = Game(seed) |
| 33 |
load_advent_dat(_game) |
| 34 |
install_words(_game) |
| 35 |
_game.start() |
| 36 |
print(_game.output[:-1]) |
| 37 |
|
| 38 |
def resume(savefile, quiet=False): |
| 39 |
global _game |
| 40 |
|
| 41 |
from .game import Game |
| 42 |
from .prompt import install_words |
| 43 |
|
| 44 |
_game = Game.resume(savefile) |
| 45 |
install_words(_game) |
| 46 |
if not quiet: |
| 47 |
print('GAME RESTORED\n') |