Class: PirateGame::Bridge

Inherits:
Object
  • Object
show all
Defined in:
lib/pirate_game/bridge.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(items, stage_items) ⇒ Bridge

Returns a new instance of Bridge.



5
6
7
8
# File 'lib/pirate_game/bridge.rb', line 5

def initialize(items, stage_items)
  @items       = items
  @stage_items = stage_items
end

Instance Attribute Details

#itemsObject

Returns the value of attribute items.



3
4
5
# File 'lib/pirate_game/bridge.rb', line 3

def items
  @items
end

#stage_itemsObject

Returns the value of attribute stage_items.



3
4
5
# File 'lib/pirate_game/bridge.rb', line 3

def stage_items
  @stage_items
end

Instance Method Details

#sample_itemObject



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/pirate_game/bridge.rb', line 10

def sample_item
  item = @stage_items.sample

  # if we selected an item in the current bridge
  # reselect a new item 80% of the time
  if items.include?(item) && items.size < stage_items.size
    item = sample_item if rand > 0.2
  end

  return item
end