Class: Minesweeprb::Gameboard

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#gameObject (readonly)

Returns the value of attribute game.



47
48
49
# File 'lib/minesweeprb/gameboard.rb', line 47

def game
  @game
end

#game_xObject (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_yObject (readonly)

Returns the value of attribute game_y.



47
48
49
# File 'lib/minesweeprb/gameboard.rb', line 47

def game_y
  @game_y
end

#windowsObject (readonly)

Returns the value of attribute windows.



47
48
49
# File 'lib/minesweeprb/gameboard.rb', line 47

def windows
  @windows
end

Instance Method Details

#clearObject



87
88
89
# File 'lib/minesweeprb/gameboard.rb', line 87

def clear
  close_screen
end

#drawObject



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_debugObject



70
71
72
# File 'lib/minesweeprb/gameboard.rb', line 70

def w_debug
  windows[:debug]
end

#w_gridObject



58
59
60
# File 'lib/minesweeprb/gameboard.rb', line 58

def w_grid
  windows[:grid]
end

#w_headerObject



54
55
56
# File 'lib/minesweeprb/gameboard.rb', line 54

def w_header
  windows[:header]
end

#w_instructionsObject



66
67
68
# File 'lib/minesweeprb/gameboard.rb', line 66

def w_instructions
  windows[:instructions]
end

#w_statusObject



62
63
64
# File 'lib/minesweeprb/gameboard.rb', line 62

def w_status
  windows[:status]
end