Class: Minesweeper::Core::Elements::Cell

Inherits:
Object
  • Object
show all
Defined in:
lib/minesweeper/core/elements/cell.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mine, mines_around = 0) ⇒ Cell

Returns a new instance of Cell.



20
21
22
23
24
# File 'lib/minesweeper/core/elements/cell.rb', line 20

def initialize(mine, mines_around = 0)
  @current_state = CellState::HIDDEN_STATE
  @mine = mine
  @mines_around = mines_around
end

Instance Attribute Details

#current_stateObject

STATES


CURRENT | ACTION | STATES | ACTION


hidden | reveal | revealed | trigger hidden | flag | flagged | flagged | reveal | revealed | trigger flagged | unflag | hidden |




17
18
19
# File 'lib/minesweeper/core/elements/cell.rb', line 17

def current_state
  @current_state
end

#mines_aroundObject

Returns the value of attribute mines_around.



18
19
20
# File 'lib/minesweeper/core/elements/cell.rb', line 18

def mines_around
  @mines_around
end

Instance Method Details

#flagObject



26
27
28
# File 'lib/minesweeper/core/elements/cell.rb', line 26

def flag
  current_state.flag(self)
end

#flagged?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/minesweeper/core/elements/cell.rb', line 50

def flagged?
  @current_state == CellState::FLAGGED_STATE
end

#revealObject



30
31
32
# File 'lib/minesweeper/core/elements/cell.rb', line 30

def reveal
  current_state.reveal(self)
end

#revealed?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/minesweeper/core/elements/cell.rb', line 46

def revealed?
  @current_state == CellState::REVEALED_STATE
end

#to_sObject



38
39
40
# File 'lib/minesweeper/core/elements/cell.rb', line 38

def to_s
  @current_state == CellState::REVEALED_STATE ? @mines_around.to_s : @current_state.to_s
end

#triggerObject



42
43
44
# File 'lib/minesweeper/core/elements/cell.rb', line 42

def trigger
  @mine.trigger
end

#unflagObject



34
35
36
# File 'lib/minesweeper/core/elements/cell.rb', line 34

def unflag
  current_state.unflag(self)
end