codebreaker_kirill 0.2.14 → 0.2.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/codebreaker_kirill/code_generator.rb +2 -0
- data/lib/codebreaker_kirill/game.rb +2 -1
- data/lib/codebreaker_kirill/guess_handler.rb +13 -3
- data/lib/codebreaker_kirill/settings.rb +4 -4
- data/lib/codebreaker_kirill/stats.rb +7 -5
- data/lib/codebreaker_kirill/user.rb +3 -2
- data/lib/codebreaker_kirill/validations.rb +5 -1
- data/lib/codebreaker_kirill/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca2a9e18040569430affe912a91553e4b75111ac9e269b0c88a536a9ba9a3fe1
|
4
|
+
data.tar.gz: 3c4b4c50a303aba79aa4191f9c7fd7795acae84fa0eab6fa59ffa611cfec7e7b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e332c34663d075529458200c45e368068d2cd11763f24599bcd07a91faef64a4776b5cc1f2a8747223f2a72b840ec033da61fe43dcc68d2562bf965e2fbab139
|
7
|
+
data.tar.gz: f40c63b83eb5f3b67bdc103efe9c64e822db52efe3c8cb8542997008385714108d28df8bd5fee84ca2a0bf706f0e386ab84e30b4f5e26887077ce73fdbc03daa
|
@@ -3,15 +3,14 @@
|
|
3
3
|
module GuessHandler
|
4
4
|
def respond_to_guess(game, input, code)
|
5
5
|
validate_guess(input)
|
6
|
+
return game.give_a_hint if input == "hint"
|
6
7
|
@result = []
|
7
8
|
@code_clone = code.clone
|
8
9
|
@numbers = input.split('').map(&:to_i)
|
9
10
|
return 'win' if @numbers == code
|
10
11
|
|
11
12
|
assess_guess(@code_clone, @numbers)
|
12
|
-
|
13
|
-
game.attempts[:used] += 1
|
14
|
-
game.attempts[:used] >= game.attempts[:all] ? 'loss' : @result.delete_if { |value| (1..6).include?(value) }.sort
|
13
|
+
attempts_handler(game)
|
15
14
|
end
|
16
15
|
|
17
16
|
def assess_guess(code, input)
|
@@ -27,4 +26,15 @@ module GuessHandler
|
|
27
26
|
input.slice!(@numbers.index(el)) end
|
28
27
|
end
|
29
28
|
end
|
29
|
+
|
30
|
+
def attempts_handler(game)
|
31
|
+
game.user.attempts[:used] += 1
|
32
|
+
if game.user.attempts[:used] >= game.user.attempts[:all]
|
33
|
+
'loss'
|
34
|
+
else
|
35
|
+
@result.delete_if do |value|
|
36
|
+
(1..6).include?(value)
|
37
|
+
end.sort
|
38
|
+
end
|
39
|
+
end
|
30
40
|
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
+
module Settings
|
3
4
|
LEVEL = {
|
4
5
|
'easy' => { attempts: 15, hints: 2 },
|
5
6
|
'medium' => { attempts: 10, hints: 1 },
|
6
7
|
'hell' => { attempts: 5, hints: 1 }
|
7
|
-
}
|
8
|
+
}.freeze
|
8
9
|
CODE_LENGTH = 4
|
9
|
-
RANDOM_RANGE = (1..6)
|
10
|
-
|
10
|
+
RANDOM_RANGE = (1..6).freeze
|
11
11
|
end
|
@@ -1,13 +1,15 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Stats
|
2
4
|
def self.save_game(user)
|
3
|
-
@data = File.exist?(
|
5
|
+
@data = File.exist?('stats.yml') ? YAML.load_file('stats.yml') : []
|
4
6
|
@data << user
|
5
|
-
File.new(
|
6
|
-
File.open(
|
7
|
+
File.new('stats.yml', 'w') unless File.exist?('stats.yml')
|
8
|
+
File.open('stats.yml', 'w') { |file| file.write(@data.to_yaml) }
|
7
9
|
end
|
8
10
|
|
9
11
|
def self.show_stats
|
10
|
-
@data = File.exist?(
|
12
|
+
@data = File.exist?('stats.yml') ? YAML.load_file('stats.yml') : []
|
11
13
|
print @data
|
12
14
|
end
|
13
15
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Validations
|
2
4
|
def validate_name(name)
|
3
5
|
raise "Name shouldn't be empty" if name.empty?
|
@@ -14,6 +16,8 @@ module Validations
|
|
14
16
|
|
15
17
|
def validate_difficulty(difficulty)
|
16
18
|
raise "Input shouldn't be empty" if difficulty.empty?
|
17
|
-
|
19
|
+
return if difficulty.match?(/easy|medium|hell/)
|
20
|
+
|
21
|
+
raise 'You should enter one of the following options: easy, medium, hell'
|
18
22
|
end
|
19
23
|
end
|