Class: Minesweeper::Cells::Base

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/minesweeper/cells/base.rb

Direct Known Subclasses

Bomb, Cell

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.



12
13
14
# File 'lib/minesweeper/cells/base.rb', line 12

def initialize
  @state = initial_state
end

Instance Attribute Details

#stateObject (readonly)

Returns the value of attribute state.



10
11
12
# File 'lib/minesweeper/cells/base.rb', line 10

def state
  @state
end

Instance Method Details

#bomb?Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


16
17
18
# File 'lib/minesweeper/cells/base.rb', line 16

def bomb?
  raise NotImplementedError, 'defined in subclass'
end

#open!Object

Raises:

  • (NotImplementedError)


33
34
35
# File 'lib/minesweeper/cells/base.rb', line 33

def open!(*)
  raise NotImplementedError, 'defined in subclass'
end

#toggle_bomb_flag!Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/minesweeper/cells/base.rb', line 20

def toggle_bomb_flag!
  return if opened?
  if marked_as_bomb?
    state.view = ' '
    state.color = COLOR_MAGENTA
    state.status = :initial
  else
    state.view = '*'
    state.color = COLOR_MAGENTA
    state.status = :marked_as_bomb
  end
end