Created
June 17, 2016 05:02
-
-
Save dsomel21/c667f7d825567d214f707b875588d011 to your computer and use it in GitHub Desktop.
Fun little dog exercise I did a while back!
This file contains hidden or 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
| # Save this file to your computer so you can run it | |
| # via the command line (Terminal) like so: | |
| # $ ruby shakil_the_dog.rb | |
| # | |
| # Your method should wait for user input, which corresponds | |
| # to you saying something to your dog (named Shakil). | |
| # You'll probably want to write other methods, but this | |
| # encapsulates the core dog logic | |
| def shakil_the_dog | |
| print "Shakil: " | |
| 5.times {print " Woof!"} | |
| finished = false | |
| until finished== true | |
| puts "\nWhat do you want to do? \n a. Speak to Shakil. \n b. Woof back! \n c. Tell him to stop! \n d. Be a cat! \n e. Give him a something he'll like! \n f. Make him leave! " | |
| choice = gets.chomp.upcase! | |
| print "You choose option #{choice}! " | |
| case choice | |
| when "A" | |
| puts"What do you want so say to him?" | |
| phrase = gets.chomp | |
| aSpeak(phrase) | |
| when "B" | |
| puts"You: " | |
| bark() | |
| when "C" | |
| mustInclude# = "Shakil STOP" | |
| puts"If you explicitly use his name and advise him to stop he will not respond back with a bark." | |
| advise = gets.capitalize.chomp | |
| if advise == mustInclude | |
| puts "Shakil: . . . " | |
| else | |
| puts "Oops! Try saying his name and yelling at him to stop!" | |
| end | |
| when "D" | |
| print "You: " | |
| purr() | |
| print "Shakil: " | |
| bark(5) | |
| when "E" | |
| puts "Say treat!" | |
| sayTreat = gets.chomp | |
| until sayTreat == "treat" | |
| treat() | |
| end | |
| when "F" | |
| puts "He left. You kicked him out by saying go away!" | |
| finished = true | |
| else | |
| puts "Invalid." | |
| bark | |
| end | |
| end | |
| end | |
| def bark(x=1) | |
| x.times{print " woof!"} | |
| end | |
| def purr | |
| puts "Meow..." | |
| end | |
| def aSpeak(saySomething) | |
| puts "You: #{saySomething}" | |
| print "Shakil: " | |
| bark() | |
| end | |
| def treat() | |
| puts "treat" | |
| puts "Shakila.... *waiting for treat*" | |
| end | |
| # Run our method | |
| shakil_the_dog |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment