Exemplo n.º 1
0
def play_game():

  print 'picking up'
  print session.get('state')
  # pick up wherever we left off
  adventure = AdventureMachine(state=session.get('state'))
  from_number = request.form.get('From')
  choice = request.form.get('Body', '').lower()

  adventure.on_transition = lambda x,y: twilio_output(from_number, y)

  # As the user progresses save their state
  def save_state(state):
    print 'changing state'
    print state
    session['state'] = state
  adventure.on_state_change = save_state

  if not choice or not len(adventure._states):
    adventure.play()
  else:
    try:
      adventure.transition_to(choice)
    except:
      twilio_output(from_number, 'Not a valid choice')
  return ''
Exemplo n.º 2
0
import sys

from adventure import Adventure as AdventureMachine

if __name__ == '__main__':
  adventure = AdventureMachine()

  def print_output(from_result, to_result):
    print to_result
    input = raw_input("choose: ")
    # Wrapping around incorrect choices
    try:
      adventure.transition_to(input)
    except:
      print_output(None, "Not a valid choice")

  adventure.on_transition = print_output
  adventure.play()