Created
February 16, 2016 20:41
-
-
Save dflynn15/4e403a4eec527c9b7880 to your computer and use it in GitHub Desktop.
Observable "Hunger Games" pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Class Capital | |
attr_reader :contestants | |
def initialize() | |
@contestants = [] | |
end | |
def register(NewContestant) | |
puts "#{NewContestant.name} has entered the game!" | |
@contestants >> NewContestant | |
end | |
def announcement(type, name) | |
@contestants.each { |contestant| contestant.announcement(type, name)} | |
end | |
def death(Contestant) | |
@contestants.delete(Contestant) | |
puts "#{Contestant.name} has died" | |
accouncement('death', Contestant.name) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Contestant | |
include Capital | |
attr_reader :name, :enemies | |
def initialize(name) | |
@name = name | |
@enemies = [] | |
Capital.register(name) | |
end | |
def announcement(type, name) | |
if type == 'death' | |
@enemies.delete(information.name) | |
elsif information.type == 'register' | |
@enemies << information.name | |
end | |
end | |
def die | |
Capital.death(self) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment