Class: MineSweeper::Cell
- Inherits:
-
Object
- Object
- MineSweeper::Cell
- Defined in:
- lib/mine-sweeper/cell.rb
Instance Attribute Summary collapse
-
#adjacent_mines ⇒ Object
readonly
Returns the value of attribute adjacent_mines.
-
#cleared ⇒ Object
readonly
Returns the value of attribute cleared.
-
#flagged ⇒ Object
readonly
Returns the value of attribute flagged.
-
#mine ⇒ Object
readonly
Returns the value of attribute mine.
Instance Method Summary collapse
- #clear ⇒ Object
- #count_adjacent_mine ⇒ Object
-
#exploded? ⇒ Boolean
This ends the game!.
- #flag ⇒ Object
-
#initialize ⇒ Cell
constructor
A new instance of Cell.
- #place_mine ⇒ Object
- #to_s ⇒ Object
- #unflag ⇒ Object
Constructor Details
#initialize ⇒ Cell
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_mines ⇒ Object (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 |
#cleared ⇒ Object (readonly)
Returns the value of attribute cleared.
5 6 7 |
# File 'lib/mine-sweeper/cell.rb', line 5 def cleared @cleared end |
#flagged ⇒ Object (readonly)
Returns the value of attribute flagged.
5 6 7 |
# File 'lib/mine-sweeper/cell.rb', line 5 def flagged @flagged end |
#mine ⇒ Object (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
#clear ⇒ Object
27 28 29 |
# File 'lib/mine-sweeper/cell.rb', line 27 def clear @cleared = true unless flagged end |
#count_adjacent_mine ⇒ Object
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!
15 16 17 |
# File 'lib/mine-sweeper/cell.rb', line 15 def exploded? mine && cleared end |
#flag ⇒ Object
31 32 33 |
# File 'lib/mine-sweeper/cell.rb', line 31 def flag @flagged = true unless cleared end |
#place_mine ⇒ Object
19 20 21 |
# File 'lib/mine-sweeper/cell.rb', line 19 def place_mine @mine = true end |
#to_s ⇒ Object
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 |
#unflag ⇒ Object
35 36 37 |
# File 'lib/mine-sweeper/cell.rb', line 35 def unflag @flagged = false end |