-
Notifications
You must be signed in to change notification settings - Fork 105
/
facade.rb
61 lines (48 loc) · 878 Bytes
/
facade.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
class Hero
attr_reader :name
def initialize(name)
@name = name
end
def join(level)
puts "#{self.name} join #{level}\n"
end
def attack(enemy)
puts "#{self.name} kick #{enemy}\n"
end
end
class Enemy
attr_reader :name
def initialize(name)
@name = name
end
def dead(hero)
puts "#{self.name} killed by #{hero}"
end
end
class Level
attr_reader :stage
def initialize(stage)
@stage = stage
end
def to_s
stage
end
end
class GameFacade
attr_reader :hero, :enemy, :level
def initialize
@hero = Hero.new('Sonic')
@enemy = Enemy.new('Eggman')
@level = Level.new('Green Hill')
end
def start_game
hero.join(level)
hero.attack(enemy.name)
enemy.dead(hero.name)
end
end
game = GameFacade.new
game.start_game
# => Sonic join Green Hill
# Sonic kick Eggman
# Eggman killed by Sonic