Commit 7f7cb837 authored by Joe Libipl's avatar Joe Libipl
Browse files

Simple selections.

parent afc1958e
Pipeline #9994315 passed with stage
in 1 minute and 24 seconds
......@@ -27,6 +27,17 @@ class SMSBeholder < Sinatra::Base
state = params['SkipToState']
elsif $game_states[state].key?('selection')
# handle using the input to choose selection
if (index = body.to_i) != 0
selections = $game_states[state]['selection'].to_a
if selections.length >= index
state = selections[index-1].last
else
puts "selections.length #{selections.length} index #{index}"
puts "Player selected #{body} but selections are #{selections}"
end
else
puts "Player game non-numeric selection: #{body}"
end
elsif $game_states[state].key?('next')
state = $game_states[state]['next']
else
......@@ -42,7 +53,8 @@ class SMSBeholder < Sinatra::Base
def process_output(player)
state = player['state']
response = String.new($game_states[state]['story'])
response = ''
response += String.new($game_states[state]['story']) if $game_states[state].key?('story')
# Present selections
if $game_states[state].key?('selection')
......
require 'spec_helper'
require 'rack/test'
require 'timeout'
require_relative '../sms_beholder.rb'
describe SMSBeholder do
......@@ -60,5 +61,39 @@ describe SMSBeholder do
expect(last_response.body).to include("what is the solution?\n1) Six\n2) Sixteen\n3) I wasn't paying attention")
end
it 'respects selections from player' do
get '/', From: 'Dude8', SkipToState: 'D1S108'
get '/', From: 'Dude8', Body: '1'
expect(last_response.body).to include('Wrong. You haven\'t been paying attention, have you?')
end
it 'rejects non-numeric selections from player' do
get '/', From: 'Dude9', SkipToState: 'D1S108'
get '/', From: 'Dude9', Body: 'Dan'
expect(last_response.body).to include("what is the solution?\n1) Six\n2) Sixteen\n3) I wasn't paying attention")
end
it 'rejects invalid selections from player' do
get '/', From: 'Dude', SkipToState: 'D1S108'
get '/', From: 'Dude', Body: '4'
expect(last_response.body).to include("what is the solution?\n1) Six\n2) Sixteen\n3) I wasn't paying attention")
end
# it 'can be played all the way through' do
# get '/', From: 'Dude'
# Timeout::timeout(10) do
# until last_response.body.include?('And you won\'t be alone...') ||
# last_response.body.include?('Royalty does not concern itself with common dances.') ||
# last_response.body.include?('True power is slow dancing with someone who could beat you senseless.') ||
# last_response.body.include?('Thirst for knowledge. Hunger for power. No feast is fine enough.') do
# get '/', From: 'Dude', Body: ['1','2','3'].sample
# puts last_response.body
# end
# end
# end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment