codebreaker_kirill 0.1.0 → 0.2.2
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/.rspec +1 -0
- data/Gemfile.lock +55 -0
- data/lib/codebreaker_kirill/autoload.rb +4 -0
- data/lib/codebreaker_kirill/game.rb +28 -0
- data/lib/codebreaker_kirill/guess_handler.rb +20 -0
- data/lib/codebreaker_kirill/user.rb +7 -0
- data/lib/codebreaker_kirill/version.rb +3 -1
- data/lib/codebreaker_kirill.rb +2 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3839ddc4449f1d11b65756055cc67909f2e2020eba4ac753da18621b0364e70a
|
4
|
+
data.tar.gz: a482b2c74a959576cbd4d430d53b31da91a8815ab35e1185a5c2b1f95cb21384
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb0881c6f1d920d2a9e94883bbe7abb1c2841232ddc23499599cf9e622f7a0f2e859b3e2fa4f17ca9b5e566ac8b426eb65452e1d83eee694db5e49445cbd3a60
|
7
|
+
data.tar.gz: 9c4bdb120ace9dd935fe39aa9d33e506c3170ca750c428319088b3ed42d7d35736ed8f01ce795abcd8c5aa7d14035707dab947227bedd9221a4d201bd1fb3a39
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
codebreaker_kirill (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.2)
|
10
|
+
diff-lcs (1.5.0)
|
11
|
+
json (2.6.2)
|
12
|
+
parallel (1.22.1)
|
13
|
+
parser (3.1.2.1)
|
14
|
+
ast (~> 2.4.1)
|
15
|
+
rainbow (3.1.1)
|
16
|
+
regexp_parser (2.5.0)
|
17
|
+
rexml (3.2.5)
|
18
|
+
rspec (3.11.0)
|
19
|
+
rspec-core (~> 3.11.0)
|
20
|
+
rspec-expectations (~> 3.11.0)
|
21
|
+
rspec-mocks (~> 3.11.0)
|
22
|
+
rspec-core (3.11.0)
|
23
|
+
rspec-support (~> 3.11.0)
|
24
|
+
rspec-expectations (3.11.0)
|
25
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
+
rspec-support (~> 3.11.0)
|
27
|
+
rspec-mocks (3.11.1)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.11.0)
|
30
|
+
rspec-support (3.11.0)
|
31
|
+
rubocop (1.35.0)
|
32
|
+
json (~> 2.3)
|
33
|
+
parallel (~> 1.10)
|
34
|
+
parser (>= 3.1.2.1)
|
35
|
+
rainbow (>= 2.2.2, < 4.0)
|
36
|
+
regexp_parser (>= 1.8, < 3.0)
|
37
|
+
rexml (>= 3.2.5, < 4.0)
|
38
|
+
rubocop-ast (>= 1.20.1, < 2.0)
|
39
|
+
ruby-progressbar (~> 1.7)
|
40
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
41
|
+
rubocop-ast (1.21.0)
|
42
|
+
parser (>= 3.1.1.0)
|
43
|
+
ruby-progressbar (1.11.0)
|
44
|
+
unicode-display_width (2.2.0)
|
45
|
+
|
46
|
+
PLATFORMS
|
47
|
+
universal-darwin-21
|
48
|
+
|
49
|
+
DEPENDENCIES
|
50
|
+
codebreaker_kirill!
|
51
|
+
rspec
|
52
|
+
rubocop (~> 1.21)
|
53
|
+
|
54
|
+
BUNDLED WITH
|
55
|
+
2.3.19
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "guess_handler"
|
4
|
+
require_relative "user"
|
5
|
+
|
6
|
+
class Game
|
7
|
+
include GuessHandler
|
8
|
+
|
9
|
+
attr_reader :secret_code
|
10
|
+
|
11
|
+
def initialize(user, difficulty)
|
12
|
+
@secret_code = (1..4).to_a.map { |_num| rand(1..6) }
|
13
|
+
@hint_array = @secret_code.map(&:clone)
|
14
|
+
@attempts = difficulty[:attempts]
|
15
|
+
@hints = {
|
16
|
+
hints_available: difficulty[:hints],
|
17
|
+
hints_used: 0
|
18
|
+
}
|
19
|
+
@name = user.name
|
20
|
+
end
|
21
|
+
|
22
|
+
def give_a_hint
|
23
|
+
return @hints[:hints_available].zero ? 0 : @hint_array[0]
|
24
|
+
@hint_array.shift
|
25
|
+
@hints[:hints_available] -= 1
|
26
|
+
@hints[:hints_used]
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GuessHandler
|
4
|
+
def respond_to_guess(user, input, code)
|
5
|
+
result = []
|
6
|
+
numbers = input.split("").map(&:to_i)
|
7
|
+
|
8
|
+
return "win" if numbers == code
|
9
|
+
|
10
|
+
numbers.each_with_index do |element, index|
|
11
|
+
if element == code[index]
|
12
|
+
result << "+"
|
13
|
+
elsif code.include?(element)
|
14
|
+
result << "-"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
user.attempts.zero ? "loss" : result
|
19
|
+
end
|
20
|
+
end
|
data/lib/codebreaker_kirill.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codebreaker_kirill
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kirill Dudchenko
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-08-
|
11
|
+
date: 2022-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -17,13 +17,19 @@ executables: []
|
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
|
+
- ".rspec"
|
20
21
|
- ".rubocop.yml"
|
21
22
|
- CHANGELOG.md
|
22
23
|
- Gemfile
|
24
|
+
- Gemfile.lock
|
23
25
|
- LICENSE.txt
|
24
26
|
- README.md
|
25
27
|
- Rakefile
|
26
28
|
- lib/codebreaker_kirill.rb
|
29
|
+
- lib/codebreaker_kirill/autoload.rb
|
30
|
+
- lib/codebreaker_kirill/game.rb
|
31
|
+
- lib/codebreaker_kirill/guess_handler.rb
|
32
|
+
- lib/codebreaker_kirill/user.rb
|
27
33
|
- lib/codebreaker_kirill/version.rb
|
28
34
|
- sig/codebreaker_kirill.rbs
|
29
35
|
homepage:
|