Class: PirateGame::Bridge
- Inherits:
-
Object
- Object
- PirateGame::Bridge
- Defined in:
- lib/pirate_game/bridge.rb
Instance Attribute Summary collapse
-
#items ⇒ Object
Returns the value of attribute items.
-
#stage_items ⇒ Object
Returns the value of attribute stage_items.
Instance Method Summary collapse
-
#initialize(items, stage_items) ⇒ Bridge
constructor
A new instance of Bridge.
- #sample_item ⇒ Object
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
#items ⇒ Object
Returns the value of attribute items.
3 4 5 |
# File 'lib/pirate_game/bridge.rb', line 3 def items @items end |
#stage_items ⇒ Object
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_item ⇒ Object
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 |