class MastermindSuzan::Validation
Attributes
guess[RW]
player[RW]
Public Class Methods
new(player)
click to toggle source
# File lib/mastermind_suzan/validation.rb, line 10 def initialize(player) @player = player end
Public Instance Methods
check_replay_input()
click to toggle source
# File lib/mastermind_suzan/validation.rb, line 31 def check_replay_input player_input = gets.chomp.downcase if player_input == "p" || player_input == "play" GameEngine.new.start else exit end end
check_valid_input?(guess)
click to toggle source
# File lib/mastermind_suzan/validation.rb, line 40 def check_valid_input?(guess) history_cheat_view_arr = %w(h c history cheat) return true if history_cheat_view_arr.include? guess guess.length == player.gamecolor.length end
collect_guess()
click to toggle source
# File lib/mastermind_suzan/validation.rb, line 14 def collect_guess loop do @guess = gets.chomp.downcase break if check_valid_input?(guess) input_error(guess.length) end guess.split("") end
input_error(guess_length)
click to toggle source
# File lib/mastermind_suzan/validation.rb, line 23 def input_error(guess_length) if guess_length < player.gamecolor.length puts short_input else puts long_input end end