Class: Minesweeprb::Gameboard
- Inherits:
-
Object
- Object
- Minesweeprb::Gameboard
- Includes:
- Curses
- Defined in:
- lib/minesweeprb/gameboard.rb
Constant Summary collapse
- RESTART =
['r'].freeze
- REVEAL =
[10, KEY_ENTER].freeze
- FLAG =
['f', ' '].freeze
- BACK =
['q', 27, 127, KEY_BACKSPACE].freeze
- MOVE =
{ KEY_UP => :up, KEY_DOWN => :down, KEY_LEFT => :left, KEY_RIGHT => :right, 'k' => :up, 'j' => :down, 'h' => :left, 'l' => :right, }.freeze
Instance Attribute Summary collapse
-
#game ⇒ Object
readonly
Returns the value of attribute game.
-
#game_x ⇒ Object
readonly
Returns the value of attribute game_x.
-
#game_y ⇒ Object
readonly
Returns the value of attribute game_y.
-
#windows ⇒ Object
readonly
Returns the value of attribute windows.
Instance Method Summary collapse
- #draw ⇒ Object
-
#initialize(game, theme:) ⇒ Gameboard
constructor
A new instance of Gameboard.
- #w_debug ⇒ Object
- #w_grid ⇒ Object
- #w_header ⇒ Object
- #w_instructions ⇒ Object
- #w_status ⇒ Object
Constructor Details
#initialize(game, theme:) ⇒ Gameboard
Returns a new instance of Gameboard.
27 28 29 30 31 32 |
# File 'lib/minesweeprb/gameboard.rb', line 27 def initialize(game, theme:) @game = game @theme = theme @active_square_sprite = theme.sprites[:active_square] build_color_map end |
Instance Attribute Details
#game ⇒ Object (readonly)
Returns the value of attribute game.
25 26 27 |
# File 'lib/minesweeprb/gameboard.rb', line 25 def game @game end |
#game_x ⇒ Object (readonly)
Returns the value of attribute game_x.
25 26 27 |
# File 'lib/minesweeprb/gameboard.rb', line 25 def game_x @game_x end |
#game_y ⇒ Object (readonly)
Returns the value of attribute game_y.
25 26 27 |
# File 'lib/minesweeprb/gameboard.rb', line 25 def game_y @game_y end |
#windows ⇒ Object (readonly)
Returns the value of attribute windows.
25 26 27 |
# File 'lib/minesweeprb/gameboard.rb', line 25 def windows @windows end |
Instance Method Details
#draw ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/minesweeprb/gameboard.rb', line 54 def draw setup_windows @timer_thread = Thread.new do loop do paint_header sleep(0.5) end end paint_grid paint_grid while process_input(w_grid.getch) ensure @timer_thread&.kill windows.each_value do |w| w.close rescue StandardError nil end @windows = nil end |
#w_debug ⇒ Object
50 51 52 |
# File 'lib/minesweeprb/gameboard.rb', line 50 def w_debug windows[:debug] end |
#w_grid ⇒ Object
38 39 40 |
# File 'lib/minesweeprb/gameboard.rb', line 38 def w_grid windows[:grid] end |
#w_header ⇒ Object
34 35 36 |
# File 'lib/minesweeprb/gameboard.rb', line 34 def w_header windows[:header] end |
#w_instructions ⇒ Object
46 47 48 |
# File 'lib/minesweeprb/gameboard.rb', line 46 def w_instructions windows[:instructions] end |
#w_status ⇒ Object
42 43 44 |
# File 'lib/minesweeprb/gameboard.rb', line 42 def w_status windows[:status] end |