-
Notifications
You must be signed in to change notification settings - Fork 63
/
powerranger.rb
85 lines (69 loc) · 1.53 KB
/
powerranger.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
require 'modules.rb'
class Person
attr_accessor :name, :caffeine_level
def initialize(name)
@name = name
@caffeine_level = 0
end
def run
"#{@name} ran away."
end
def scream(string)
"#{string.upcase}!!!"
end
def drink_coffee
@caffeine_level += 1
end
end
class PowerRanger < Person
include Fight
def initialize(name, strength, color)
super(name)
@strength = strength
@color = color
end
def rest
"zzzzzzzzzzzzzzzzzzz..."
end
def self.use_megazord(target)
puts target.scream("ow")
puts target.run
puts target.scream("ow")
puts target.run
target.caffeine_level -= 1
end
end
class EvilNinja < Person
include Fight
def initialize(name, strength, evilness)
super(name)
@strength = strength
@evilness = evilness
end
def cause_mayhem(target)
target.caffeine_level = 0
puts "mayhem caused"
end
end
def fight_scene(person1, person2, pr1, pr2, ninja1, ninja2)
person1.drink_coffee
person2.drink_coffee
person1.drink_coffee
ninja1.cause_mayhem(person1)
ninja2.cause_mayhem(person2)
pr1.punch(ninja1)
pr2.punch(ninja2)
ninja1.punch(pr1)
ninja2.punch(pr2)
pr1.rest
pr2.rest
PowerRanger.use_megazord(ninja1)
PowerRanger.use_megazord(ninja2)
end
bob = Person.new("Bob")
phil = Person.new("Phil")
red = PowerRanger.new("John", 5, "red")
green = PowerRanger.new("Sean", 4, "green")
ninja1 = EvilNinja.new("Evil Ninja 1", 10, 10)
ninja2 = EvilNinja.new("Evil Ninja 1", 15, 30)
fight_scene(bob, phil, red, green, ninja1, ninja2)