Class: CodebreakerRostik::Game
- Inherits:
-
Object
- Object
- CodebreakerRostik::Game
show all
- Includes:
- Validator
- Defined in:
- lib/game.rb
Constant Summary
collapse
- LENGTH_GUESS_CODE =
4
- RANGE_GUESS_CODE =
(1..6).freeze
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Validator
#valid_length?, #validate_class?, #validate_each_char_in_range?, #validate_length_range?
Constructor Details
#initialize ⇒ Game
Returns a new instance of Game.
9
10
11
12
13
14
|
# File 'lib/game.rb', line 9
def initialize
@hints_left = 0
@attempts_left = 0
@secret_code = generate_secrete_code
@secret_code_for_hints = @secret_code.clone.shuffle
end
|
Instance Attribute Details
#attempts_left ⇒ Object
Returns the value of attribute attempts_left.
4
5
6
|
# File 'lib/game.rb', line 4
def attempts_left
@attempts_left
end
|
#hints_left ⇒ Object
Returns the value of attribute hints_left.
4
5
6
|
# File 'lib/game.rb', line 4
def hints_left
@hints_left
end
|
#secret_code ⇒ Object
Returns the value of attribute secret_code.
4
5
6
|
# File 'lib/game.rb', line 4
def secret_code
@secret_code
end
|
#secret_code_for_hints ⇒ Object
Returns the value of attribute secret_code_for_hints.
4
5
6
|
# File 'lib/game.rb', line 4
def secret_code_for_hints
@secret_code_for_hints
end
|
Instance Method Details
#attempts_left_increase(user) ⇒ Object
32
33
34
|
# File 'lib/game.rb', line 32
def attempts_left_increase(user)
user[:attempts_left] += 1
end
|
#attempts_left_increment ⇒ Object
28
29
30
|
# File 'lib/game.rb', line 28
def attempts_left_increment
@attempts_left += 1
end
|
#compare_guess_and_secret_codes(guess_code) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/game.rb', line 41
def compare_guess_and_secret_codes(guess_code)
@result_signs = ''
double_secret_code = @secret_code.clone
code_arr = guess_code.split('').map(&:to_i)
double_guess_code = code_arr
check_same_index(code_arr, double_secret_code, double_guess_code)
[double_secret_code, double_guess_code].each(&:compact!)
check_different_index(double_guess_code, double_secret_code)
@result_signs
end
|
#give_digit_hint ⇒ Object
36
37
38
39
|
# File 'lib/game.rb', line 36
def give_digit_hint
@hints_left += 1
@secret_code_for_hints.pop
end
|
#hints_left_increase(user) ⇒ Object
20
21
22
|
# File 'lib/game.rb', line 20
def hints_left_increase(user)
user[:hints_left] += 1
end
|
#hints_left_increment ⇒ Object
24
25
26
|
# File 'lib/game.rb', line 24
def hints_left_increment
@hints_left += 1
end
|
#valid_guess_code?(guess_code) ⇒ Boolean
16
17
18
|
# File 'lib/game.rb', line 16
def valid_guess_code?(guess_code)
validate_each_char_in_range?(guess_code.split(''), RANGE_GUESS_CODE) && valid_length?(guess_code, LENGTH_GUESS_CODE)
end
|