class SeaBattle::Cell
Attributes
status[R]
Public Class Methods
new(status = 1)
click to toggle source
status value: 1 -> empty field 2 -> field is part of ship 4 -> attacked field 8 -> is only selected by user
16 -> is sunk
6 -> attacked field and exsist ship
# File lib/sea_battle/cell.rb, line 16 def initialize(status = 1) @status = status end
Public Instance Methods
add_ship()
click to toggle source
# File lib/sea_battle/cell.rb, line 20 def add_ship @status += 2 unless is_in_ship? end
attack()
click to toggle source
# File lib/sea_battle/cell.rb, line 24 def attack @status += 4 unless is_attacked? end
is_attacked?()
click to toggle source
# File lib/sea_battle/cell.rb, line 36 def is_attacked? @status & 4 == 4 end
is_empty?()
click to toggle source
# File lib/sea_battle/cell.rb, line 40 def is_empty? @status & 1 == 1 end
is_in_ship?()
click to toggle source
# File lib/sea_battle/cell.rb, line 44 def is_in_ship? @status & 2 == 2 end
is_selected?()
click to toggle source
# File lib/sea_battle/cell.rb, line 48 def is_selected? @status & 8 == 8 end
is_sunk?()
click to toggle source
# File lib/sea_battle/cell.rb, line 52 def is_sunk? @status & 16 == 16 end
reset_cell()
click to toggle source
# File lib/sea_battle/cell.rb, line 56 def reset_cell @status = 1 end
sunk()
click to toggle source
# File lib/sea_battle/cell.rb, line 28 def sunk @status += 16 unless is_sunk? end
switch_select()
click to toggle source
# File lib/sea_battle/cell.rb, line 32 def switch_select is_selected? ? @status -= 8 : @status += 8 end