Class: Ship

Inherits:
Object
  • Object
show all
Includes:
State
Defined in:
lib/ship.rb

Overview

class Ship describes ship state

Constant Summary

Constants included from State

State::BROKEN, State::EMPTY, State::MISSED, State::SHIP

Instance Method Summary collapse

Constructor Details

#initialize(cells) ⇒ Ship

Returns a new instance of Ship.



14
15
16
17
# File 'lib/ship.rb', line 14

def initialize(cells)
  @cells = cells
  @cells.each { |c| c.state = SHIP }
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)


19
20
21
22
# File 'lib/ship.rb', line 19

def alive?
  @cells.each { |c| return true if c.state == SHIP }
  false
end

#include?(cell) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/ship.rb', line 24

def include?(cell)
  @cells.include? cell
end