-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOrangeTree.rb
60 lines (50 loc) · 1.03 KB
/
OrangeTree.rb
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
class OrangeTree
def initialize
puts "program started"
@age = 0
@height = 0
@oranges = 0
@totaloranges = 0
startyear
end
def startyear
puts " A new year begins"
@age += 1
#tree dies meth here
treegrows
puts "your tree is #{@age} years old and #{@height} feet tall"
groworanges
die
endyear
end
def treegrows
@height += 1 + rand(3)
end
def groworanges
if @height >= 12 or @age >= 4
@age.times do
@oranges += rand(5)
@totaloranges += @oranges
end
puts "Your tree grew #{@oranges} oranges this year"
end
end
def die
chance = @age / 2 + rand(21)
if chance > 30
puts ""
puts "Your tree died"
puts "it produced #{@totaloranges} oranges over its life of #{@age} years"
puts "and grew to #{@height} feet tall"
exit
end
end
def endyear
puts "your tree survied another year!"
puts ""
puts ""
@oranges = 0
startyear
end
end
OrangeTree.new