Class: MineSweeper::Cell

Inherits:
Object
  • Object
show all
Defined in:
lib/mine-sweeper/cell.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCell

Returns a new instance of Cell.



7
8
9
10
11
12
# File 'lib/mine-sweeper/cell.rb', line 7

def initialize
  @mine = false
  @cleared = false
  @flagged = false
  @adjacent_mines = 0
end

Instance Attribute Details

#adjacent_minesObject (readonly)

Returns the value of attribute adjacent_mines.



5
6
7
# File 'lib/mine-sweeper/cell.rb', line 5

def adjacent_mines
  @adjacent_mines
end

#clearedObject (readonly)

Returns the value of attribute cleared.



5
6
7
# File 'lib/mine-sweeper/cell.rb', line 5

def cleared
  @cleared
end

#flaggedObject (readonly)

Returns the value of attribute flagged.



5
6
7
# File 'lib/mine-sweeper/cell.rb', line 5

def flagged
  @flagged
end

#mineObject (readonly)

Returns the value of attribute mine.



5
6
7
# File 'lib/mine-sweeper/cell.rb', line 5

def mine
  @mine
end

Instance Method Details

#clearObject



27
28
29
# File 'lib/mine-sweeper/cell.rb', line 27

def clear
  @cleared = true unless flagged
end

#count_adjacent_mineObject



23
24
25
# File 'lib/mine-sweeper/cell.rb', line 23

def count_adjacent_mine
  @adjacent_mines += 1
end

#exploded?Boolean

This ends the game!

Returns:

  • (Boolean)


15
16
17
# File 'lib/mine-sweeper/cell.rb', line 15

def exploded?
  mine && cleared
end

#flagObject



31
32
33
# File 'lib/mine-sweeper/cell.rb', line 31

def flag
  @flagged = true unless cleared
end

#place_mineObject



19
20
21
# File 'lib/mine-sweeper/cell.rb', line 19

def place_mine
  @mine = true
end

#to_sObject



39
40
41
42
43
44
45
# File 'lib/mine-sweeper/cell.rb', line 39

def to_s
  if cleared
    cleared_string_states
  else
    uncleared_string_states
  end
end

#unflagObject



35
36
37
# File 'lib/mine-sweeper/cell.rb', line 35

def unflag
  @flagged = false
end