kelciste.py 902 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import error
  2. from common import Directions
  3. from game import *
  4. import sys
  5. import graphics
  6. def game_loop():
  7. '''Reads user input, parses it and performs it'''
  8. gameState = game()
  9. print gameState
  10. while 1:
  11. graphics.graphicsloop(gameState)
  12. def up(gameState):
  13. gameState.move(Directions.UP)
  14. def down(gameState):
  15. gameState.move(Directions.DOWN)
  16. def left(gameState):
  17. gameState.move(Directions.LEFT)
  18. def right(gameState):
  19. gameState.move(Directions.RIGHT)
  20. def iact(gameState):
  21. gameState.interact()
  22. def errorCommand(gameState):
  23. print "Not a valid command!"
  24. def quit(gameState):
  25. print "End!"
  26. sys.exit()
  27. def parse_command(raw):
  28. if raw in command_lookup:
  29. return command_lookup[raw]
  30. else:
  31. return errorCommand
  32. command_lookup = {'w': up,
  33. 'a': left,
  34. 's': down,
  35. 'd': right,
  36. 'f': iact,
  37. 'q': quit}
  38. if __name__ == "__main__":
  39. print "Beginning!"
  40. game_loop()