Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.54 KB | None | 0 0
  1. class Dragon
  2. attr_accessor :color
  3.  
  4. def initialize(input_name, color)
  5. @name = input_name
  6. @asleep = false
  7. @stuff_in_belly = 10
  8. @stuff_in_intestines = 0
  9. @color = color
  10. if @color == "blue" || @color == "green"
  11. @stuff_in_belly = 5
  12. @stuff_in_intestines = 5
  13. end
  14. end
  15.  
  16. def paint(color)
  17. @color = color.to_s
  18. end
  19.  
  20. def special_power
  21. case @color
  22. when "blue"
  23. puts "#{@name} breathes ICE and freezes you. See you after you defrost."
  24. when "red"
  25. puts "#{@name} runs at superspeed, leaving fire in their wake and is lost forever."
  26. exit
  27. when "green"
  28. puts "#{@name} suddenly speaks in fluent French and you both share a baguette."
  29. when "purple"
  30. puts "#{@name} jumps so high, that they make a hole in the ceiling."
  31. else
  32. puts "#{@name}'s special power is being a really nice dragon companion."
  33. end
  34. end
  35.  
  36. def power_word
  37. case @color
  38. when "red"
  39. power_words = ["fire", "smoke", "charred marshmallows", "lava"]
  40. when "blue"
  41. power_words = ["ice", "snowflakes", "existential angst", "frozen hot chocolate"]
  42. when "green"
  43. power_words = ["berets", "tiny Eiffel Tower key-chains", "eclairs", "croissants"]
  44. when "purple"
  45. power_words = ["pogo sticks", "trampolines", "Moon Shoes: the hottest toy of 2002", "Air Jordans"]
  46. else
  47. power_words = ["bubbles", "cats", "sprinkles", "daisies"]
  48. end
  49. return power_words
  50. end
  51.  
  52. def feed
  53. puts "#{@name} ate food."
  54. @stuff_in_belly = 10
  55. passage_of_time
  56. end
  57.  
  58. def toss
  59. puts "You tossed #{@name} into the air"
  60. puts "They giggle, and it singes your eyebrows"
  61. passage_of_time
  62. dragon_art_toss
  63. end
  64.  
  65. def walk
  66. puts "You take #{@name} out for a walk"
  67. @stuff_in_intestines = 0
  68. passage_of_time
  69. end
  70.  
  71. def put_to_bed
  72. puts "You put #{@name} to bed"
  73. @asleep = true
  74.  
  75. 3.times do
  76. random = rand(4)
  77. if @asleep
  78. passage_of_time
  79. end
  80. if @asleep
  81. puts "#{@name} snores. They fill the room with #{power_word[random]}."
  82. end
  83. end
  84.  
  85. if @asleep
  86. @asleep = false
  87. puts "#{@name} wakes up slowly."
  88. dragon_art_awake
  89. end
  90. end
  91.  
  92. def rock
  93. puts "You rock #{@name} gently to sleep."
  94. @asleep = true
  95. passage_of_time
  96. if @asleep
  97. @asleep = false
  98. puts "But they wake up after you stop."
  99. end
  100. end
  101. end
  102.  
  103. private
  104.  
  105. def dragon_art_toss
  106. puts "|\___/|"
  107. puts "(,\ /,)\ "
  108. puts " / / \ "
  109. puts "(@_^_@)/ \ "
  110. puts "W//W_/ \ "
  111. puts "(//) | \ "
  112. puts "(/ /) _|_ / ) \ "
  113. puts "(// /) '/,_ _ _/ (~^-."
  114. puts "(( // )) ,-{ _ `."
  115. puts "(( /// )) '/\ / |"
  116. puts "(( ///)) `. { }"
  117. puts "((/ )) .----~-.\ \-"
  118. puts "///.----..> \ "
  119. puts " ///-._ _ _ _} "
  120. end
  121.  
  122. def dragon_art_awake
  123. puts '( ) /\ _ ( '
  124. puts ' \ | ( \ ( \.( ) _____'
  125. puts ' \ \ \ ` ` ) \ ( ___ / _ \ '
  126. puts '(_` \+ . x ( .\ \/ \____-----------/ (o) \_'
  127. puts '- .- \+ ; ( O \____'
  128. puts' ) \_____________ ` \ /'
  129. puts "'(__ +- .( -'.- <. - _ VVVVVVV VV V /"
  130. puts "(_____ ._._: <_ - <- _ (-- _AAAAAAA__A_/ |"
  131. puts '. /./.+- . .- / +-- - . \______________//_ \_______'
  132. puts "(__ ' /x / x _/ ( \___' \ /"
  133. puts ", x / ( ' . / . / | \ /"
  134. puts " / / _/ / + / \/"
  135. puts " ' (__/ / \ "
  136. end
  137.  
  138. def hungry?
  139. return @stuff_in_belly <=2
  140. end
  141.  
  142. def poopy?
  143. return @stuff_in_intestines >= 8
  144. end
  145.  
  146. def passage_of_time
  147.  
  148. if @stuff_in_belly > 0
  149. @stuff_in_belly -= 1
  150. @stuff_in_intestines +=1
  151. else
  152. if @asleep
  153. @asleep = false
  154. puts "#{@name} wakes up."
  155. end
  156. puts "They were starving! In desperation, they ATE you!"
  157. exit
  158. end
  159.  
  160. if @stuff_in_intestines >= 10
  161. @stuff_in_intestines = 0
  162. puts "#{@name} had an accident..."
  163. end
  164.  
  165. if hungry?
  166. if @asleep
  167. @asleep = false
  168. puts "#{@name} suddenly wakes up!"
  169. end
  170. puts "#{@name}'s stomach is grumbling..."
  171. end
  172.  
  173. if poopy?
  174. if @asleep
  175. @asleep = false
  176. puts "#{@name} suddenly wakes up!"
  177. end
  178. puts "#{@name} is doing the potty dance..."
  179. end
  180. end
  181.  
  182. puts "Welcome to the Baby Dragon 5000!"
  183. puts "What is your dragon's name?"
  184. name = gets.chomp
  185. puts "What color is your dragon? (Hint: blue, red, green, and purple make stunning dragons)"
  186. color = gets.chomp
  187.  
  188. dragon = Dragon.new(name, color)
  189.  
  190. puts "There are a lot of fun things to do with your dragon. Enter \"done\" when you are tired of him."
  191. options = %w(feed toss walk put\ to\ bed rock special\ power paint)
  192. puts "You can:"
  193. options.each do |option|
  194. puts option.capitalize
  195. end
  196.  
  197. response = ""
  198. until response == "done"
  199. puts "What would you like to do next?"
  200. response = gets.chomp.downcase
  201. case response
  202. when "feed"
  203. dragon.feed
  204. when "toss"
  205. dragon.toss
  206. when "put to bed"
  207. dragon.put_to_bed
  208. when "rock"
  209. dragon.rock
  210. when "walk"
  211. dragon.walk
  212. when "special power"
  213. dragon.special_power
  214. when "paint"
  215. print "What color would you like to paint your dragon? "
  216. color = gets.chomp.downcase
  217. dragon.paint(color)
  218. when "done"
  219. puts "Your dragon will miss you! Come back soon!"
  220. else
  221. print "Sorry, you can't do that!"
  222. end
  223. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement