class Console
Attributes
user_code[RW]
Public Class Methods
new()
click to toggle source
# File lib/console.rb, line 8 def initialize @user_code = [] end
Public Instance Methods
run()
click to toggle source
# File lib/console.rb, line 12 def run show_welcome main_menu end
Private Instance Methods
_get_difficulty_level()
click to toggle source
# File lib/console.rb, line 80 def _get_difficulty_level show_msg(:EnterDifficulty) answer = user_enter return answer if DIFFICULTIES.include?(answer.to_sym) show_msg(:InvalidCommand) _get_difficulty_level end
_get_name()
click to toggle source
# File lib/console.rb, line 70 def _get_name show_msg(:EnterName) answer = user_enter return answer if valid_name?(answer) show_msg(:InvalidCommand) _get_name end
check_code(answer)
click to toggle source
# File lib/console.rb, line 60 def check_code(answer) result = game.result(answer) puts result result end
exit?(answer)
click to toggle source
# File lib/console.rb, line 115 def exit?(answer) answer == EXIT_COMMAND end
game()
click to toggle source
# File lib/console.rb, line 119 def game CurrentGame.game end
game_scenario()
click to toggle source
# File lib/console.rb, line 33 def game_scenario loop do return lost if game.lost? show_msg(:AccompanyingMsg) process_answer_game(user_enter) end end
lost()
click to toggle source
# File lib/console.rb, line 100 def lost show_msg(:Loss) puts game.secret_code.join main_menu end
process_answer_game(answer)
click to toggle source
# File lib/console.rb, line 42 def process_answer_game(answer) case answer when /^[1-6]{4}$/ return won if game.won?(check_code(answer)) when 'hint' then request_of_hint else show_msg(:InvalidCommand) end end
registration()
click to toggle source
# File lib/console.rb, line 66 def registration CodebreakerParatskiy.run_game(_get_name, _get_difficulty_level) end
request_of_hint()
click to toggle source
# File lib/console.rb, line 56 def request_of_hint game.hints.zero? ? show_msg(:HintsEnded) : (puts game.use_hint) end
save_result?()
click to toggle source
# File lib/console.rb, line 89 def save_result? show_msg(:SaveResult) user_enter == CONFIRM_COMMAND end
start()
click to toggle source
# File lib/console.rb, line 28 def start registration game_scenario end
user_enter()
click to toggle source
# File lib/console.rb, line 106 def user_enter enter = gets.chomp.downcase if exit?(enter) show_msg(:Exit) exit end enter end
won()
click to toggle source
# File lib/console.rb, line 94 def won show_msg(:Won) game.save_result if save_result? main_menu end