__init__.py 1.0 KB

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