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
- QUIT =
['q', 27].freeze
- MOVE =
{ KEY_UP => :up, KEY_DOWN => :down, KEY_LEFT => :left, KEY_RIGHT => :right, 'k' => :up, 'j' => :down, 'h' => :left, 'l' => :right, }.freeze
- COLORS =
{ win: [A_BOLD | COLOR_GREEN], lose: [A_BOLD | COLOR_MAGENTA], Game::SPRITES[:clock] => [A_BOLD | COLOR_CYAN], Game::SPRITES[:win_face] => [A_BOLD | COLOR_YELLOW], Game::SPRITES[:lose_face] => [A_BOLD | COLOR_RED], Game::SPRITES[:play_face] => [A_BOLD | COLOR_CYAN], Game::SPRITES[:mine] => [A_BOLD | COLOR_RED], Game::SPRITES[:flag] => [A_BOLD | COLOR_RED], Game::SPRITES[:mark] => [A_BOLD | COLOR_MAGENTA], Game::SPRITES[:clues][0] => [COLOR_BLACK], Game::SPRITES[:clues][1] => [COLOR_BLUE], Game::SPRITES[:clues][2] => [COLOR_GREEN], Game::SPRITES[:clues][3] => [COLOR_MAGENTA], Game::SPRITES[:clues][4] => [COLOR_CYAN], Game::SPRITES[:clues][5] => [COLOR_RED], Game::SPRITES[:clues][6] => [COLOR_YELLOW], Game::SPRITES[:clues][7] => [A_BOLD | COLOR_MAGENTA], Game::SPRITES[:clues][8] => [A_BOLD | COLOR_RED], }.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
- #clear ⇒ Object
- #draw ⇒ Object
-
#initialize(game) ⇒ 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) ⇒ Gameboard
Returns a new instance of Gameboard.
49 50 51 52 |
# File 'lib/minesweeprb/gameboard.rb', line 49 def initialize(game) @game = game setup_curses end |
Instance Attribute Details
#game ⇒ Object (readonly)
Returns the value of attribute game.
47 48 49 |
# File 'lib/minesweeprb/gameboard.rb', line 47 def game @game end |
#game_x ⇒ Object (readonly)
Returns the value of attribute game_x.
47 48 49 |
# File 'lib/minesweeprb/gameboard.rb', line 47 def game_x @game_x end |
#game_y ⇒ Object (readonly)
Returns the value of attribute game_y.
47 48 49 |
# File 'lib/minesweeprb/gameboard.rb', line 47 def game_y @game_y end |
#windows ⇒ Object (readonly)
Returns the value of attribute windows.
47 48 49 |
# File 'lib/minesweeprb/gameboard.rb', line 47 def windows @windows end |
Instance Method Details
#clear ⇒ Object
87 88 89 |
# File 'lib/minesweeprb/gameboard.rb', line 87 def clear close_screen end |
#draw ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/minesweeprb/gameboard.rb', line 74 def draw # paint_debug Thread.new do loop do paint_header sleep(0.5) end end paint_grid paint_grid while process_input(w_grid.getch) end |
#w_debug ⇒ Object
70 71 72 |
# File 'lib/minesweeprb/gameboard.rb', line 70 def w_debug windows[:debug] end |
#w_grid ⇒ Object
58 59 60 |
# File 'lib/minesweeprb/gameboard.rb', line 58 def w_grid windows[:grid] end |
#w_header ⇒ Object
54 55 56 |
# File 'lib/minesweeprb/gameboard.rb', line 54 def w_header windows[:header] end |
#w_instructions ⇒ Object
66 67 68 |
# File 'lib/minesweeprb/gameboard.rb', line 66 def w_instructions windows[:instructions] end |
#w_status ⇒ Object
62 63 64 |
# File 'lib/minesweeprb/gameboard.rb', line 62 def w_status windows[:status] end |