class Codebreaker::Interface
Public Class Methods
new()
click to toggle source
# File lib/rk/codebreaker/interface.rb, line 8 def initialize @game = Game.new greeting end
Public Instance Methods
game_begin()
click to toggle source
# File lib/rk/codebreaker/interface.rb, line 13 def game_begin while @game.available_attempts > 0 guess = proposal_and_input next if hint_call?(guess) rez = @game.check_input(guess) puts rez break if win?(rez) end no_attempts unless @game.available_attempts > 0 save_result end
Private Instance Methods
hint_call?(code)
click to toggle source
# File lib/rk/codebreaker/interface.rb, line 44 def hint_call?(code) return false unless hint_input?(code) no_hint unless @game.hint puts @game.hint_answer true end
hint_input?(code)
click to toggle source
# File lib/rk/codebreaker/interface.rb, line 40 def hint_input?(code) code.to_s.match(/^h$/) end
new_game()
click to toggle source
# File lib/rk/codebreaker/interface.rb, line 33 def new_game user_answer = new_game_proposition return goodbye unless user_agree?(user_answer) @game = Game.new game_begin end
save_result()
click to toggle source
# File lib/rk/codebreaker/interface.rb, line 27 def save_result user_answer = save_result_proposition return new_game unless user_agree?(user_answer) @game.save_to_file("game_results.txt", username) end
user_agree?(answer)
click to toggle source
# File lib/rk/codebreaker/interface.rb, line 57 def user_agree?(answer) answer == 'y' end
win?(combination)
click to toggle source
# File lib/rk/codebreaker/interface.rb, line 51 def win?(combination) return false unless combination == '++++' lucky_combination true end