codebreaker_kolyanjy 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: fbe4c88e9997e8364b5265f7b8ddadb2fefd792914e7312b2eea1c215d733b16
4
+ data.tar.gz: '09b1c188c77b8f79c531139682d21341a8a2727bae69304a407588cc4e60e3af'
5
+ SHA512:
6
+ metadata.gz: 5a7613eaccd739ff7ced31366357d667f1753d9e7b66660d3bf95a8b5c7f03287cf9f63cb2c8bd8098a3d001d2bddd98070654345b6b660b9ef4aaf55e8ba714
7
+ data.tar.gz: 226023e4ba1b091ab9c1116094360d4f2d5f415a3139c5d8b4cafe0c830c61d41156adf5788e291ec5b699115eb266e473cd5a9aec555f8804b5b0278e794598
data/.fasterer.yml ADDED
@@ -0,0 +1,19 @@
1
+ speedups:
2
+ rescue_vs_respond_to: true
3
+ module_eval: true
4
+ shuffle_first_vs_sample: true
5
+ for_loop_vs_each: true
6
+ each_with_index_vs_while: false
7
+ map_flatten_vs_flat_map: true
8
+ reverse_each_vs_reverse_each: true
9
+ select_first_vs_detect: true
10
+ sort_vs_sort_by: true
11
+ fetch_with_argument_vs_block: true
12
+ keys_each_vs_each_key: true
13
+ hash_merge_bang_vs_hash_brackets: true
14
+ block_vs_symbol_to_proc: true
15
+ proc_call_vs_yield: true
16
+ gsub_vs_tr: true
17
+ select_last_vs_reverse_detect: true
18
+ getter_vs_attr_reader: true
19
+ setter_vs_attr_writer: true
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /spec/reports/
7
+ /tmp/
data/.rake_tasks~ ADDED
@@ -0,0 +1,7 @@
1
+ build
2
+ clean
3
+ clobber
4
+ install
5
+ install:local
6
+ release[remote]
7
+ spec
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,17 @@
1
+ Style/Encoding:
2
+ Enabled: false
3
+ Metrics/LineLength:
4
+ Max: 120
5
+ Metrics/ClassLength:
6
+ Max: 100
7
+ Metrics/MethodLength:
8
+ Max: 20
9
+ Metrics/CyclomaticComplexity:
10
+ Max: 10
11
+ Metrics/AbcSize:
12
+ Max: 20
13
+ Metrics/BlockLength:
14
+ ExcludedMethods: ['describe']
15
+ Max: 50
16
+ Documentation:
17
+ Enabled: false
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ rg-codebreaker
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.5.1
@@ -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 kolyan654d@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
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in codebreaker-gem.gemspec
6
+
7
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,75 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ codebreaker (0.1.3)
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
+ diff-lcs (1.3)
13
+ docile (1.3.1)
14
+ fasterer (0.4.1)
15
+ colorize (~> 0.7)
16
+ ruby_parser (~> 3.11.0)
17
+ jaro_winkler (1.5.2)
18
+ json (2.1.0)
19
+ method_source (0.9.2)
20
+ parallel (1.13.0)
21
+ parser (2.6.0.0)
22
+ ast (~> 2.4.0)
23
+ powerpack (0.1.2)
24
+ pry (0.12.2)
25
+ coderay (~> 1.1.0)
26
+ method_source (~> 0.9.0)
27
+ rainbow (3.0.0)
28
+ rake (10.5.0)
29
+ rspec (3.8.0)
30
+ rspec-core (~> 3.8.0)
31
+ rspec-expectations (~> 3.8.0)
32
+ rspec-mocks (~> 3.8.0)
33
+ rspec-core (3.8.0)
34
+ rspec-support (~> 3.8.0)
35
+ rspec-expectations (3.8.2)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.8.0)
38
+ rspec-mocks (3.8.0)
39
+ diff-lcs (>= 1.2.0, < 2.0)
40
+ rspec-support (~> 3.8.0)
41
+ rspec-support (3.8.0)
42
+ rubocop (0.63.1)
43
+ jaro_winkler (~> 1.5.1)
44
+ parallel (~> 1.10)
45
+ parser (>= 2.5, != 2.5.1.1)
46
+ powerpack (~> 0.1)
47
+ rainbow (>= 2.2.2, < 4.0)
48
+ ruby-progressbar (~> 1.7)
49
+ unicode-display_width (~> 1.4.0)
50
+ ruby-progressbar (1.10.0)
51
+ ruby_parser (3.11.0)
52
+ sexp_processor (~> 4.9)
53
+ sexp_processor (4.11.0)
54
+ simplecov (0.16.1)
55
+ docile (~> 1.1)
56
+ json (>= 1.8, < 3)
57
+ simplecov-html (~> 0.10.0)
58
+ simplecov-html (0.10.2)
59
+ unicode-display_width (1.4.1)
60
+
61
+ PLATFORMS
62
+ ruby
63
+
64
+ DEPENDENCIES
65
+ bundler (~> 1.17)
66
+ codebreaker!
67
+ fasterer
68
+ pry
69
+ rake (~> 10.0)
70
+ rspec (~> 3.0)
71
+ rubocop
72
+ simplecov
73
+
74
+ BUNDLED WITH
75
+ 1.17.3
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 kolyanjy
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
+ # Codebreaker::Gem
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/gem`. 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-gem'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
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. 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. 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 Codebreaker::Gem project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/codebreaker-gem/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/autoload.rb ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+ require_relative './lib/modules/storage.rb'
5
+ require_relative './lib/modules/phrases.rb'
6
+ require_relative './lib/modules/validator.rb'
7
+ require_relative './lib/modules/storage.rb'
8
+ require_relative './lib/modules/input_helper.rb'
9
+ require_relative './lib/entities/game.rb'
10
+ require_relative './lib/entities/console.rb'
11
+ require_relative './lib/entities/core.rb'
12
+ require_relative './lib/entities/wellcome.rb'
13
+ require_relative './lib/codebreaker/version.rb'
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "codebreaker"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,35 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "codebreaker/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "codebreaker_kolyanjy"
8
+ spec.version = Codebreaker::VERSION
9
+ spec.authors = ["kolyanjy"]
10
+ spec.email = ["kolyan654d@gmail.com"]
11
+
12
+ spec.summary = 'codebreaker gem'
13
+ spec.description = 'gem for codebreaker web app'
14
+ spec.homepage = 'https://github.com/kolyanjy/codebreaker-gem.git'
15
+ spec.license = "MIT"
16
+
17
+
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_development_dependency "bundler", "~> 1.17"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "rspec", "~> 3.0"
31
+ spec.add_development_dependency "fasterer"
32
+ spec.add_development_dependency "pry"
33
+ spec.add_development_dependency "rubocop"
34
+ spec.add_development_dependency "simplecov"
35
+ end
data/index.rb ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/codebreaker.rb'
4
+
5
+ Codebreaker::Wellcome.new.start_codebreaker
@@ -0,0 +1,3 @@
1
+ module Codebreaker
2
+ VERSION = "0.1.3"
3
+ end
@@ -0,0 +1,4 @@
1
+ require "codebreaker/version"
2
+ module Codebreaker
3
+ require_relative '../autoload'
4
+ end
data/lib/data/data.yml ADDED
@@ -0,0 +1,5 @@
1
+ ---
2
+ - :name: Kolyan
3
+ :attempts: 5
4
+ :hints: 0
5
+ :level: easy
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+ module Codebreaker
3
+ class Console
4
+ attr_reader :game
5
+ include Phrases
6
+ include Storage
7
+ include Validator
8
+ include InputHelper
9
+
10
+ def initialize(name)
11
+ @game = Game.new(name)
12
+ end
13
+
14
+ def choose_complexity
15
+ about_complexities
16
+ @game.generate_hints_attempts(user_input('complexity').to_sym)
17
+ play
18
+ end
19
+
20
+ def play
21
+ phrase_before_guess
22
+ user_guess = user_input('guess')
23
+ if user_guess == COMMANDS[:hint]
24
+ show_hint
25
+ else
26
+ check_game_answer @game.guess user_guess
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def check_game_answer(answer)
33
+ case answer
34
+ when :win then phrase_win
35
+ when :lose then phrase_lose
36
+ else
37
+ show answer
38
+ play
39
+ end
40
+ end
41
+
42
+ def show_hint
43
+ hint = @game.hint
44
+ hint ? puts_hint(hint) : zero_hint
45
+ play
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+ module Codebreaker
3
+ class Core
4
+ GUESSED_PLACE = '+'
5
+ GUESSED_PRESENCE = '-'
6
+ CB_ARRAY_SIZE = 4
7
+ GAME_NUMBER_RANGE = (1..6).freeze
8
+
9
+ def generate_secret_code
10
+ CB_ARRAY_SIZE.times.map { rand(GAME_NUMBER_RANGE) }
11
+ end
12
+
13
+ def check(cb_numbers, guess_arr)
14
+ result = ''
15
+ code_guess_arr = cb_numbers.zip(guess_arr)
16
+ code_after_each = []
17
+ guess_after_each = []
18
+ code_guess_arr.each do |unite_arr|
19
+ if unite_arr.uniq.size == 1
20
+ result += GUESSED_PLACE
21
+ else
22
+ code_after_each << unite_arr.first
23
+ guess_after_each << unite_arr.last
24
+ end
25
+ end
26
+ guess_after_each.each { |elem| result += GUESSED_PRESENCE if code_after_each.uniq.include?(elem) }
27
+ result
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+ module Codebreaker
3
+ class Game
4
+ attr_reader :attempts, :hints, :cb_numbers, :level, :cb_numbers, :name, :cb_numbers_copy
5
+ include Storage
6
+
7
+ WIN = :win
8
+ LOSE = :lose
9
+ LEVELS = { easy: 'easy', medium: 'medium', hard: 'hard' }.freeze
10
+ COMPLEXITIES = { easy: { hints: 2, attempts: 15, level: LEVELS[:easy] },
11
+ medium: { hints: 1, attempts: 10, level: LEVELS[:medium] },
12
+ hard: { hints: 1, attempts: 5, level: LEVELS[:hard] } }.freeze
13
+
14
+ def initialize(name)
15
+ @name = name
16
+ @cb_numbers = Core.new.generate_secret_code
17
+ @cb_numbers_copy = @cb_numbers.clone
18
+ end
19
+
20
+ def generate_hints_attempts(level)
21
+ @level = level
22
+ level_hash = take_level_hash
23
+ @hints = level_hash[:hints]
24
+ @attempts = level_hash[:attempts]
25
+ end
26
+
27
+ def guess(user_guess)
28
+ return LOSE if lose?
29
+
30
+ @attempts -= 1
31
+ user_guess_array = user_guess.split('').map(&:to_i)
32
+ return WIN if win? user_guess_array
33
+
34
+ Core.new.check(@cb_numbers, user_guess_array)
35
+ end
36
+
37
+ def hint
38
+ return nil if @hints.zero?
39
+
40
+ @hints -= 1
41
+ @cb_numbers_copy.shuffle.pop
42
+ end
43
+
44
+ def calculate_hints
45
+ take_level_hash[:hints] - @hints
46
+ end
47
+
48
+ def calculate_attempts
49
+ take_level_hash[:attempts] - @attempts
50
+ end
51
+
52
+ private
53
+
54
+ def take_level_hash
55
+ COMPLEXITIES[@level]
56
+ end
57
+
58
+ def win?(user_guess_array)
59
+ save_result if user_guess_array == @cb_numbers
60
+ end
61
+
62
+ def lose?
63
+ @attempts.zero?
64
+ end
65
+
66
+ def save_result
67
+ data = restore_storage
68
+ data << { name: @name, attempts: calculate_attempts, hints: calculate_hints, level: @level }
69
+ save(data)
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+ module Codebreaker
3
+ class Wellcome
4
+ include Phrases
5
+ include Storage
6
+ include Validator
7
+ include InputHelper
8
+
9
+ def start_codebreaker
10
+ greeting
11
+ spot
12
+ end
13
+
14
+ def spot
15
+ case user_input('navigation')
16
+ when COMMANDS[:start] then registration
17
+ when COMMANDS[:rules] then rules
18
+ when COMMANDS[:statistics] then show_statistics
19
+ end
20
+ end
21
+
22
+ def show_statistics
23
+ show restore_storage
24
+ spot
25
+ end
26
+
27
+ def registration
28
+ about_name
29
+ Console.new(user_input('name')).choose_complexity
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+ module Codebreaker
3
+ module InputHelper
4
+ def user_input(validator)
5
+ input = gets.chomp.downcase
6
+ if valid_input?(input, validator)
7
+ input
8
+ else
9
+ error_massage(validator)
10
+ user_input(validator)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+ module Codebreaker
3
+ module Phrases
4
+ def greeting
5
+ puts <<~HEREDOC
6
+ Hello it`s a codebreaker
7
+ for start Core write: "start"
8
+ for show statistics write: "stat"
9
+ for show rules write: "rules"
10
+ in any moments you can exit just write: "exit"
11
+ HEREDOC
12
+ end
13
+
14
+ def about_complexities
15
+ puts <<~HEREDOC
16
+ I have 3 levels of complexity
17
+ easy: hints 2, attempts 15
18
+ medium: hints 1, attempts 10
19
+ hard: hints 1, attempts 5
20
+ for choose complexity write: "easy", "medium" or "hard"
21
+ HEREDOC
22
+ end
23
+
24
+ def about_name
25
+ puts <<~HEREDOC
26
+ Remember!
27
+ your name must be from 3 to 25 letter
28
+ write your name:
29
+ HEREDOC
30
+ end
31
+
32
+ def rules
33
+ puts <<~HEREDOC
34
+ the game sets a task
35
+ and this is a four-digit number
36
+ the goal is to guess this number
37
+ the game consists of 3 levels of difficulty easy, medium, hard
38
+ if you guess digit position in number the game would give you "+"
39
+ if you guess the presence of numbers in the number the game would give you "-"
40
+ also you can take a hint which would show a random number
41
+ the game will end when you guess the number or your hints will end
42
+ good luck and have fun
43
+ HEREDOC
44
+ end
45
+
46
+ def goodbye
47
+ puts '<------------goodbye------------>'
48
+ exit
49
+ end
50
+
51
+ def error_massage(validator)
52
+ case validator
53
+ when 'navigation'
54
+ puts 'please write "start", "stat" or "rules"'
55
+ when 'name'
56
+ puts 'valid name must have 3-25 letters'
57
+ when 'guess'
58
+ puts 'valid guess must have 4 nunbers and you can take hint'
59
+ when 'complexity'
60
+ puts 'you have 3 level "easy", "medium", "hard"'
61
+ end
62
+ end
63
+
64
+ def phrase_before_guess
65
+ puts <<~HEREDOC
66
+ numbers is ready
67
+ try to guess or take a hint;)
68
+ HEREDOC
69
+ end
70
+
71
+ def puts_hint(hint)
72
+ puts "hint: #{hint}"
73
+ end
74
+
75
+ def zero_hint
76
+ puts 'sorry but tips are over :('
77
+ end
78
+
79
+ def phrase_lose
80
+ puts 'you lose :('
81
+ end
82
+
83
+ def show(obj)
84
+ puts obj
85
+ end
86
+
87
+ def phrase_win
88
+ puts '<----------------YOU---WIN---------------->'
89
+ end
90
+
91
+ def empty_statistic
92
+ puts 'statistic is empty'
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+ module Codebreaker
3
+ module Storage
4
+ FILE_PATH = 'lib/data/data.yml'
5
+
6
+ def save(data)
7
+ create_storage unless storage_exist?
8
+ File.open(FILE_PATH, 'w') { |file| file.write data.to_yaml }
9
+ end
10
+
11
+ def restore_storage
12
+ storage_exist? ? YAML.load_stream(File.open(FILE_PATH)) : []
13
+ end
14
+
15
+ private
16
+
17
+ def storage_exist?
18
+ File.exist? FILE_PATH
19
+ end
20
+
21
+ def create_storage
22
+ File.new(FILE_PATH, 'w+')
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+ module Codebreaker
3
+ module Validator
4
+ COMMANDS = { start: 'start', rules: 'rules', statistics: 'stat', hint: 'hint', exit: 'exit' }.freeze
5
+ NAME_SIZE = (3..25).freeze
6
+ LEVELS = { easy: 'easy', medium: 'medium', hard: 'hard' }.freeze
7
+ CB_ARRAY_SIZE = 4
8
+ GAME_NUMBER_RANGE = (1..6).freeze
9
+
10
+ def valid_input?(input, validator)
11
+ goodbye if input == COMMANDS[:exit]
12
+
13
+ case validator
14
+ when 'guess'
15
+ return false unless input.size == CB_ARRAY_SIZE
16
+ return true if input == COMMANDS[:hint]
17
+
18
+ input.split('').map { |number| GAME_NUMBER_RANGE.cover?(number.to_i) }.all?
19
+ when 'name'
20
+ NAME_SIZE.include?(input.size)
21
+ when 'navigation'
22
+ COMMANDS.value?(input)
23
+ when 'complexity'
24
+ LEVELS.value?(input)
25
+ else
26
+ false
27
+ end
28
+ end
29
+ end
30
+ end
Binary file
Binary file
metadata ADDED
@@ -0,0 +1,172 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: codebreaker_kolyanjy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - kolyanjy
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-02-24 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.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
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: fasterer
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: pry
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: rubocop
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: simplecov
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
+ description: gem for codebreaker web app
112
+ email:
113
+ - kolyan654d@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".fasterer.yml"
119
+ - ".gitignore"
120
+ - ".rake_tasks~"
121
+ - ".rspec"
122
+ - ".rubocop.yml"
123
+ - ".ruby-gemset"
124
+ - ".ruby-version"
125
+ - CODE_OF_CONDUCT.md
126
+ - Gemfile
127
+ - Gemfile.lock
128
+ - LICENSE.txt
129
+ - README.md
130
+ - Rakefile
131
+ - autoload.rb
132
+ - bin/console
133
+ - bin/setup
134
+ - codebreaker.gemspec
135
+ - index.rb
136
+ - lib/codebreaker.rb
137
+ - lib/codebreaker/version.rb
138
+ - lib/data/data.yml
139
+ - lib/entities/console.rb
140
+ - lib/entities/core.rb
141
+ - lib/entities/game.rb
142
+ - lib/entities/wellcome.rb
143
+ - lib/modules/input_helper.rb
144
+ - lib/modules/phrases.rb
145
+ - lib/modules/storage.rb
146
+ - lib/modules/validator.rb
147
+ - pkg/codebreaker-0.1.2.gem
148
+ - pkg/codebreaker-0.1.3.gem
149
+ homepage: https://github.com/kolyanjy/codebreaker-gem.git
150
+ licenses:
151
+ - MIT
152
+ metadata: {}
153
+ post_install_message:
154
+ rdoc_options: []
155
+ require_paths:
156
+ - lib
157
+ required_ruby_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ required_rubygems_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ requirements: []
168
+ rubygems_version: 3.0.2
169
+ signing_key:
170
+ specification_version: 4
171
+ summary: codebreaker gem
172
+ test_files: []