Class: CodebreakerVk::GameMenu
Constant Summary
collapse
- START =
'start'
- RULES =
'rules'
- STATISTICS =
'stats'
- EXIT =
'exit'
Constants included
from Validation
Validation::MAX_LETTERS, Validation::MIN_LETTERS
Constants included
from Database
Database::SEED
Class Method Summary
collapse
Methods included from Validation
valid_string_length?
Methods included from Database
load, save, save_results
Methods included from Output
rules, start_info, summary_info
Class Method Details
.choose_difficulty ⇒ Object
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/codebreaker_vk/game_menu.rb', line 51
def choose_difficulty
loop do
puts I18n.t(:choose_difficulty)
input = gets.chomp
break close if input == EXIT
break input.to_sym if Game::DIFFICULTY_LEVEL.keys.include? input.to_sym
puts I18n.t(:wrong_difficulty)
end
end
|
.choose_name ⇒ Object
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/codebreaker_vk/game_menu.rb', line 40
def choose_name
loop do
puts I18n.t(:choose_name)
name = gets.chomp
break close if name == EXIT
break name if valid_string_length?(name)
puts I18n.t(:wrong_name)
end
end
|
.close ⇒ Object
70
71
72
73
|
# File 'lib/codebreaker_vk/game_menu.rb', line 70
def close
puts I18n.t(:goodbye)
exit
end
|
.registration ⇒ Object
35
36
37
38
|
# File 'lib/codebreaker_vk/game_menu.rb', line 35
def registration
GameConsole.new(choose_name, choose_difficulty).start
welcome
end
|
.run ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/codebreaker_vk/game_menu.rb', line 22
def run
loop do
puts I18n.t(:menu)
case gets.chomp
when START then break registration
when RULES then rules
when STATISTICS then stats
when EXIT then break close
else puts I18n.t(:wrong_run)
end
end
end
|
.stats ⇒ Object
62
63
64
65
66
67
68
|
# File 'lib/codebreaker_vk/game_menu.rb', line 62
def stats
return puts I18n.t(:no_stats) unless File.exist?('spec/fixtures/seed.yaml')
table = load.sort_by { |row| [row.hints_total, row.attempts_used] }
table.each { |row| row.difficulty = Game::DIFFICULTY_LEVEL.key([row.attempts_total, row.hints_total]) }
puts table
end
|
.welcome ⇒ Object
17
18
19
20
|
# File 'lib/codebreaker_vk/game_menu.rb', line 17
def welcome
puts I18n.t(:greeting)
run
end
|