Class: BattleBoats::Cell

Inherits:
Object
  • Object
show all
Defined in:
lib/battle_boats/cell.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCell

Returns a new instance of Cell.


7
8
9
10
# File 'lib/battle_boats/cell.rb', line 7

def initialize
  @hit = false
  @occupant = BattleBoats::NullShip.new
end

Instance Attribute Details

#occupantObject

Returns the value of attribute occupant


5
6
7
# File 'lib/battle_boats/cell.rb', line 5

def occupant
  @occupant
end

Instance Method Details

#hit?Boolean

Returns:

  • (Boolean)

12
13
14
# File 'lib/battle_boats/cell.rb', line 12

def hit?
  @hit
end

#occupied?Boolean

Returns:

  • (Boolean)

32
33
34
# File 'lib/battle_boats/cell.rb', line 32

def occupied?
  !occupant.empty?
end

#status_reportObject


23
24
25
26
27
28
29
30
# File 'lib/battle_boats/cell.rb', line 23

def status_report
  occupant_name = occupant.name
  if occupant.sunk?
    "You sunk my #{occupant_name}!"
  elsif hit?
    "You hit my #{occupant_name}!"
  end
end

#strikeObject


16
17
18
19
20
21
# File 'lib/battle_boats/cell.rb', line 16

def strike
  if !hit?
    occupant.hit
    @hit = true
  end
end