codebreaker_rostik 0.1.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 +7 -0
- data/.circleci/config.yml +46 -0
- data/.gitignore +14 -0
- data/.rspec +3 -0
- data/.rubocop.yml +16 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +82 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +6 -0
- data/autoload.rb +9 -0
- data/bin/console +8 -0
- data/bin/setup +8 -0
- data/codebreaker_rostik.gemspec +44 -0
- data/i18n_config.rb +2 -0
- data/index.rb +3 -0
- data/lib/codebreaker_rostik/version.rb +3 -0
- data/lib/codebreaker_rostik.rb +2 -0
- data/lib/console.rb +155 -0
- data/lib/db/.keep +0 -0
- data/lib/difficulty.rb +29 -0
- data/lib/game.rb +66 -0
- data/lib/modules/console_helpers.rb +14 -0
- data/lib/modules/validator.rb +19 -0
- data/lib/storage.rb +37 -0
- data/lib/text_messages/en.yml +41 -0
- metadata +199 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 0de1545532e0c58ac731bf88176fad1405426ffc597775000a5b7f0930b1d870
|
|
4
|
+
data.tar.gz: 99a0a1436cf6c188ba7a18044a2542d81c82694abf6c901a4bbca09969380fd3
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 161eb67dcb462afbfbbe0d71c3cfadecd4bc4deb093254ed47db2aaf4e7e461a147df8c81e4686f08ad8c0e1d0323df6405ac3c48bbc0b05e33249dc58174b4e
|
|
7
|
+
data.tar.gz: 3c8a25d61c9d89d41139eb02e7125d0acf42043102839cdc675136308ced768e8ba30cd2d573846b318564a0573be6425b6a9912648a95afb3d6ff20cad52a50
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Ruby CircleCI 2.0 configuration file
|
|
2
|
+
#
|
|
3
|
+
# Check https://circleci.com/docs/2.0/language-ruby/ for more details
|
|
4
|
+
#
|
|
5
|
+
version: 2
|
|
6
|
+
jobs:
|
|
7
|
+
build:
|
|
8
|
+
docker:
|
|
9
|
+
# specify the version you desire here
|
|
10
|
+
- image: circleci/ruby:2.5.1-node-browsers
|
|
11
|
+
|
|
12
|
+
working_directory: ~/repo
|
|
13
|
+
|
|
14
|
+
steps:
|
|
15
|
+
- checkout
|
|
16
|
+
|
|
17
|
+
- restore_cache:
|
|
18
|
+
keys:
|
|
19
|
+
- v1-dependencies-{{ checksum "Gemfile.lock" }}
|
|
20
|
+
# fallback to using the latest cache if no exact match is found
|
|
21
|
+
- v1-dependencies-
|
|
22
|
+
|
|
23
|
+
- run:
|
|
24
|
+
name: install dependencies
|
|
25
|
+
command: |
|
|
26
|
+
bundle install --jobs=4 --retry=3 --path vendor/bundle
|
|
27
|
+
- save_cache:
|
|
28
|
+
paths:
|
|
29
|
+
- ./vendor/bundle
|
|
30
|
+
key: v1-dependencies-{{ checksum "Gemfile.lock" }}
|
|
31
|
+
|
|
32
|
+
- run:
|
|
33
|
+
name: run tests
|
|
34
|
+
command: |
|
|
35
|
+
mkdir /tmp/test-results
|
|
36
|
+
TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
|
|
37
|
+
|
|
38
|
+
bundle exec rspec --format progress \
|
|
39
|
+
--out /tmp/test-results/rspec.xml \
|
|
40
|
+
--format progress \
|
|
41
|
+
$TEST_FILES
|
|
42
|
+
- store_test_results:
|
|
43
|
+
path: /tmp/test-results
|
|
44
|
+
- store_artifacts:
|
|
45
|
+
path: /tmp/test-results
|
|
46
|
+
destination: test-results
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ruby-2.5.3
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at rost4402255@gmail.com. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: http://contributor-covenant.org
|
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
codebreaker_rostik (0.1.0)
|
|
5
|
+
|
|
6
|
+
GEM
|
|
7
|
+
remote: https://rubygems.org/
|
|
8
|
+
specs:
|
|
9
|
+
ast (2.4.0)
|
|
10
|
+
coderay (1.1.2)
|
|
11
|
+
colorize (0.8.1)
|
|
12
|
+
concurrent-ruby (1.1.3)
|
|
13
|
+
diff-lcs (1.3)
|
|
14
|
+
docile (1.3.1)
|
|
15
|
+
fasterer (0.4.1)
|
|
16
|
+
colorize (~> 0.7)
|
|
17
|
+
ruby_parser (~> 3.11.0)
|
|
18
|
+
i18n (1.1.1)
|
|
19
|
+
concurrent-ruby (~> 1.0)
|
|
20
|
+
jaro_winkler (1.5.1)
|
|
21
|
+
json (2.1.0)
|
|
22
|
+
method_source (0.9.2)
|
|
23
|
+
parallel (1.12.1)
|
|
24
|
+
parser (2.5.3.0)
|
|
25
|
+
ast (~> 2.4.0)
|
|
26
|
+
powerpack (0.1.2)
|
|
27
|
+
pry (0.12.2)
|
|
28
|
+
coderay (~> 1.1.0)
|
|
29
|
+
method_source (~> 0.9.0)
|
|
30
|
+
rainbow (3.0.0)
|
|
31
|
+
rake (10.5.0)
|
|
32
|
+
rspec (3.8.0)
|
|
33
|
+
rspec-core (~> 3.8.0)
|
|
34
|
+
rspec-expectations (~> 3.8.0)
|
|
35
|
+
rspec-mocks (~> 3.8.0)
|
|
36
|
+
rspec-core (3.8.0)
|
|
37
|
+
rspec-support (~> 3.8.0)
|
|
38
|
+
rspec-expectations (3.8.2)
|
|
39
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
40
|
+
rspec-support (~> 3.8.0)
|
|
41
|
+
rspec-mocks (3.8.0)
|
|
42
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
43
|
+
rspec-support (~> 3.8.0)
|
|
44
|
+
rspec-support (3.8.0)
|
|
45
|
+
rubocop (0.60.0)
|
|
46
|
+
jaro_winkler (~> 1.5.1)
|
|
47
|
+
parallel (~> 1.10)
|
|
48
|
+
parser (>= 2.5, != 2.5.1.1)
|
|
49
|
+
powerpack (~> 0.1)
|
|
50
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
51
|
+
ruby-progressbar (~> 1.7)
|
|
52
|
+
unicode-display_width (~> 1.4.0)
|
|
53
|
+
rubocop-rspec (1.30.1)
|
|
54
|
+
rubocop (>= 0.60.0)
|
|
55
|
+
ruby-progressbar (1.10.0)
|
|
56
|
+
ruby_parser (3.11.0)
|
|
57
|
+
sexp_processor (~> 4.9)
|
|
58
|
+
sexp_processor (4.11.0)
|
|
59
|
+
simplecov (0.16.1)
|
|
60
|
+
docile (~> 1.1)
|
|
61
|
+
json (>= 1.8, < 3)
|
|
62
|
+
simplecov-html (~> 0.10.0)
|
|
63
|
+
simplecov-html (0.10.2)
|
|
64
|
+
unicode-display_width (1.4.0)
|
|
65
|
+
|
|
66
|
+
PLATFORMS
|
|
67
|
+
ruby
|
|
68
|
+
|
|
69
|
+
DEPENDENCIES
|
|
70
|
+
bundler (~> 1.16)
|
|
71
|
+
codebreaker_rostik!
|
|
72
|
+
fasterer
|
|
73
|
+
i18n
|
|
74
|
+
pry
|
|
75
|
+
rake (~> 10.0)
|
|
76
|
+
rspec (~> 3.0)
|
|
77
|
+
rubocop
|
|
78
|
+
rubocop-rspec
|
|
79
|
+
simplecov
|
|
80
|
+
|
|
81
|
+
BUNDLED WITH
|
|
82
|
+
1.17.1
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 rostikkkk2
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# CodebreakerRostik
|
|
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_rostik`. 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
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add this line to your application's Gemfile:
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem 'codebreaker_rostik'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
And then execute:
|
|
16
|
+
|
|
17
|
+
$ bundle
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
|
|
21
|
+
$ gem install codebreaker_rostik
|
|
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 tags, 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_rostik. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
|
36
|
+
|
|
37
|
+
## License
|
|
38
|
+
|
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
40
|
+
|
|
41
|
+
## Code of Conduct
|
|
42
|
+
|
|
43
|
+
Everyone interacting in the CodebreakerRostik project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/codebreaker_rostik/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/autoload.rb
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
require 'i18n'
|
|
2
|
+
require 'yaml'
|
|
3
|
+
require_relative './lib/modules/console_helpers'
|
|
4
|
+
require_relative './lib/modules/validator'
|
|
5
|
+
require_relative './lib/console'
|
|
6
|
+
require_relative './lib/difficulty'
|
|
7
|
+
require_relative './lib/storage'
|
|
8
|
+
require_relative './lib/game'
|
|
9
|
+
require_relative './i18n_config'
|
data/bin/console
ADDED
data/bin/setup
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
|
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require "codebreaker_rostik/version"
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "codebreaker_rostik"
|
|
8
|
+
spec.version = CodebreakerRostik::VERSION
|
|
9
|
+
spec.authors = ["rostikkkk2"]
|
|
10
|
+
spec.email = ["rost4402255@gmail.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = 'CodebreakerRostik'
|
|
13
|
+
spec.description = 'Game'
|
|
14
|
+
spec.homepage = "https://github.com/rostikkkk2/codebreaker-gem"
|
|
15
|
+
spec.license = "MIT"
|
|
16
|
+
|
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
|
19
|
+
if spec.respond_to?(:metadata)
|
|
20
|
+
spec.metadata["allowed_push_host"] = 'https://rubygems.org'
|
|
21
|
+
else
|
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
|
23
|
+
"public gem pushes."
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Specify which files should be added to the gem when it is released.
|
|
27
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
28
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
|
29
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
30
|
+
end
|
|
31
|
+
spec.bindir = "exe"
|
|
32
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
33
|
+
spec.require_paths = ["lib"]
|
|
34
|
+
|
|
35
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
|
36
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
37
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
38
|
+
spec.add_development_dependency "i18n"
|
|
39
|
+
spec.add_development_dependency "fasterer"
|
|
40
|
+
spec.add_development_dependency "pry"
|
|
41
|
+
spec.add_development_dependency "rubocop"
|
|
42
|
+
spec.add_development_dependency "rubocop-rspec"
|
|
43
|
+
spec.add_development_dependency "simplecov"
|
|
44
|
+
end
|
data/i18n_config.rb
ADDED
data/index.rb
ADDED
data/lib/console.rb
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
module CodebreakerRostik
|
|
2
|
+
class Console
|
|
3
|
+
include ConsoleHelpers
|
|
4
|
+
include Validator
|
|
5
|
+
|
|
6
|
+
attr_reader :info_difficult, :user_name, :user
|
|
7
|
+
|
|
8
|
+
OPTIONS = {
|
|
9
|
+
start: 'Start',
|
|
10
|
+
rules: 'Rules',
|
|
11
|
+
stats: 'Stats',
|
|
12
|
+
exit: 'Exit'
|
|
13
|
+
}.freeze
|
|
14
|
+
GAME_RESULTS = {
|
|
15
|
+
win: '++++',
|
|
16
|
+
lose: '----'
|
|
17
|
+
}.freeze
|
|
18
|
+
NAME_DIFFICULTIES = %w[Easy Medium Hell].freeze
|
|
19
|
+
COUNT_ATTEMPTS = 0
|
|
20
|
+
COUNT_HINTS = 0
|
|
21
|
+
ANSWERS = {
|
|
22
|
+
yes: 'Yes'
|
|
23
|
+
}.freeze
|
|
24
|
+
NAME_LENGTH_RANGE = (3..20).freeze
|
|
25
|
+
HINT = 'Hint'.freeze
|
|
26
|
+
EXIT = 'Exit'.freeze
|
|
27
|
+
|
|
28
|
+
def check_option
|
|
29
|
+
show_info(:welcome)
|
|
30
|
+
loop do
|
|
31
|
+
case show_message_with_input(:choose_option)
|
|
32
|
+
when OPTIONS[:start] then return registration
|
|
33
|
+
when OPTIONS[:rules] then show_rules
|
|
34
|
+
when OPTIONS[:stats] then show_stats
|
|
35
|
+
else
|
|
36
|
+
show_info(:wrong_input_option)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def show_message_with_input(message, key = nil)
|
|
42
|
+
show_info(message, key)
|
|
43
|
+
value = gets.chomp.capitalize
|
|
44
|
+
value == OPTIONS[:exit] ? bye : value
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
private
|
|
48
|
+
|
|
49
|
+
def registration
|
|
50
|
+
@user_name = ask_name
|
|
51
|
+
@info_difficulty = ask_difficulty
|
|
52
|
+
@user = { name: user_name, **@info_difficulty, attempts_left: COUNT_ATTEMPTS, hints_left: COUNT_HINTS }
|
|
53
|
+
play_game
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def ask_name
|
|
57
|
+
loop do
|
|
58
|
+
name = show_message_with_input(:write_name)
|
|
59
|
+
return name if valid_name?(name)
|
|
60
|
+
|
|
61
|
+
show_info(:unexpected_command)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def valid_name?(name)
|
|
66
|
+
validate_length_range?(name, NAME_LENGTH_RANGE) && validate_class?(name, String)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def ask_difficulty
|
|
70
|
+
loop do
|
|
71
|
+
difficulty = show_message_with_input(:choose_difficulty,
|
|
72
|
+
difficulties: Difficulty::DIFFICULTIES.keys.join(', '))
|
|
73
|
+
break Difficulty.new(difficulty).choose_difficulty if NAME_DIFFICULTIES.include?(difficulty)
|
|
74
|
+
|
|
75
|
+
show_info(:unexpected_command)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def play_game
|
|
80
|
+
@game ||= Game.new
|
|
81
|
+
loop do
|
|
82
|
+
guess_code = show_message_with_input(:message_guess_code)
|
|
83
|
+
check_hint if guess_code == HINT
|
|
84
|
+
@game.valid_guess_code?(guess_code) ? game_proccess(guess_code) : show_info(:unexpected_command)
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def game_proccess(guess_code)
|
|
89
|
+
puts @game.compare_guess_and_secret_codes(guess_code)
|
|
90
|
+
check_win_with_lose(guess_code)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def check_win_with_lose(guess_code)
|
|
94
|
+
guess_code == @game.secret_code.join ? win : check_lose
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def win
|
|
98
|
+
show_info(:win)
|
|
99
|
+
ask_for_save
|
|
100
|
+
ask_restart
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def show_hint
|
|
104
|
+
@game.hints_left_increase(user)
|
|
105
|
+
puts @game.give_digit_hint
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def ask_restart
|
|
109
|
+
return check_option if show_message_with_input(:restart) == ANSWERS[:yes]
|
|
110
|
+
|
|
111
|
+
bye
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def ask_for_save
|
|
115
|
+
Storage.new.add_data_to_db(user) if show_message_with_input(:ask_save_to_db) == ANSWERS[:yes]
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def check_lose
|
|
119
|
+
@game.attempts_left_increase(user)
|
|
120
|
+
return if attempts_left?
|
|
121
|
+
|
|
122
|
+
show_info(:lose)
|
|
123
|
+
ask_restart
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def attempts_left?
|
|
127
|
+
user[:attempts_left] != user[:attempts_total]
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def check_hint
|
|
131
|
+
user[:hints_left] == user[:hints_total] ? show_info(:used_all_hints) : show_hint
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def new_storage
|
|
135
|
+
@db = Storage.new
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def show_rules
|
|
139
|
+
show_info(:rules)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def show_stats
|
|
143
|
+
new_storage
|
|
144
|
+
@db.file_exist? ? show_db_info(@db.load) : show_info(:clear_stats)
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def show_db_info(data)
|
|
148
|
+
@db.sort_db_info(data).each do |user|
|
|
149
|
+
user.each do |key, value|
|
|
150
|
+
puts "#{key}: #{value} #{"\n" if key == :hints_left} "
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
end
|
data/lib/db/.keep
ADDED
|
File without changes
|
data/lib/difficulty.rb
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module CodebreakerRostik
|
|
2
|
+
class Difficulty
|
|
3
|
+
DIFFICULTIES = {
|
|
4
|
+
easy: {
|
|
5
|
+
difficulty: 'Easy',
|
|
6
|
+
attempts_total: 15,
|
|
7
|
+
hints_total: 2
|
|
8
|
+
},
|
|
9
|
+
medium: {
|
|
10
|
+
difficulty: 'Medium',
|
|
11
|
+
attempts_total: 10,
|
|
12
|
+
hints_total: 1
|
|
13
|
+
},
|
|
14
|
+
hell: {
|
|
15
|
+
difficulty: 'Hell',
|
|
16
|
+
attempts_total: 5,
|
|
17
|
+
hints_total: 1
|
|
18
|
+
}
|
|
19
|
+
}.freeze
|
|
20
|
+
|
|
21
|
+
def initialize(difficulty)
|
|
22
|
+
@difficulty = difficulty.downcase.to_sym if difficulty
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def choose_difficulty
|
|
26
|
+
return DIFFICULTIES[@difficulty] if DIFFICULTIES.key?(@difficulty)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
data/lib/game.rb
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
module CodebreakerRostik
|
|
2
|
+
class Game
|
|
3
|
+
include Validator
|
|
4
|
+
attr_reader :secret_code, :secret_code_for_hints
|
|
5
|
+
|
|
6
|
+
LENGTH_GUESS_CODE = 4
|
|
7
|
+
RANGE_GUESS_CODE = (1..6).freeze
|
|
8
|
+
|
|
9
|
+
def initialize
|
|
10
|
+
@secret_code = generate_secrete_code
|
|
11
|
+
@secret_code_for_hints = @secret_code.clone.shuffle
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def valid_guess_code?(guess_code)
|
|
15
|
+
validate_each_char_in_range?(guess_code.split(''), RANGE_GUESS_CODE) && valid_length?(guess_code, LENGTH_GUESS_CODE)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def hints_left_increase(user)
|
|
19
|
+
user[:hints_left] += 1
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def attempts_left_increase(user)
|
|
23
|
+
user[:attempts_left] += 1
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def give_digit_hint
|
|
27
|
+
@secret_code_for_hints.pop
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def compare_guess_and_secret_codes(guess_code)
|
|
31
|
+
@result_signs = ''
|
|
32
|
+
double_secret_code = @secret_code.clone
|
|
33
|
+
code_arr = guess_code.split('').map(&:to_i)
|
|
34
|
+
double_guess_code = code_arr
|
|
35
|
+
|
|
36
|
+
check_same_index(code_arr, double_secret_code, double_guess_code)
|
|
37
|
+
[double_secret_code, double_guess_code].each(&:compact!)
|
|
38
|
+
check_different_index(double_guess_code, double_secret_code)
|
|
39
|
+
@result_signs
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
private
|
|
43
|
+
|
|
44
|
+
def check_same_index(code_arr, double_secret_code, double_guess_code)
|
|
45
|
+
code_arr.each_index do |index|
|
|
46
|
+
next unless code_arr[index] == @secret_code[index]
|
|
47
|
+
|
|
48
|
+
double_secret_code[index], double_guess_code[index] = nil
|
|
49
|
+
@result_signs += '+'
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def check_different_index(double_guess_code, double_secret_code)
|
|
54
|
+
double_guess_code.each do |guess_digit|
|
|
55
|
+
next unless double_secret_code.include?(guess_digit)
|
|
56
|
+
|
|
57
|
+
double_secret_code[double_secret_code.find_index(guess_digit)] = nil
|
|
58
|
+
@result_signs += '-'
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def generate_secrete_code
|
|
63
|
+
Array.new(LENGTH_GUESS_CODE) { rand(RANGE_GUESS_CODE) }
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module CodebreakerRostik
|
|
2
|
+
module Validator
|
|
3
|
+
def validate_length_range?(value, length_range)
|
|
4
|
+
length_range.include?(value.length)
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def validate_class?(value, klass)
|
|
8
|
+
value.is_a?(klass)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def validate_each_char_in_range?(value, length_range)
|
|
12
|
+
value.each { |num| return false unless length_range.include?(num.to_i) }
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def valid_length?(value, length)
|
|
16
|
+
value.length == length
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
data/lib/storage.rb
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module CodebreakerRostik
|
|
2
|
+
class Storage
|
|
3
|
+
attr_reader :db_user
|
|
4
|
+
PATH_TO_DB = File.dirname(__FILE__) + '/db/db.yaml'
|
|
5
|
+
|
|
6
|
+
def initialize
|
|
7
|
+
@db_user = []
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def add_data_to_db(user)
|
|
11
|
+
file_exist? ? add_data_to_old_info(user) : @db_user.push(user)
|
|
12
|
+
write_to_db
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def add_data_to_old_info(user)
|
|
16
|
+
@db_user = load.push(user)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def file_exist?
|
|
20
|
+
File.exist?(PATH_TO_DB)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def sort_db_info(data)
|
|
24
|
+
data.sort_by { |user| [user[:attempts_total], user[:attempts_used], user[:hints_used]] }
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def load
|
|
28
|
+
YAML.load_file(PATH_TO_DB)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def write_to_db
|
|
32
|
+
db_file = File.open(PATH_TO_DB, 'w')
|
|
33
|
+
db_file.write(@db_user.to_yaml)
|
|
34
|
+
db_file.close
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
en:
|
|
2
|
+
welcome: "Welcome to Codebreaker!"
|
|
3
|
+
choose_option: "
|
|
4
|
+
\nChoose option one of several possible scenarios:
|
|
5
|
+
\nstart, rules, stats, exit.\n "
|
|
6
|
+
wrong_input_option: "You have passed unexpected command. Please choose one from listed commands\n "
|
|
7
|
+
goodbye: 'Goodbye'
|
|
8
|
+
rules: "\n Codebreaker is a logic game in which a code-breaker tries to break a secret code created by a code-maker.\n
|
|
9
|
+
The codemaker, which will be played by the application we’re going to write,\n
|
|
10
|
+
creates a secret code of four numbers between 1 and 6.\n
|
|
11
|
+
The codebreaker gets some number of chances to break the code (depends on chosen difficulty).\n
|
|
12
|
+
In each turn, the codebreaker makes a guess of 4 numbers.\n
|
|
13
|
+
The codemaker then marks the guess with up to 4 signs - or - or empty spaces. \n
|
|
14
|
+
A indicates an exact match: one of the numbers in the guess is the same as one of the numbers,\n
|
|
15
|
+
in the secret code and in the same position.\n
|
|
16
|
+
For example:\n
|
|
17
|
+
Secret number - 1234\n
|
|
18
|
+
Input number - 6264 \n
|
|
19
|
+
Number of pluses - 2 (second and fourth position)\n
|
|
20
|
+
A - indicates a number match: \n
|
|
21
|
+
one of the numbers in the guess is the same as one of the numbers,\n
|
|
22
|
+
in the secret code but in a different position.\n
|
|
23
|
+
For example:\n
|
|
24
|
+
Secret number - 1234\n
|
|
25
|
+
Input number - 6462\n
|
|
26
|
+
Number of minuses - 2 (second and fourth position)\n
|
|
27
|
+
An empty space indicates that there is not a current digit in a secret number.\n
|
|
28
|
+
If codebreaker inputs the exact number as a secret number\n
|
|
29
|
+
- codebreaker wins the game. If all attempts are spent - codebreaker loses.\n
|
|
30
|
+
Codebreaker also has some number of hints(depends on chosen difficulty).\n
|
|
31
|
+
If a user takes a hint - he receives back a separate digit of the secret code.\n "
|
|
32
|
+
write_name: 'Enter your name'
|
|
33
|
+
choose_difficulty: "\nChoose your difficulty: %{difficulties}\n "
|
|
34
|
+
message_guess_code: "guess of secret code! You can take hint or exit\n "
|
|
35
|
+
unexpected_command: 'Unexpected command'
|
|
36
|
+
restart: 'Do you want to restart game?'
|
|
37
|
+
lose: "You lose \n"
|
|
38
|
+
win: "You win \n"
|
|
39
|
+
used_all_hints: 'You used all hints'
|
|
40
|
+
clear_stats: 'Statistic is empty'
|
|
41
|
+
ask_save_to_db: "Do you want to save your progres? yes/no or nothing \n"
|
metadata
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: codebreaker_rostik
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- rostikkkk2
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2019-01-07 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.16'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.16'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '3.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: i18n
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: fasterer
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: pry
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - ">="
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0'
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - ">="
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '0'
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: rubocop
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - ">="
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '0'
|
|
104
|
+
type: :development
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - ">="
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '0'
|
|
111
|
+
- !ruby/object:Gem::Dependency
|
|
112
|
+
name: rubocop-rspec
|
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
|
114
|
+
requirements:
|
|
115
|
+
- - ">="
|
|
116
|
+
- !ruby/object:Gem::Version
|
|
117
|
+
version: '0'
|
|
118
|
+
type: :development
|
|
119
|
+
prerelease: false
|
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
121
|
+
requirements:
|
|
122
|
+
- - ">="
|
|
123
|
+
- !ruby/object:Gem::Version
|
|
124
|
+
version: '0'
|
|
125
|
+
- !ruby/object:Gem::Dependency
|
|
126
|
+
name: simplecov
|
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
|
128
|
+
requirements:
|
|
129
|
+
- - ">="
|
|
130
|
+
- !ruby/object:Gem::Version
|
|
131
|
+
version: '0'
|
|
132
|
+
type: :development
|
|
133
|
+
prerelease: false
|
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
135
|
+
requirements:
|
|
136
|
+
- - ">="
|
|
137
|
+
- !ruby/object:Gem::Version
|
|
138
|
+
version: '0'
|
|
139
|
+
description: Game
|
|
140
|
+
email:
|
|
141
|
+
- rost4402255@gmail.com
|
|
142
|
+
executables: []
|
|
143
|
+
extensions: []
|
|
144
|
+
extra_rdoc_files: []
|
|
145
|
+
files:
|
|
146
|
+
- ".circleci/config.yml"
|
|
147
|
+
- ".gitignore"
|
|
148
|
+
- ".rspec"
|
|
149
|
+
- ".rubocop.yml"
|
|
150
|
+
- ".ruby-version"
|
|
151
|
+
- ".travis.yml"
|
|
152
|
+
- CODE_OF_CONDUCT.md
|
|
153
|
+
- Gemfile
|
|
154
|
+
- Gemfile.lock
|
|
155
|
+
- LICENSE.txt
|
|
156
|
+
- README.md
|
|
157
|
+
- Rakefile
|
|
158
|
+
- autoload.rb
|
|
159
|
+
- bin/console
|
|
160
|
+
- bin/setup
|
|
161
|
+
- codebreaker_rostik.gemspec
|
|
162
|
+
- i18n_config.rb
|
|
163
|
+
- index.rb
|
|
164
|
+
- lib/codebreaker_rostik.rb
|
|
165
|
+
- lib/codebreaker_rostik/version.rb
|
|
166
|
+
- lib/console.rb
|
|
167
|
+
- lib/db/.keep
|
|
168
|
+
- lib/difficulty.rb
|
|
169
|
+
- lib/game.rb
|
|
170
|
+
- lib/modules/console_helpers.rb
|
|
171
|
+
- lib/modules/validator.rb
|
|
172
|
+
- lib/storage.rb
|
|
173
|
+
- lib/text_messages/en.yml
|
|
174
|
+
homepage: https://github.com/rostikkkk2/codebreaker-gem
|
|
175
|
+
licenses:
|
|
176
|
+
- MIT
|
|
177
|
+
metadata:
|
|
178
|
+
allowed_push_host: https://rubygems.org
|
|
179
|
+
post_install_message:
|
|
180
|
+
rdoc_options: []
|
|
181
|
+
require_paths:
|
|
182
|
+
- lib
|
|
183
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
184
|
+
requirements:
|
|
185
|
+
- - ">="
|
|
186
|
+
- !ruby/object:Gem::Version
|
|
187
|
+
version: '0'
|
|
188
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
189
|
+
requirements:
|
|
190
|
+
- - ">="
|
|
191
|
+
- !ruby/object:Gem::Version
|
|
192
|
+
version: '0'
|
|
193
|
+
requirements: []
|
|
194
|
+
rubyforge_project:
|
|
195
|
+
rubygems_version: 2.7.7
|
|
196
|
+
signing_key:
|
|
197
|
+
specification_version: 4
|
|
198
|
+
summary: CodebreakerRostik
|
|
199
|
+
test_files: []
|