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.
-
#ui ⇒ Object
readonly
Returns the value of attribute ui.
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
#initialize(board_params) ⇒ Board
Returns a new instance of Board.
16 17 18 19 20 |
# File 'lib/minesweeper/board.rb', line 16 def initialize(board_params) @board_params = board_params @ui = Minesweeper::Ui @cells = [] end |
Instance Attribute Details
#board_params ⇒ Object (readonly)
Returns the value of attribute board_params.
14 15 16 |
# File 'lib/minesweeper/board.rb', line 14 def board_params @board_params end |
#cells ⇒ Object (readonly)
Returns the value of attribute cells.
14 15 16 |
# File 'lib/minesweeper/board.rb', line 14 def cells @cells end |
#ui ⇒ Object (readonly)
Returns the value of attribute ui.
14 15 16 |
# File 'lib/minesweeper/board.rb', line 14 def ui @ui end |
Instance Method Details
#bombs ⇒ Object
209 210 211 |
# File 'lib/minesweeper/board.rb', line 209 def bombs cells.flatten(1).select(&:bomb?) end |
#found_bombs ⇒ Object
213 214 215 |
# File 'lib/minesweeper/board.rb', line 213 def found_bombs bombs.select(&:marked_as_bomb?) end |
#number_of_cells ⇒ Object
217 218 219 |
# File 'lib/minesweeper/board.rb', line 217 def number_of_cells cells.flatten.count end |
#play(stdy = nil, stdx = nil) ⇒ Object
22 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 |
# File 'lib/minesweeper/board.rb', line 22 def play(stdy = nil, stdx = nil) draw_board ui.setpos(stdy, stdx) if stdx && stdy noecho loop do ch = ui.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(ui.cury, ui.curx) end rescue GameWon, GameOver => e end_game(e) exit end |