Class: BloodChalice::EventDeck
- Inherits:
-
Object
- Object
- BloodChalice::EventDeck
- Defined in:
- lib/bloodchalice/event_deck.rb
Constant Summary collapse
- CARDS =
[:new_zombie, :new_knight, :new_peasant]
Instance Attribute Summary collapse
-
#game ⇒ Object
Returns the value of attribute game.
-
#map ⇒ Object
Returns the value of attribute map.
Instance Method Summary collapse
- #get_card ⇒ Object
-
#initialize(game) ⇒ EventDeck
constructor
A new instance of EventDeck.
- #modify_world(card) ⇒ Object
- #take_a_card ⇒ Object
Constructor Details
#initialize(game) ⇒ EventDeck
Returns a new instance of EventDeck.
7 8 9 10 |
# File 'lib/bloodchalice/event_deck.rb', line 7 def initialize(game) @game = game @map = game.map end |
Instance Attribute Details
#game ⇒ Object
Returns the value of attribute game.
5 6 7 |
# File 'lib/bloodchalice/event_deck.rb', line 5 def game @game end |
#map ⇒ Object
Returns the value of attribute map.
5 6 7 |
# File 'lib/bloodchalice/event_deck.rb', line 5 def map @map end |
Instance Method Details
#get_card ⇒ Object
16 17 18 |
# File 'lib/bloodchalice/event_deck.rb', line 16 def get_card() CARDS.sample end |
#modify_world(card) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/bloodchalice/event_deck.rb', line 20 def modify_world(card) empty_tiles = @map.map.flatten.select { |t| t.empty?} case card when :new_zombie puts "New zombie!" tile = empty_tiles.sample @map.set_tile(tile.position, Zombie.new(map: @map, position: tile.position, game: @game)) when :new_knight puts "New Knight!" tile = empty_tiles.sample @map.set_tile(tile.position, Knight.new(map: @map, position: tile.position, game: @game)) when :new_peasant puts "New Peasant!" tile = empty_tiles.sample @map.set_tile(tile.position, Peasant.new(map: @map, position: tile.position, game: @game)) end end |
#take_a_card ⇒ Object
12 13 14 |
# File 'lib/bloodchalice/event_deck.rb', line 12 def take_a_card() modify_world(get_card()) end |