forked from Trishthedish/ruby_dragon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdragon.rb
More file actions
151 lines (132 loc) · 3.46 KB
/
Copy pathdragon.rb
File metadata and controls
151 lines (132 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
class Dragon
# ------------- Initialized Method -------------#
def initialize(name, color)
# We need to figure out how much these values start at. Thus, we first create
@food_in_belly = 100
@food_in_intestine = 0
@awake = true
@name = name
@color = color
puts "#{name} has been born!"
if @color == "gold"
@gold = 0
end
end
# ------------- feed Method -------------#
# amount = 10 making it default.
def feed(amount = 10)
#plus equals because you're eating.
@food_in_belly += amount
if @food_in_belly > 100
puts "#{@name} is overstuffed and makes a mess"
@food_in_belly = 100
else
puts "#{@name} eats happily for #{amount}, he now has #{@food_in_intestine} in his intestine."
end
time_passed
end
# ------------- walk Method -------------#
def walk
if @awake != true
puts "You wake #{@name}"
@awake = true
end
if @food_in_intestine > 50
if @color == "gold"
@gold += @food_in_intestine
@poop = @food_in_intestine
puts "#{@name} just pooped #{@poop} gold nuggets!! Surprise"
end
@food_in_intestine = 0
puts "#{@name} makes use of the facilities"
else
puts "#{@name} sniffs around but doesn't do business"
end
time_passed
end
end
# ------------- nap Method -------------#
def nap
@awake = false
puts "#{@name} takes a nap!! "
time_passed
end
# ------------- play Method -------------#
def play
wake
puts "You play toss with #{@name}."
puts "#{@name} purrs singing you eyebrows"
time_passed
end
# ------------- wake Method -------------#
def wake
if @awake
return
else
@awake = true
puts "You gently swake #{@name}"
end
end
# ------------- specialty Method -------------#
def specialty
wake
case @color
when "red"
puts "#{@name} in love and breathing fire"
when "blue"
puts "#{@name} is sad and breathing water"
when "green"
puts "#{@name} is envious and mowing the lawn"
when "purple"
puts "#{@name} in royal and puts on a crown"
when "gold"
puts "#{@name} has excreeted #{@gold} gold nuggets so far..."
end
end
end
# ------------- time_passed Method -------------#
private
def time_passed
@food_in_belly -= 10
@food_in_intestine += 10
if @food_in_belly < 30
puts "#{@name} is HUNGRY!! Rawr!"
end
if @food_in_intestine > 80
if @awake != true
@awake = true
puts "#{@name} suddenly awakes"
else
puts "#{@name} is doing potty dance!!"
end
end
if @food_in_belly <= 30
if @awake != true
@awake = true
puts "#{@name} suddenly awakens!"
end
puts "#{@name} is STARVING and he EATS YOU!!!!!"
exit
end
if @awake != true
puts "#{@name} snores loudly!!!"
end
end
end
#here how you test your Dragon, when all you have is one initialized method.
my_dragon = Dragon.new("Princess Dragon", "gold")
my_dragon.feed(200)
my_dragon.feed
my_dragon.feed
my_dragon.feed
my_dragon.walk
my_dragon.walk
my_dragon.nap
my_dragon.nap
my_dragon.play
my_dragon.play
my_dragon.play
#if were feeding dragon
# dragon.rb:32:in `<main>': uninitialized constant Dragon (NameError)
# dragon.rb:32:in `<main>': uninitialized constant Dragon (NameError)
# fixed by realizing you made a def Dragon, NOT CLASS DRAGON.