Class: CodebreakerRostik::Console

Inherits:
Object
  • Object
show all
Includes:
ConsoleHelpers, Validator
Defined in:
lib/console.rb

Constant Summary collapse

OPTIONS =
{
  start: 'Start',
  rules: 'Rules',
  stats: 'Stats',
  exit: 'Exit'
}.freeze
GAME_RESULTS =
{
  win: '++++',
  lose: '----'
}.freeze
NAME_DIFFICULTIES =
%w[Easy Medium Hell].freeze
COUNT_ATTEMPTS =
0
COUNT_HINTS =
0
ANSWERS =
{
  yes: 'Yes'
}.freeze
NAME_LENGTH_RANGE =
(3..20).freeze
HINT =
'Hint'.freeze
EXIT =
'Exit'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Validator

#valid_length?, #validate_class?, #validate_each_char_in_range?, #validate_length_range?

Methods included from ConsoleHelpers

#bye, #show_info

Instance Attribute Details

#info_difficultObject (readonly)

Returns the value of attribute info_difficult.



6
7
8
# File 'lib/console.rb', line 6

def info_difficult
  @info_difficult
end

#userObject (readonly)

Returns the value of attribute user.



6
7
8
# File 'lib/console.rb', line 6

def user
  @user
end

#user_nameObject (readonly)

Returns the value of attribute user_name.



6
7
8
# File 'lib/console.rb', line 6

def user_name
  @user_name
end

Instance Method Details

#check_optionObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/console.rb', line 28

def check_option
  show_info(:welcome)
  loop do
    case show_message_with_input(:choose_option)
    when OPTIONS[:start] then return registration
    when OPTIONS[:rules] then show_rules
    when OPTIONS[:stats] then show_stats
    else
      show_info(:wrong_input_option)
    end
  end
end

#show_message_with_input(message, key = nil) ⇒ Object



41
42
43
44
45
# File 'lib/console.rb', line 41

def show_message_with_input(message, key = nil)
  show_info(message, key)
  value = gets.chomp.capitalize
  value == OPTIONS[:exit] ? bye : value
end