codebreaker_vv 0.2.0 → 1.0.0
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 +11 -0
- data/Gemfile +0 -6
- data/Gemfile.lock +2 -11
- data/README.md +2 -24
- data/codebreaker.gemspec +3 -2
- data/lib/codebreaker/version.rb +2 -4
- data/lib/codebreaker.rb +54 -61
- data/lib/src/autoloader.rb +2 -1
- data/lib/src/data_base_manager.rb +1 -7
- data/lib/src/factory.rb +1 -1
- metadata +8 -10
- data/.idea/.gitignore +0 -8
- data/.idea/codebreaker.iml +0 -46
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77eb940969009562c9d6490b4cceec06233b79d01fadf14ddd20cc23db834b3e
|
4
|
+
data.tar.gz: 9b8bd99eab675c16e6a91989d239fbcfa6aab90769a43e33a1fffaed386208d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4fcefb21e16484ad27714ecca6fd32a4832661a295a909b1f805f70674a46ca688541cffff804be79fe09a79660b38439db6db033224b8fadc0bf5af3ba9f6b
|
7
|
+
data.tar.gz: 8d98d3eef5524add83d4875fd11d2beb126cf9b5890e4b481d85ecff49e41d0a2c295ad77265ef2ff7208f06224b62e30f9a702bb6b0f5b7517ee46c41786ea7
|
data/.rubocop.yml
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
codebreaker_vv (0.
|
4
|
+
codebreaker_vv (0.2.0)
|
5
5
|
fasterer (~> 0.9.0)
|
6
|
-
|
6
|
+
rspec
|
7
7
|
rubocop (~> 1.21)
|
8
8
|
simplecov (~> 0.21.2)
|
9
9
|
|
@@ -11,7 +11,6 @@ GEM
|
|
11
11
|
remote: https://rubygems.org/
|
12
12
|
specs:
|
13
13
|
ast (2.4.2)
|
14
|
-
coderay (1.1.3)
|
15
14
|
colorize (0.8.1)
|
16
15
|
diff-lcs (1.5.0)
|
17
16
|
docile (1.4.0)
|
@@ -19,15 +18,10 @@ GEM
|
|
19
18
|
colorize (~> 0.7)
|
20
19
|
ruby_parser (>= 3.14.1)
|
21
20
|
json (2.6.2)
|
22
|
-
method_source (1.0.0)
|
23
21
|
parallel (1.22.1)
|
24
22
|
parser (3.1.2.1)
|
25
23
|
ast (~> 2.4.1)
|
26
|
-
pry (0.14.1)
|
27
|
-
coderay (~> 1.1)
|
28
|
-
method_source (~> 1.0)
|
29
24
|
rainbow (3.1.1)
|
30
|
-
rake (13.0.6)
|
31
25
|
regexp_parser (2.5.0)
|
32
26
|
rexml (3.2.5)
|
33
27
|
rspec (3.11.0)
|
@@ -72,9 +66,6 @@ PLATFORMS
|
|
72
66
|
|
73
67
|
DEPENDENCIES
|
74
68
|
codebreaker_vv!
|
75
|
-
rake (~> 13.0)
|
76
|
-
rspec (~> 3.0)
|
77
|
-
simplecov
|
78
69
|
|
79
70
|
BUNDLED WITH
|
80
71
|
2.3.7
|
data/README.md
CHANGED
@@ -1,35 +1,13 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/codebreaker`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
1
|
+
# Codebreaker_vv
|
6
2
|
|
7
3
|
## Installation
|
8
4
|
|
9
5
|
Add this line to your application's Gemfile:
|
10
6
|
|
11
7
|
```ruby
|
12
|
-
gem '
|
8
|
+
gem 'codebreaker_vv'
|
13
9
|
```
|
14
10
|
|
15
11
|
And then execute:
|
16
12
|
|
17
13
|
$ bundle install
|
18
|
-
|
19
|
-
Or install it yourself as:
|
20
|
-
|
21
|
-
$ gem install codebreaker
|
22
|
-
|
23
|
-
## Usage
|
24
|
-
|
25
|
-
TODO: Write usage instructions here
|
26
|
-
|
27
|
-
## Development
|
28
|
-
|
29
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
-
|
31
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
-
|
33
|
-
## Contributing
|
34
|
-
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/codebreaker.
|
data/codebreaker.gemspec
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative 'lib/codebreaker/version'
|
2
|
+
require_relative 'lib/src/autoloader'
|
2
3
|
|
3
4
|
Gem::Specification.new do |spec|
|
4
5
|
spec.name = 'codebreaker_vv'
|
@@ -7,7 +8,7 @@ Gem::Specification.new do |spec|
|
|
7
8
|
spec.email = ['valerii.radzhabov@rubygarage.org']
|
8
9
|
|
9
10
|
spec.summary = 'Codebreaker game'
|
10
|
-
spec.description = 'This awesome gem can create a secret code and a lot of other
|
11
|
+
spec.description = 'This awesome gem can create a secret code and a lot of other beautiful things!'
|
11
12
|
spec.homepage = 'https://rubygems.org/gems/codebreaker_vv'
|
12
13
|
spec.required_ruby_version = '>= 3.1'
|
13
14
|
|
@@ -30,7 +31,7 @@ Gem::Specification.new do |spec|
|
|
30
31
|
|
31
32
|
# Uncomment to register a new dependency of your gem
|
32
33
|
spec.add_dependency 'fasterer', '~> 0.9.0'
|
33
|
-
spec.add_dependency '
|
34
|
+
spec.add_dependency 'rspec'
|
34
35
|
spec.add_dependency 'rubocop', '~> 1.21'
|
35
36
|
spec.add_dependency 'simplecov', '~> 0.21.2'
|
36
37
|
|
data/lib/codebreaker/version.rb
CHANGED
data/lib/codebreaker.rb
CHANGED
@@ -1,77 +1,70 @@
|
|
1
|
-
# require_relative 'codebreaker/version'
|
2
1
|
require_relative 'src/autoloader'
|
3
2
|
|
4
|
-
|
5
|
-
|
3
|
+
class Codebreaker
|
4
|
+
attr_reader :secret_code, :attempts, :hints
|
6
5
|
|
7
|
-
|
8
|
-
|
6
|
+
def initialize
|
7
|
+
@data_base_manager = DataBaseManager.new
|
8
|
+
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
generate_secret_code
|
19
|
-
end
|
10
|
+
def start_game(difficulty, player_name)
|
11
|
+
@difficulty = difficulty
|
12
|
+
@player_name = player_name
|
13
|
+
init_difficulty_stats(difficulty)
|
14
|
+
@hints = @total_hints
|
15
|
+
@attempts = @total_attempts
|
16
|
+
generate_secret_code
|
17
|
+
end
|
20
18
|
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
def check_code_and_give_result(user_code)
|
20
|
+
answer = @verifier.verify_user_code(user_code)
|
21
|
+
@attempts -= 1
|
24
22
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
23
|
+
if answer == '++++'
|
24
|
+
"#{answer} #{Locale::PLAYER_WIN}"
|
25
|
+
elsif @attempts <= 0
|
26
|
+
"#{answer} #{Locale::PLAYER_LOSE}"
|
27
|
+
else
|
28
|
+
answer
|
32
29
|
end
|
30
|
+
end
|
33
31
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
32
|
+
def give_hint
|
33
|
+
if @hints <= 0
|
34
|
+
Locale::NO_MORE_HINTS_AVAILABLE
|
35
|
+
else
|
36
|
+
@hints -= 1
|
37
|
+
hint = @code_for_hints.sample
|
38
|
+
@code_for_hints.delete_at(@code_for_hints.index(hint))
|
39
|
+
hint
|
43
40
|
end
|
41
|
+
end
|
44
42
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
43
|
+
def save_game_result
|
44
|
+
attempts_used = @total_attempts - @attempts
|
45
|
+
hints_used = @total_hints - @hints
|
46
|
+
@data_base_manager.save_game_results([@player_name, @difficulty,
|
47
|
+
@total_attempts, attempts_used,
|
48
|
+
@total_hints, hints_used])
|
49
|
+
end
|
52
50
|
|
53
|
-
|
54
|
-
|
55
|
-
|
51
|
+
def load_game_results
|
52
|
+
@data_base_manager.load_game_results
|
53
|
+
end
|
56
54
|
|
57
|
-
|
55
|
+
private
|
58
56
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
else
|
67
|
-
@total_attempts = 5
|
68
|
-
end
|
69
|
-
end
|
57
|
+
def init_difficulty_stats(difficulty)
|
58
|
+
@total_attempts, @total_hints = case difficulty
|
59
|
+
when 0 then [15, 2]
|
60
|
+
when 1 then [10, 1]
|
61
|
+
else [5, 1]
|
62
|
+
end
|
63
|
+
end
|
70
64
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
end
|
65
|
+
def generate_secret_code
|
66
|
+
@secret_code = Factory.new_secret_code
|
67
|
+
@verifier = CodeVerifier.new(@secret_code)
|
68
|
+
@code_for_hints = @secret_code.clone
|
76
69
|
end
|
77
70
|
end
|
data/lib/src/autoloader.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
require_relative '../codebreaker/version'
|
2
|
+
require_relative '../codebreaker'
|
2
3
|
require_relative 'code_verifier'
|
3
4
|
require_relative 'factory'
|
4
5
|
require_relative 'config/locale'
|
5
6
|
require_relative 'data_base_manager'
|
6
|
-
require '
|
7
|
+
require 'singleton'
|
7
8
|
require 'yaml'
|
@@ -1,13 +1,7 @@
|
|
1
1
|
class DataBaseManager
|
2
|
-
@instance = new
|
3
|
-
private_class_method :new
|
4
|
-
class << self
|
5
|
-
attr_reader :instance
|
6
|
-
end
|
7
|
-
|
8
2
|
def save_game_results(attributes)
|
9
3
|
data = { name: attributes[0], difficulty: attributes[1], attempts_total: attributes[2],
|
10
|
-
attempts_used: attributes[3], hints_total: attributes[4], hints_used: attributes[
|
4
|
+
attempts_used: attributes[3], hints_total: attributes[4], hints_used: attributes[5] }
|
11
5
|
Dir.mkdir('lib/db') unless Dir.exist?('lib/db')
|
12
6
|
File.open('lib/db/codebreaker_db.yml', 'a') { |file| file.puts(data.to_yaml) }
|
13
7
|
end
|
data/lib/src/factory.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codebreaker_vv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Valerii
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-09-
|
11
|
+
date: 2022-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fasterer
|
@@ -25,19 +25,19 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.9.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0
|
33
|
+
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rubocop
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 0.21.2
|
69
|
-
description: This awesome gem can create a secret code and a lot of other
|
69
|
+
description: This awesome gem can create a secret code and a lot of other beautiful
|
70
70
|
things!
|
71
71
|
email:
|
72
72
|
- valerii.radzhabov@rubygarage.org
|
@@ -75,8 +75,6 @@ extensions: []
|
|
75
75
|
extra_rdoc_files: []
|
76
76
|
files:
|
77
77
|
- ".fasterer.yml"
|
78
|
-
- ".idea/.gitignore"
|
79
|
-
- ".idea/codebreaker.iml"
|
80
78
|
- ".rspec"
|
81
79
|
- ".rubocop.yml"
|
82
80
|
- ".ruby-version"
|
data/.idea/.gitignore
DELETED
data/.idea/codebreaker.iml
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<module type="RUBY_MODULE" version="4">
|
3
|
-
<component name="ModuleRunConfigurationManager">
|
4
|
-
<shared />
|
5
|
-
</component>
|
6
|
-
<component name="NewModuleRootManager">
|
7
|
-
<content url="file://$MODULE_DIR$">
|
8
|
-
<sourceFolder url="file://$MODULE_DIR$/features" isTestSource="true" />
|
9
|
-
<sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
|
10
|
-
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
11
|
-
</content>
|
12
|
-
<orderEntry type="inheritedJdk" />
|
13
|
-
<orderEntry type="sourceFolder" forTests="false" />
|
14
|
-
<orderEntry type="library" scope="PROVIDED" name="ast (v2.4.2, rbenv: 3.1.2) [gem]" level="application" />
|
15
|
-
<orderEntry type="library" scope="PROVIDED" name="bundler (v2.3.7, rbenv: 3.1.2) [gem]" level="application" />
|
16
|
-
<orderEntry type="library" scope="PROVIDED" name="coderay (v1.1.3, rbenv: 3.1.2) [gem]" level="application" />
|
17
|
-
<orderEntry type="library" scope="PROVIDED" name="colorize (v0.8.1, rbenv: 3.1.2) [gem]" level="application" />
|
18
|
-
<orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.5.0, rbenv: 3.1.2) [gem]" level="application" />
|
19
|
-
<orderEntry type="library" scope="PROVIDED" name="docile (v1.4.0, rbenv: 3.1.2) [gem]" level="application" />
|
20
|
-
<orderEntry type="library" scope="PROVIDED" name="fasterer (v0.9.0, rbenv: 3.1.2) [gem]" level="application" />
|
21
|
-
<orderEntry type="library" scope="PROVIDED" name="json (v2.6.2, rbenv: 3.1.2) [gem]" level="application" />
|
22
|
-
<orderEntry type="library" scope="PROVIDED" name="method_source (v1.0.0, rbenv: 3.1.2) [gem]" level="application" />
|
23
|
-
<orderEntry type="library" scope="PROVIDED" name="parallel (v1.22.1, rbenv: 3.1.2) [gem]" level="application" />
|
24
|
-
<orderEntry type="library" scope="PROVIDED" name="parser (v3.1.2.1, rbenv: 3.1.2) [gem]" level="application" />
|
25
|
-
<orderEntry type="library" scope="PROVIDED" name="pry (v0.14.1, rbenv: 3.1.2) [gem]" level="application" />
|
26
|
-
<orderEntry type="library" scope="PROVIDED" name="rainbow (v3.1.1, rbenv: 3.1.2) [gem]" level="application" />
|
27
|
-
<orderEntry type="library" scope="PROVIDED" name="rake (v13.0.6, rbenv: 3.1.2) [gem]" level="application" />
|
28
|
-
<orderEntry type="library" scope="PROVIDED" name="rbs (v2.1.0, rbenv: 3.1.2) [gem]" level="application" />
|
29
|
-
<orderEntry type="library" scope="PROVIDED" name="regexp_parser (v2.5.0, rbenv: 3.1.2) [gem]" level="application" />
|
30
|
-
<orderEntry type="library" scope="PROVIDED" name="rexml (v3.2.5, rbenv: 3.1.2) [gem]" level="application" />
|
31
|
-
<orderEntry type="library" scope="PROVIDED" name="rspec (v3.11.0, rbenv: 3.1.2) [gem]" level="application" />
|
32
|
-
<orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.11.0, rbenv: 3.1.2) [gem]" level="application" />
|
33
|
-
<orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.11.0, rbenv: 3.1.2) [gem]" level="application" />
|
34
|
-
<orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.11.1, rbenv: 3.1.2) [gem]" level="application" />
|
35
|
-
<orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.11.0, rbenv: 3.1.2) [gem]" level="application" />
|
36
|
-
<orderEntry type="library" scope="PROVIDED" name="rubocop (v1.36.0, rbenv: 3.1.2) [gem]" level="application" />
|
37
|
-
<orderEntry type="library" scope="PROVIDED" name="rubocop-ast (v1.21.0, rbenv: 3.1.2) [gem]" level="application" />
|
38
|
-
<orderEntry type="library" scope="PROVIDED" name="ruby-progressbar (v1.11.0, rbenv: 3.1.2) [gem]" level="application" />
|
39
|
-
<orderEntry type="library" scope="PROVIDED" name="ruby_parser (v3.19.1, rbenv: 3.1.2) [gem]" level="application" />
|
40
|
-
<orderEntry type="library" scope="PROVIDED" name="sexp_processor (v4.16.1, rbenv: 3.1.2) [gem]" level="application" />
|
41
|
-
<orderEntry type="library" scope="PROVIDED" name="simplecov (v0.21.2, rbenv: 3.1.2) [gem]" level="application" />
|
42
|
-
<orderEntry type="library" scope="PROVIDED" name="simplecov-html (v0.12.3, rbenv: 3.1.2) [gem]" level="application" />
|
43
|
-
<orderEntry type="library" scope="PROVIDED" name="simplecov_json_formatter (v0.1.4, rbenv: 3.1.2) [gem]" level="application" />
|
44
|
-
<orderEntry type="library" scope="PROVIDED" name="unicode-display_width (v2.2.0, rbenv: 3.1.2) [gem]" level="application" />
|
45
|
-
</component>
|
46
|
-
</module>
|