Class: Minesweeprb::Commands::Play

Inherits:
Object
  • Object
show all
Includes:
Curses
Defined in:
lib/minesweeprb/commands/play.rb

Constant Summary collapse

SIZES =
[
  # [ label, width, height, # of mines ]
  ['Tiny',    5,  5, 3],
  ['Small',   9,  9, 10],
  ['Medium', 13, 13, 15],
  ['Large',  17, 17, 20],
  ['Huge',   21, 21, 25],
].map { |label, width, height, mines| GameTemplate.new(label:, width:, height:, mines:) }.freeze
BOARD_CHROME_ROWS =

Gameboard chrome: 1 top margin + 1 header + 1 gap + grid + 1 gap + 1 status + 1 gap + 1 instructions

7

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Play

Returns a new instance of Play.



23
24
25
26
# File 'lib/minesweeprb/commands/play.rb', line 23

def initialize(options)
  @options = options
  @theme = @options[:theme] ? Theme[@options[:theme]] : Theme.default
end

Instance Method Details

#executeObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/minesweeprb/commands/play.rb', line 28

def execute
  init_screen
  use_default_colors
  start_color
  curs_set(0)
  noecho
  self.ESCDELAY = 1
  mousemask(BUTTON1_CLICKED | BUTTON2_CLICKED | BUTTON3_CLICKED | BUTTON4_CLICKED)

  loop do
    template = prompt_size
    break if template.nil?

    game = Game.new(**template.to_h, sprites: @theme.sprites)
    Gameboard.new(game, theme: @theme).draw
  end
ensure
  close_screen
end