# Choose your own adventure: redux
#printing the prompt
#reading input from the console
#return the input
def prompt_and_chomp(prompt)
puts prompt
gets.chomp
end
#loop ensure that prompt is included in valid_responses
#call prompt_and_chomp
def get_valid_response(prompt, valid_responses)
response = prompt_and_chomp(prompt)
if valid_responses.include?(response)
response
else
puts "Not valid, try again."
get_valid_response
end
end
$armed = false
$naked = true
$window_broken = false
$girl_scream = false
puts
puts "You wake up in an alley. Your completely naked!"
puts "Looking around you see the surrounding buildings are covered in burn marks."
puts "There are some tattered clothes in the trash, a gun store across the street,"
puts "and an appartment building near by. Carved into your arm are the words"
puts '"Save the Girl"'
def first_room
puts
puts "Your in the alley."
response = get_valid_response("What do you do?: get dressed, go to gun store, go to appartment", ['get dressed', 'go to gun store', 'go to appartment'])
if response == 'get dressed'
puts "You are now dressed. Congrats!"
$naked = false
first_room
elsif response == 'go to gun store'
second_room
elsif response == 'go to appartment'
third_room
end
end
def second_room
puts
puts "You look into the gun store and see a lot of guns."
puts
response = get_valid_response("What do you do?: break window, open door, steal guns, go to appartment", ['break window', 'open door', 'steal guns', 'go to appartment'] )
if response == 'break window'
if $window_broken
puts "The window is broken"
second_room
else
puts "You smash the window with a nearby brick."
$window_broken = true
second_room
end
elsif response == 'open door'
puts "The door is locked."
second_room
elsif response == 'steal guns'
if $window_broken
puts "You're now armed to the teeth!"
$armed = true
second_room
else
puts "There's a window in the way!"
second_room
end
elsif response == 'go to appartment'
third_room
end
end
def third_room
puts
puts "Your at the appartment, there seems to be a girl inside."
puts
response = get_valid_response("What do you want to do? : knock, save the girl, go to gun store", ['knock', 'save the girl', 'go to gun store'])
if response == 'knock'
puts "You knock, and hear a scream. There's a killer robot in there!"
$girl_scream = true
third_room
elsif response == 'save the girl'
if $girl_scream
if $armed
puts "You bust in and blow that killer robot away!"
if $naked
puts "The girl is thankful to her naked hero."
puts "Great work!"
else
puts "Great work!"
end
else
puts "You stand no chance agaisnt the killer robot."
puts "The world is doomed, you all die horribly."
end
else
if $armed
puts "You bust threw the door...."
if $naked
puts "The girl screams at the naked man that just broke in."
puts "The girl then brains you with a lamp!"
puts "The world is doomed, you all die horribly"
else
puts "The girl screams at the man that just broke in."
puts "While she's wondering what your doing in her house a killer robot attacks"
puts "You blow away the killer robot, cause your armed to the teeth"
puts "You saved the girl."
puts "Great work!"
end
else
puts "The girl is confused, why did you just break into her house?"
puts "A killer robot jumps out and kills everyone!"
puts "The world is doomed, you all die horribly"
end
end
end
end
first_room