Created
April 16, 2015 22:00
-
-
Save eddroid/0d720fb2f9402c478d96 to your computer and use it in GitHub Desktop.
Batman C5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Batman | |
def intro | |
puts "*"*80 | |
puts "Welcome to Batman: Arkham Asylum" | |
puts "*"*80 | |
end | |
def ask_question(question, options) | |
puts "*"*80, question, "*"*80 | |
response = nil | |
until options.include?(response) | |
puts "Your options are: #{options.join(', ')}" | |
response = gets.chomp.downcase | |
end | |
response | |
end | |
def first_question | |
options = ["hit", "run away", "look around"] | |
response = | |
ask_question("What do you want to do Batman?", options) | |
case response | |
when "hit" | |
puts 'Mental Patient: "What did I ever do to you, Batman!"' | |
when "run away" | |
puts 'Batman: "Bats can\'t run."' | |
when "look around" | |
puts "You see a bunch of angry mental patients." | |
end | |
response | |
end | |
def second_question | |
options = %w[batarang flashlight fists] | |
response = | |
ask_question("What weapon would you like to use?", options) | |
case response | |
when "batarang" | |
puts 'Batman: "Let\'s do this!"' | |
response = Batarang.new | |
when "flashlight" | |
puts 'Mental Patient: "Ahh, I\'m blind!."' | |
response = Flashlight.new | |
when "fists" | |
puts 'Batman: "I\'s time to kick ass and chew bubble gum and I\'m all out of bubble gum"' | |
response = Fist.new | |
end | |
response | |
end | |
end | |
class Weapon | |
def use | |
puts "I'm just a weapon" | |
end | |
end | |
class Batarang < Weapon | |
def use | |
puts "Swish!" | |
end | |
end | |
class Flashlight < Weapon | |
def use | |
puts "Flash!" | |
end | |
end | |
class Fist < Weapon | |
def use | |
puts "Smack!" | |
end | |
end | |
def test | |
game = Batman.new | |
game.intro | |
response = game.first_question | |
puts(["hit", "run away", "look around"].include?(response)) | |
response = game.second_question | |
puts((response.is_a?(Weapon))) | |
weapon = response | |
weapon.use | |
end | |
test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment