Module: CodeBreakerGemHoltobinAnton::DataCheck

Included in:
Game
Defined in:
lib/code_breaker_gem_holtobin_anton.rb

Instance Method Summary collapse

Instance Method Details

#check_attempts_ended?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/code_breaker_gem_holtobin_anton.rb', line 16

def check_attempts_ended?
  @choice_did >= @choice_size? true : false
end

#check_for_matchObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/code_breaker_gem_holtobin_anton.rb', line 20

def check_for_match
  secr_temp, user_temp = @secret_code.clone, @user_code.clone
  secr_temp.each_char.with_index(index = 0) do |item, index|
    if item == user_temp[index]
      secr_temp[index],user_temp[index] = '0', '0'
      @result << '+'
    end
  end

  secr_temp.each_char do |item|
    next if item == '0'
    if user_temp.include?(item)
      @result << '-'
      secr_temp.gsub!(item,'0')
    end
  end
end

#check_victory?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/code_breaker_gem_holtobin_anton.rb', line 12

def check_victory?
  @secret_code.eql?(@user_code)
end

#data_checking?(data) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
9
10
# File 'lib/code_breaker_gem_holtobin_anton.rb', line 6

def data_checking?(data)
  hint if data.capitalize == 'Hint'
  exit if data.capitalize == 'Exit'
  data =~ /(^([1-6]{4})$)/? false : true
end