codebreaker_kirill 0.2.2 → 0.2.5
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/.rubocop.yml +2 -7
- data/Gemfile +3 -3
- data/Rakefile +2 -2
- data/lib/codebreaker_kirill/autoload.rb +2 -2
- data/lib/codebreaker_kirill/game.rb +10 -12
- data/lib/codebreaker_kirill/guess_handler.rb +11 -7
- data/lib/codebreaker_kirill/user.rb +2 -0
- data/lib/codebreaker_kirill/version.rb +2 -2
- data/lib/codebreaker_kirill.rb +3 -3
- 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: 822dd661933b64d2f99a3bdeb15e4131c45bd41d0c483f0173b06e5c4f2251e0
|
4
|
+
data.tar.gz: f61020913965d8c136d6941452f5f445758217d1ef04bd0aee44058103d9f071
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 108baa4707873a9f04be27fdc96928a165770089ebdc215358f301b334ec711440e09cf9cd38fa8726c1f54c0e3b66d87d54f8cb1b18354eb394c0745b979c82
|
7
|
+
data.tar.gz: 9bcc28298a06ae3edfc8163c057a3681ce9c524f83a23b3a30aa04445f4476cb07dcdc146634aee8d3b9cfc0964956b24f7e7f481cdfc561ce33926f58055efa
|
data/.rubocop.yml
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
AllCops:
|
2
2
|
TargetRubyVersion: 2.6
|
3
3
|
|
4
|
-
Style/
|
5
|
-
Enabled:
|
6
|
-
EnforcedStyle: double_quotes
|
7
|
-
|
8
|
-
Style/StringLiteralsInInterpolation:
|
9
|
-
Enabled: true
|
10
|
-
EnforcedStyle: double_quotes
|
4
|
+
Style/Documentation:
|
5
|
+
Enabled: false
|
11
6
|
|
12
7
|
Layout/LineLength:
|
13
8
|
Max: 120
|
data/Gemfile
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
source
|
3
|
+
source 'https://rubygems.org'
|
4
4
|
|
5
5
|
# Specify your gem's dependencies in codebreaker_kirill.gemspec
|
6
6
|
gemspec
|
7
7
|
|
8
|
-
gem
|
8
|
+
gem 'rspec'
|
9
9
|
|
10
|
-
gem
|
10
|
+
gem 'rubocop', '~> 1.21'
|
data/Rakefile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
4
|
-
require_relative
|
3
|
+
require_relative 'guess_handler'
|
4
|
+
require_relative 'user'
|
5
5
|
|
6
6
|
class Game
|
7
7
|
include GuessHandler
|
@@ -10,19 +10,17 @@ class Game
|
|
10
10
|
|
11
11
|
def initialize(user, difficulty)
|
12
12
|
@secret_code = (1..4).to_a.map { |_num| rand(1..6) }
|
13
|
-
@
|
14
|
-
@attempts = difficulty[:attempts]
|
15
|
-
@hints = {
|
16
|
-
hints_available: difficulty[:hints],
|
17
|
-
hints_used: 0
|
18
|
-
}
|
13
|
+
@hint_counter = 0
|
14
|
+
@attempts = { available: difficulty[:attempts], used: 0 }
|
15
|
+
@hints = { available: difficulty[:hints], used: 0 }
|
19
16
|
@name = user.name
|
20
17
|
end
|
21
18
|
|
22
19
|
def give_a_hint
|
23
|
-
return @hints[:
|
24
|
-
|
25
|
-
@hints[:
|
26
|
-
@hints[:
|
20
|
+
return 0 if @hints[:available].zero?
|
21
|
+
|
22
|
+
@hints[:available] -= 1
|
23
|
+
@hints[:used] += 1
|
24
|
+
@secret_code[@hints[:used]]
|
27
25
|
end
|
28
26
|
end
|
@@ -1,20 +1,24 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module GuessHandler
|
4
|
-
def respond_to_guess(
|
4
|
+
def respond_to_guess(game, input, code)
|
5
5
|
result = []
|
6
|
-
numbers = input.split(
|
6
|
+
numbers = input.split('').map(&:to_i)
|
7
|
+
return 'win' if numbers == code
|
7
8
|
|
8
|
-
|
9
|
+
game.assess_guess(numbers, code)
|
10
|
+
game.attempts[:available] -= 1
|
11
|
+
game.attempts[:used] += 1
|
12
|
+
game.attempts[:available].zero ? 'loss' : result
|
13
|
+
end
|
9
14
|
|
15
|
+
def assess_guess(numbers, code)
|
10
16
|
numbers.each_with_index do |element, index|
|
11
17
|
if element == code[index]
|
12
|
-
result <<
|
18
|
+
result << '+'
|
13
19
|
elsif code.include?(element)
|
14
|
-
result <<
|
20
|
+
result << '-'
|
15
21
|
end
|
16
22
|
end
|
17
|
-
|
18
|
-
user.attempts.zero ? "loss" : result
|
19
23
|
end
|
20
24
|
end
|
data/lib/codebreaker_kirill.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
4
|
-
require_relative
|
5
|
-
require_relative
|
3
|
+
require_relative 'codebreaker_kirill/version'
|
4
|
+
require_relative 'codebreaker_kirill/game'
|
5
|
+
require_relative 'codebreaker_kirill/user'
|
6
6
|
|
7
7
|
module CodebreakerKirill
|
8
8
|
class Error < StandardError; end
|