-
Notifications
You must be signed in to change notification settings - Fork 0
/
powerrangers.rb
146 lines (114 loc) · 2.52 KB
/
powerrangers.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
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
class Person
attr_accessor :health, :caffeine_level
attr_reader :name
def initialize(name)
@name = name
@caffeine_level = 100
@health = 100
end
def run
puts "#{@name} runs for his/her life!"
end
def scream
puts "#{@name} screams in horror!"
end
def drink_coffee
if @caffeine_level <= 85
@caffeine_level += 15
"Drinks a cup of coffee."
elsif @caffeine_level >= 100
"Fully caffeinated!"
end
end
end
module KungFu
def punch(victim)
if @caffeine_level >= 5
puts "#{@name} throws a punch."
punch = rand(@strength)
if punch > 5
puts "#{victim.name} summersaults into the air and takes #{punch} damage!"
elsif punch == 0
puts "The #{@name}'s punch does nothing."
else
puts "The #{@name} punches #{victim.name} for #{punch} damage."
end
victim.health -= punch
@caffeine_level -= 5
victim.scream
victim.run
else
puts "Please rest to restore energy."
end
end
end
class PowerRanger < Person
attr_accessor :health, :caffeine_level
attr_reader :name
include KungFu
def initialize(name, color, strength = 10)
super(name)
@name = name
@color = color
@strength = strength
end
def use_megazord(victim)
if @caffeine_level >= 75
punch = rand(100..5000)
puts "Go go Power Rangers! Megazord attacks #{victim.name} for #{punch} damage."
victim.health -= punch
@caffeine_level -= 75
else
puts "Not enough energy to summon Megazord. Let the power ranger rest."
end
end
def rest
@caffeine_level = 100
puts "#{@name} is fully rested!"
end
end
class EvilNinja < Person
attr_accessor :health
attr_reader :name
include KungFu
def initialize
super(name)
@strength = 10
@evilness = 100
@name = "Evil Ninja"
end
def cause_mayhem(victim)
if @evilness >= 75
victim.caffeine_level = 0
@evilness -= 75
puts "Evil Ninja causes mayhem draining #{victim.name}'s energy to 0."
else
puts "Ninja is not evil enough, he needs rest."
end
end
end
def fight_scene
glenn = Person.new("Glenn")
steve = Person.new("Steve")
tommy = PowerRanger.new("Tommy", "Green")
rocky = PowerRanger.new("Rocky", "Red")
ninja_a = EvilNinja.new
ninja_b = EvilNinja.new
glenn.run
glenn.scream
steve.run
steve.scream
ninja_a.punch(glenn)
ninja_a.cause_mayhem(glenn)
ninja_b.punch(steve)
ninja_b.cause_mayhem(steve)
tommy.punch(ninja_a)
tommy.use_megazord(ninja_a)
tommy.rest
rocky.punch(ninja_b)
rocky.use_megazord(ninja_b)
rocky.rest
end
# glenn = Person.new("Glenn")
# tommy = PowerRanger.new(10, "red")
# tommy.punch(glenn)