Class: BattleBoats::Cell
- Inherits:
-
Object
- Object
- BattleBoats::Cell
- Defined in:
- lib/battle_boats/cell.rb
Instance Attribute Summary collapse
-
#occupant ⇒ Object
Returns the value of attribute occupant.
Instance Method Summary collapse
- #hit? ⇒ Boolean
-
#initialize ⇒ Cell
constructor
A new instance of Cell.
- #occupied? ⇒ Boolean
- #status_report ⇒ Object
- #strike ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Cell
Returns a new instance of Cell.
9 10 11 12 |
# File 'lib/battle_boats/cell.rb', line 9 def initialize @hit = false @occupant = BattleBoats::NullShip.new end |
Instance Attribute Details
#occupant ⇒ Object
Returns the value of attribute occupant.
7 8 9 |
# File 'lib/battle_boats/cell.rb', line 7 def occupant @occupant end |
Instance Method Details
#hit? ⇒ Boolean
14 15 16 |
# File 'lib/battle_boats/cell.rb', line 14 def hit? @hit end |
#occupied? ⇒ Boolean
42 43 44 |
# File 'lib/battle_boats/cell.rb', line 42 def occupied? !occupant.empty? end |
#status_report ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/battle_boats/cell.rb', line 33 def status_report occupant_name = occupant.name if occupant.sunk? "You sunk my #{occupant_name}!" elsif hit? "You hit my #{occupant_name}!" end end |
#strike ⇒ Object
18 19 20 21 22 23 |
# File 'lib/battle_boats/cell.rb', line 18 def strike if !hit? occupant.hit @hit = true end end |
#to_s ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/battle_boats/cell.rb', line 25 def to_s if hit? occupant.symbol else ".".blue end end |