Class: Minesweeper::Board
- Inherits:
-
Object
- Object
- Minesweeper::Board
- Extended by:
- Forwardable
- Defined in:
- lib/minesweeper/board.rb
Constant Summary collapse
- ENTER =
10
- STEP =
3
- LEFT_RIGHT_PADDING =
2
- SPACE =
' '
Instance Attribute Summary collapse
-
#board_params ⇒ Object
readonly
Returns the value of attribute board_params.
-
#cells ⇒ Object
readonly
Returns the value of attribute cells.
-
#window ⇒ Object
readonly
Returns the value of attribute window.
Instance Method Summary collapse
- #bombs ⇒ Object
- #found_bombs ⇒ Object
-
#initialize(board_params) ⇒ Board
constructor
A new instance of Board.
- #number_of_cells ⇒ Object
- #play(stdy = nil, stdx = nil) ⇒ Object
Constructor Details
Instance Attribute Details
#board_params ⇒ Object (readonly)
Returns the value of attribute board_params.
15 16 17 |
# File 'lib/minesweeper/board.rb', line 15 def board_params @board_params end |
#cells ⇒ Object (readonly)
Returns the value of attribute cells.
15 16 17 |
# File 'lib/minesweeper/board.rb', line 15 def cells @cells end |
#window ⇒ Object (readonly)
Returns the value of attribute window.
15 16 17 |
# File 'lib/minesweeper/board.rb', line 15 def window @window end |
Instance Method Details
#bombs ⇒ Object
211 212 213 |
# File 'lib/minesweeper/board.rb', line 211 def bombs cells.flatten(1).select(&:bomb?) end |
#found_bombs ⇒ Object
215 216 217 |
# File 'lib/minesweeper/board.rb', line 215 def found_bombs bombs.select(&:marked_as_bomb?) end |
#number_of_cells ⇒ Object
219 220 221 |
# File 'lib/minesweeper/board.rb', line 219 def number_of_cells cells.flatten.count end |
#play(stdy = nil, stdx = nil) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/minesweeper/board.rb', line 23 def play(stdy = nil, stdx = nil) window.keypad = true draw_board window.setpos(stdy, stdx) if stdx && stdy noecho loop do ch = window.getch case ch when KEY_UP move_up when KEY_DOWN move_down when KEY_LEFT move_left when KEY_RIGHT move_right when ENTER open_cell when SPACE toggle_bomb_flag end play(cury, curx) end rescue GameWon, GameOver => e end_game(e) exit end |