Class: Minesweeper::Ui

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Singleton
Defined in:
lib/minesweeper/ui.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.method_missing(method_name, *arguments, &block) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/minesweeper/ui.rb', line 11

def self.method_missing(method_name, *arguments, &block)
  if instance.respond_to?(method_name)
    instance.send(method_name, *arguments, &block)
  else
    super
  end
end

.respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/minesweeper/ui.rb', line 19

def self.respond_to_missing?(method_name, include_private = false)
  instance.respond_to?(:method_name) || super
end

Instance Method Details

#col_numObject



39
40
41
# File 'lib/minesweeper/ui.rb', line 39

def col_num
  addstr('Number of columns: ')
end

#greeting_messageObject



25
26
27
28
29
30
31
32
33
# File 'lib/minesweeper/ui.rb', line 25

def greeting_message
  clear
  enable_keypad
  refresh
  addch("\n")
  addstr("Welcome to Minesweeper \n")
  addstr("screen size: rows: #{window.maxy}; columns: #{window.maxx / Minesweeper::Board::STEP} \n")
  addstr("controls: `space` to mark/unmark cell as bomb, `arrow keys` to navigate \n")
end

#levelObject



47
48
49
# File 'lib/minesweeper/ui.rb', line 47

def level
  addstr('Your Level (beginner/advanced/expert): ')
end

#params_messageObject



35
36
37
# File 'lib/minesweeper/ui.rb', line 35

def params_message
  addstr('Start game with default parameters? (Y/N)')
end

#row_numObject



43
44
45
# File 'lib/minesweeper/ui.rb', line 43

def row_num
  addstr('Number of rows: ')
end

#validation_errors(errors) ⇒ Object



51
52
53
54
55
56
# File 'lib/minesweeper/ui.rb', line 51

def validation_errors(errors)
  clear
  addstr("Some of the parameters were invalid \n")
  addstr(errors.full_messages.join("\n"))
  addstr("\n")
end

#windowObject



58
59
60
# File 'lib/minesweeper/ui.rb', line 58

def window
  @window ||= Window.new(0, 0, 0, 0)
end