SHARE
TWEET

Untitled

a guest Feb 27th, 2020 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Hero
  2.   attr_reader :name
  3.  
  4.   def initialize(name)
  5.     @name = name
  6.   end
  7.  
  8.   def join(level)
  9.     puts "#{self.name} join #{level}\n"
  10.   end
  11.  
  12.   def attack(enemy)
  13.     puts "#{self.name} kick #{enemy}\n"
  14.   end
  15. end
  16.  
  17. class Enemy
  18.   attr_reader :name
  19.  
  20.   def initialize(name)
  21.     @name = name
  22.   end
  23.  
  24.   def dead(hero)
  25.     puts "#{self.name} killed by #{hero}"
  26.   end
  27. end
  28.  
  29. class Level
  30.   attr_reader :stage
  31.  
  32.   def initialize(stage)
  33.     @stage = stage
  34.   end
  35.  
  36.   def to_s
  37.     stage
  38.   end
  39. end
  40.  
  41. class GameFacade
  42.   attr_reader :hero, :enemy, :level
  43.  
  44.   def initialize
  45.     @hero  = Hero.new('Sonic')
  46.     @enemy = Enemy.new('Eggman')
  47.     @level = Level.new('Green Hill')
  48.   end
  49.  
  50.   def start_game
  51.     hero.join(level)
  52.     hero.attack(enemy.name)
  53.     enemy.dead(hero.name)
  54.   end
  55. end
  56.  
  57. game = GameFacade.new
  58. game.start_game
  59. # => Sonic join Green Hill
  60. #    Sonic kick Eggman
  61. #    Eggman killed by Sonic
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top