codebreaker_Bavykin 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +6 -0
- data/.rspec +3 -0
- data/.ruby-gemset +1 -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 +58 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/codebreaker.gemspec +39 -0
- data/lib/codebreaker.rb +12 -0
- data/lib/codebreaker/console.rb +125 -0
- data/lib/codebreaker/game.rb +60 -0
- data/lib/codebreaker/src/phrases.yml +23 -0
- data/lib/codebreaker/storage.rb +22 -0
- data/lib/codebreaker/version.rb +5 -0
- metadata +135 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 35525184bc14aec129f1e4aa5fc177cf5954957e
|
4
|
+
data.tar.gz: 46480b3c65001ae1fd90c541107c4adf021516ca
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 13c77c7c48a79626fda3ebb604055e351111c5dde5b635909876b8b65ef42b7fb770ee58bd5a2526745d51f2552e3ecd857e3c637e5f621f02677ead805dd8e5
|
7
|
+
data.tar.gz: 6284babb20532732a56e29dd7155dfcbb7478465fc55851bef6e0a388c74ac286832ca4927ac559b2d1723aa907e1e82979c3091ceb45dd7ed81275e2b969fbb
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
codebreaker
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.3.0
|
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 1996@3g.ua. 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,58 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
codebreaker (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.3.0)
|
10
|
+
coderay (1.1.2)
|
11
|
+
diff-lcs (1.3)
|
12
|
+
method_source (0.9.0)
|
13
|
+
parallel (1.12.0)
|
14
|
+
parser (2.4.0.2)
|
15
|
+
ast (~> 2.3)
|
16
|
+
powerpack (0.1.1)
|
17
|
+
pry (0.11.3)
|
18
|
+
coderay (~> 1.1.0)
|
19
|
+
method_source (~> 0.9.0)
|
20
|
+
rainbow (2.2.2)
|
21
|
+
rake
|
22
|
+
rake (10.5.0)
|
23
|
+
rspec (3.7.0)
|
24
|
+
rspec-core (~> 3.7.0)
|
25
|
+
rspec-expectations (~> 3.7.0)
|
26
|
+
rspec-mocks (~> 3.7.0)
|
27
|
+
rspec-core (3.7.0)
|
28
|
+
rspec-support (~> 3.7.0)
|
29
|
+
rspec-expectations (3.7.0)
|
30
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
+
rspec-support (~> 3.7.0)
|
32
|
+
rspec-mocks (3.7.0)
|
33
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
+
rspec-support (~> 3.7.0)
|
35
|
+
rspec-support (3.7.0)
|
36
|
+
rubocop (0.51.0)
|
37
|
+
parallel (~> 1.10)
|
38
|
+
parser (>= 2.3.3.1, < 3.0)
|
39
|
+
powerpack (~> 0.1)
|
40
|
+
rainbow (>= 2.2.2, < 3.0)
|
41
|
+
ruby-progressbar (~> 1.7)
|
42
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
43
|
+
ruby-progressbar (1.9.0)
|
44
|
+
unicode-display_width (1.3.0)
|
45
|
+
|
46
|
+
PLATFORMS
|
47
|
+
ruby
|
48
|
+
|
49
|
+
DEPENDENCIES
|
50
|
+
bundler (~> 1.16)
|
51
|
+
codebreaker!
|
52
|
+
pry (~> 0.11.3)
|
53
|
+
rake (~> 10.0)
|
54
|
+
rspec (~> 3.0)
|
55
|
+
rubocop (~> 0.51.0)
|
56
|
+
|
57
|
+
BUNDLED WITH
|
58
|
+
1.16.0
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Dmitriy Bavykin
|
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
|
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
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'codebreaker'
|
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. 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. 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 project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/codebreaker/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'codebreaker'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/codebreaker.gemspec
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
lib = File.expand_path('../lib', __FILE__)
|
5
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
|
+
require 'codebreaker/version'
|
7
|
+
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = 'codebreaker_Bavykin'
|
10
|
+
spec.version = Codebreaker::VERSION
|
11
|
+
spec.authors = ['Dmitriy Bavykin']
|
12
|
+
spec.email = ['6aBblKuH@gmail.com']
|
13
|
+
spec.summary = 'My first summary'
|
14
|
+
spec.description = 'My first codebreaker'
|
15
|
+
spec.homepage = "https://github.com/6aBblKuH/codebreaker"
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
19
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
20
|
+
if spec.respond_to?(:metadata)
|
21
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
22
|
+
else
|
23
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
24
|
+
'public gem pushes.'
|
25
|
+
end
|
26
|
+
|
27
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
28
|
+
f.match(%r{^(test|spec|features)/})
|
29
|
+
end
|
30
|
+
spec.bindir = 'exe'
|
31
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
32
|
+
spec.require_paths = ['lib']
|
33
|
+
|
34
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
35
|
+
spec.add_development_dependency 'pry', '~> 0.11.3'
|
36
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
37
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
38
|
+
spec.add_development_dependency 'rubocop', '~> 0.51.0'
|
39
|
+
end
|
data/lib/codebreaker.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'codebreaker/version'
|
4
|
+
require 'yaml'
|
5
|
+
require 'pry'
|
6
|
+
require_relative 'codebreaker/console'
|
7
|
+
require_relative 'codebreaker/storage'
|
8
|
+
require_relative 'codebreaker/game'
|
9
|
+
|
10
|
+
module Codebreaker
|
11
|
+
Codebreaker::Console.new
|
12
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Codebreaker
|
4
|
+
|
5
|
+
class Console
|
6
|
+
attr_reader :game, :difficulty_name
|
7
|
+
|
8
|
+
def welcome
|
9
|
+
output(:welcome)
|
10
|
+
welcome_instructions
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def welcome_instructions
|
16
|
+
case ask(:welcome_instruction).downcase
|
17
|
+
when 'game' then new_game
|
18
|
+
when 'stats' then output_statistics
|
19
|
+
when 'exit' then exit
|
20
|
+
else
|
21
|
+
output(:spelling_error)
|
22
|
+
welcome_instructions
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def new_game
|
27
|
+
rules
|
28
|
+
handle_difficulty
|
29
|
+
@game = Codebreaker::Game.new(difficulty_name)
|
30
|
+
game_round
|
31
|
+
end
|
32
|
+
|
33
|
+
def game_round
|
34
|
+
while game.attempts.positive?
|
35
|
+
user_answer = round_question(game.attempts)
|
36
|
+
next hint if user_answer == 'hint'
|
37
|
+
return win if game.equal_codes?(user_answer)
|
38
|
+
round_message(user_answer)
|
39
|
+
end
|
40
|
+
lose
|
41
|
+
end
|
42
|
+
|
43
|
+
def handle_difficulty
|
44
|
+
@difficulty_name = ask(:choose_difficulty).to_sym
|
45
|
+
return if Game::DIFFICULTIES.key? @difficulty_name
|
46
|
+
output(:spelling_error)
|
47
|
+
handle_difficulty
|
48
|
+
end
|
49
|
+
|
50
|
+
def hint
|
51
|
+
msg = game.hints.empty? ? :no_hint : game.take_a_hint!
|
52
|
+
output(msg)
|
53
|
+
end
|
54
|
+
|
55
|
+
def round_message(user_answer)
|
56
|
+
message = game.valid_answer?(user_answer) ? game.handle_guess(user_answer) : :invalid_number
|
57
|
+
output(message)
|
58
|
+
end
|
59
|
+
|
60
|
+
def output(message)
|
61
|
+
puts message.is_a?(Symbol) ? phrases[message] : message
|
62
|
+
end
|
63
|
+
|
64
|
+
def ask(question)
|
65
|
+
output(question) if question
|
66
|
+
gets.chomp
|
67
|
+
end
|
68
|
+
|
69
|
+
def dichotomy_question?(question)
|
70
|
+
answer = ask(question).downcase
|
71
|
+
%w[yes y yeap].include?(answer)
|
72
|
+
end
|
73
|
+
|
74
|
+
def rules
|
75
|
+
output(:rules)
|
76
|
+
difficulty_rules
|
77
|
+
end
|
78
|
+
|
79
|
+
def output_statistics
|
80
|
+
handle_statistics_for_output.each { |record| output(record) }
|
81
|
+
welcome_instructions
|
82
|
+
end
|
83
|
+
|
84
|
+
def round_question(attempts)
|
85
|
+
ask("#{phrases[:round_question]}#{attempts}")
|
86
|
+
end
|
87
|
+
|
88
|
+
def win
|
89
|
+
output(:win)
|
90
|
+
Codebreaker::Storage.save_score(score_data) if dichotomy_question?(:save_score)
|
91
|
+
dichotomy_question?(:new_game) ? new_game : output(:goodbye)
|
92
|
+
end
|
93
|
+
|
94
|
+
def lose
|
95
|
+
output(phrases[:lose] << game.secret_code.join)
|
96
|
+
dichotomy_question?(:new_game) ? new_game : output(:goodbye)
|
97
|
+
end
|
98
|
+
|
99
|
+
def difficulty_rules
|
100
|
+
Game::DIFFICULTIES.each do |diff_name, params|
|
101
|
+
output("#{diff_name}: #{params[:attempts]} attempts and #{params[:hints]} hints")
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def phrases
|
106
|
+
@phrases ||= Codebreaker::Storage.load_file('phrases')
|
107
|
+
end
|
108
|
+
|
109
|
+
def statistics
|
110
|
+
@statistics ||= Codebreaker::Storage.load_file('statistics')
|
111
|
+
end
|
112
|
+
|
113
|
+
def handle_statistics_for_output
|
114
|
+
statistics.map do |record|
|
115
|
+
"#{record[:name]} won the game on #{record[:difficulty]} level and still had #{record[:attempts]} attempts and #{record[:hints]} hints"
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def score_data
|
120
|
+
name = ask(:username)
|
121
|
+
{ name: name, difficulty: @difficulty_name, attempts: game.attempts, hints: game.hints.size }
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Codebreaker
|
4
|
+
|
5
|
+
class Game
|
6
|
+
DIFFICULTIES = {
|
7
|
+
easy: { attempts: 30, hints: 3 },
|
8
|
+
medium: { attempts: 15, hints: 2 },
|
9
|
+
hard: { attempts: 10, hints: 1 }
|
10
|
+
}.freeze
|
11
|
+
|
12
|
+
attr_reader :attempts, :hints, :secret_code
|
13
|
+
attr_accessor :user_code
|
14
|
+
|
15
|
+
def initialize(difficulty)
|
16
|
+
@secret_code = Array.new(4) { rand(1..6) }
|
17
|
+
@attempts = DIFFICULTIES.dig(difficulty, :attempts)
|
18
|
+
@hints = secret_code.shuffle.take(DIFFICULTIES.dig(difficulty, :hints))
|
19
|
+
end
|
20
|
+
|
21
|
+
def handle_guess(user_answer)
|
22
|
+
@user_code = user_answer.each_char.map(&:to_i)
|
23
|
+
handle_numbers
|
24
|
+
@attempts -= 1
|
25
|
+
@round_result.empty? ? 'No matches' : @round_result
|
26
|
+
end
|
27
|
+
|
28
|
+
def valid_answer?(user_answer)
|
29
|
+
user_answer =~ /^[1-6]{4}$/
|
30
|
+
end
|
31
|
+
|
32
|
+
def take_a_hint!
|
33
|
+
@hints.pop
|
34
|
+
end
|
35
|
+
|
36
|
+
def equal_codes?(user_answer)
|
37
|
+
secret_code.join == user_answer
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def check_numbers_for_correct_position
|
43
|
+
secret_code.map.with_index do |element, index|
|
44
|
+
next element unless element == user_code[index]
|
45
|
+
user_code[index] = nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def handle_numbers
|
50
|
+
uncatched_numbers = check_numbers_for_correct_position
|
51
|
+
@round_result = '+' * uncatched_numbers.select(&:nil?).size
|
52
|
+
user_code.compact.map do |number|
|
53
|
+
next unless uncatched_numbers.compact.include?(number)
|
54
|
+
@round_result += '-'
|
55
|
+
uncatched_numbers[uncatched_numbers.index(number)] = nil
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
:choose_difficulty: 'Choose the difficulty lvl'
|
2
|
+
:codebreaker_logo:
|
3
|
+
"_____ ______ ______ ______ _____ ____\n
|
4
|
+
| ___| | __ | | _ \ | ___| | _ \ |\n
|
5
|
+
| | | | | | | | \ | | | | |_| | |\n
|
6
|
+
| | | | | | | | | | | |__ |_____| |\n
|
7
|
+
| | | | | | | | | | | __| | _ \ | _\n
|
8
|
+
| |__ | |__| | | |_/ | | |__ | |_| | | | \\\n
|
9
|
+
|_____| |______| |_____/ |_____| |_____| |__| \_|\n
|
10
|
+
"
|
11
|
+
:welcome: "Welcome to CO-CO-CO-Coooodebreaker."
|
12
|
+
:welcome_instruction: "Type 'game' for starting new game.\nType 'stats' for showing statistics\nType 'exit' for exit"
|
13
|
+
:rules: "You have to guess 4-digit number where each digit placed between 1 and 6.\nThe code-maker then marks the guess with up to four + and - signs.\nA + indicates an exact match: one of the numbers in the guess is the same.\nA - indicates a number match: one of the numbers in the guess is the same as one of the numbers in the secret code but in a different position."
|
14
|
+
:win: 'Congrat. U did it'
|
15
|
+
:lose: 'What do we say God of Games? Not today. Secret code was - '
|
16
|
+
:no_hint: 'Hints are over'
|
17
|
+
:round_question: "Put the number. Attempts remain - "
|
18
|
+
:invalid_number: 'Put 4-digital number'
|
19
|
+
:spelling_error: 'Spelling error'
|
20
|
+
:new_game: 'Play one more? (y/n)'
|
21
|
+
:save_score: 'Save your score? (y/n)'
|
22
|
+
:username: 'What is your name?'
|
23
|
+
:goodbye: 'Thank you for game'
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Codebreaker::Storage
|
4
|
+
PATH = 'lib/codebreaker/src/'
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def load_file(filename)
|
8
|
+
YAML.load_file(file_path(filename)) if File.exist?(file_path(filename))
|
9
|
+
end
|
10
|
+
|
11
|
+
def file_path(filename)
|
12
|
+
"#{PATH}#{filename}.yml"
|
13
|
+
end
|
14
|
+
|
15
|
+
def save_score(data)
|
16
|
+
current_file_path = file_path(:statistics)
|
17
|
+
File.new(current_file_path, 'w+') unless File.exist?(current_file_path)
|
18
|
+
record = load_file('statistics') || []
|
19
|
+
File.write(current_file_path, (record << data).to_yaml)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: codebreaker_Bavykin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dmitriy Bavykin
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-12-17 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: pry
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.11.3
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.11.3
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.51.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.51.0
|
83
|
+
description: My first codebreaker
|
84
|
+
email:
|
85
|
+
- 6aBblKuH@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".ruby-gemset"
|
93
|
+
- ".ruby-version"
|
94
|
+
- ".travis.yml"
|
95
|
+
- CODE_OF_CONDUCT.md
|
96
|
+
- Gemfile
|
97
|
+
- Gemfile.lock
|
98
|
+
- LICENSE.txt
|
99
|
+
- README.md
|
100
|
+
- Rakefile
|
101
|
+
- bin/console
|
102
|
+
- bin/setup
|
103
|
+
- codebreaker.gemspec
|
104
|
+
- lib/codebreaker.rb
|
105
|
+
- lib/codebreaker/console.rb
|
106
|
+
- lib/codebreaker/game.rb
|
107
|
+
- lib/codebreaker/src/phrases.yml
|
108
|
+
- lib/codebreaker/storage.rb
|
109
|
+
- lib/codebreaker/version.rb
|
110
|
+
homepage: https://github.com/6aBblKuH/codebreaker
|
111
|
+
licenses:
|
112
|
+
- MIT
|
113
|
+
metadata:
|
114
|
+
allowed_push_host: https://rubygems.org
|
115
|
+
post_install_message:
|
116
|
+
rdoc_options: []
|
117
|
+
require_paths:
|
118
|
+
- lib
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
requirements: []
|
130
|
+
rubyforge_project:
|
131
|
+
rubygems_version: 2.5.1
|
132
|
+
signing_key:
|
133
|
+
specification_version: 4
|
134
|
+
summary: My first summary
|
135
|
+
test_files: []
|