morph_codebreaker 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/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +35 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/codebreaker.gemspec +38 -0
- data/lib/codebreaker.rb +5 -0
- data/lib/codebreaker/constants.rb +40 -0
- data/lib/codebreaker/game.rb +73 -0
- data/lib/codebreaker/game_console.rb +106 -0
- data/lib/codebreaker/version.rb +3 -0
- data/scores.yml +2 -0
- metadata +104 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: de0a0334de3c0e17bfc454041c71ebdb718a528bb699bc72c5037e3630f1d670
|
|
4
|
+
data.tar.gz: 61223f3a494078b13dcb13afff285913ec0f5e860385fce9f0b0de3b74e7dc9e
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 0a126c058f209d639d3ca88e137c1c759297652bda48a9d8313ee642851c26de01693c6b5c5f7bcf69bc9cf629b767b96d3ea39097bd6d9c76aa1ff3363ac8a0
|
|
7
|
+
data.tar.gz: 036a058af029d8d09beef95eb4a47731d6cd6ecce34e54f9d04af5dfce95c1a68e459eb5b24a2f2f99401dea37598cda8990e5e0227c1ec0eb9ec375663604dd
|
data/.gitignore
ADDED
data/.rspec
ADDED
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 Creatorsk@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,35 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
morph_codebreaker (0.1.0)
|
|
5
|
+
|
|
6
|
+
GEM
|
|
7
|
+
remote: https://rubygems.org/
|
|
8
|
+
specs:
|
|
9
|
+
diff-lcs (1.3)
|
|
10
|
+
rake (10.5.0)
|
|
11
|
+
rspec (3.7.0)
|
|
12
|
+
rspec-core (~> 3.7.0)
|
|
13
|
+
rspec-expectations (~> 3.7.0)
|
|
14
|
+
rspec-mocks (~> 3.7.0)
|
|
15
|
+
rspec-core (3.7.1)
|
|
16
|
+
rspec-support (~> 3.7.0)
|
|
17
|
+
rspec-expectations (3.7.0)
|
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
19
|
+
rspec-support (~> 3.7.0)
|
|
20
|
+
rspec-mocks (3.7.0)
|
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
22
|
+
rspec-support (~> 3.7.0)
|
|
23
|
+
rspec-support (3.7.1)
|
|
24
|
+
|
|
25
|
+
PLATFORMS
|
|
26
|
+
ruby
|
|
27
|
+
|
|
28
|
+
DEPENDENCIES
|
|
29
|
+
bundler (~> 1.16)
|
|
30
|
+
morph_codebreaker!
|
|
31
|
+
rake (~> 10.0)
|
|
32
|
+
rspec
|
|
33
|
+
|
|
34
|
+
BUNDLED WITH
|
|
35
|
+
1.16.2
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 MorpheusFR
|
|
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,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
data/codebreaker.gemspec
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
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 = "morph_codebreaker"
|
|
8
|
+
spec.version = Codebreaker::VERSION
|
|
9
|
+
spec.authors = ["MorpheusFR"]
|
|
10
|
+
spec.email = ["Creatorsk@gmail.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = %q{My codebreaker}
|
|
13
|
+
spec.description = %q{A game based on bull and cow rules.}
|
|
14
|
+
spec.homepage = "https://github.com/MorpheusFR/codebreaker.git"
|
|
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"] = "TODO: Set to 'http://mygemserver.com'"
|
|
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
|
+
end
|
data/lib/codebreaker.rb
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
module Codebreaker
|
|
2
|
+
ATTEMPTS = 6
|
|
3
|
+
HINTS = 4
|
|
4
|
+
PATH_TO_LOG_FILES = './scores.yml'.freeze
|
|
5
|
+
GAME_TURN = "Play turn/attempt "
|
|
6
|
+
WON = "... You won!!! ...".freeze
|
|
7
|
+
LOOS = "... You loos :( ...".freeze
|
|
8
|
+
THE_HINTS_ENDED = "You are losing because the tips have ended".freeze
|
|
9
|
+
RESTART_OR_BREAK = "You a ready play more? (y/n)".freeze
|
|
10
|
+
NAME_USER = "Enter your name:".freeze
|
|
11
|
+
|
|
12
|
+
RULES =
|
|
13
|
+
" The code-breaker then gets some number of chances to break the code.\n " \
|
|
14
|
+
" In each turn, the code-breaker makes a guess of four numbers.\n " \
|
|
15
|
+
" The code-maker then marks the guess with up to four + and - signs.\n " \
|
|
16
|
+
"\n" \
|
|
17
|
+
"You have #{ATTEMPTS} attempts and game answers with" \
|
|
18
|
+
" up to four pluses and minuses \n " \
|
|
19
|
+
" \n" \
|
|
20
|
+
" + (plus) indicates an exact match: \n" \
|
|
21
|
+
" one of the numbers in the guess is the same as one of the numbers \n" \
|
|
22
|
+
" in the secret code and in the same position. \n" \
|
|
23
|
+
" - (minus) indicates a number match: \n" \
|
|
24
|
+
" one of the numbers in the guess is the same as one of the numbers \n" \
|
|
25
|
+
" in the secret code but in a different position. \n" \
|
|
26
|
+
" Tips & Tricks \n" \
|
|
27
|
+
"HINTS: type 'h' and game will show one number from code to you \n" \
|
|
28
|
+
"RULES: if you forget the rules, just enter 'rules' " \
|
|
29
|
+
.freeze
|
|
30
|
+
|
|
31
|
+
GREETING_MESSAGE =
|
|
32
|
+
"#######################################################################\n"\
|
|
33
|
+
" CODEBREACKER is a logic game in which a code-breaker tries to break\n"\
|
|
34
|
+
" a secret code created by a code-maker. The code-maker creates a secret\n"\
|
|
35
|
+
" code of four numbers between 1 and 6. \n #{RULES} \n " \
|
|
36
|
+
' GOOD LUCK! ' \
|
|
37
|
+
.freeze
|
|
38
|
+
|
|
39
|
+
LINE = "..................................................................".freeze
|
|
40
|
+
end
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
module Codebreaker
|
|
2
|
+
# Module Game - logic
|
|
3
|
+
class Game
|
|
4
|
+
attr_reader :hints, :hints_used, :total_attempts, :match_result, :turn, :turn_statistic
|
|
5
|
+
|
|
6
|
+
def initialize
|
|
7
|
+
@secret_code = code_generator
|
|
8
|
+
@total_attempts = ATTEMPTS
|
|
9
|
+
@hints = HINTS
|
|
10
|
+
@hints_used = 0
|
|
11
|
+
@match_result = ''
|
|
12
|
+
@turn = 1
|
|
13
|
+
@turn_statistic = {}
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def validate_turn(input_code)
|
|
17
|
+
data_checking input_code
|
|
18
|
+
find_cows_and_bulls input_code
|
|
19
|
+
counter_attepmpts_and_turn
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def counter_attepmpts_and_turn
|
|
23
|
+
@total_attempts -= 1
|
|
24
|
+
GAME_TURN + "#{@turn += 1}"
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def inbound_processing(input_code)
|
|
28
|
+
data_checking input_code
|
|
29
|
+
@attempts -= 1
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def winner?
|
|
33
|
+
@match_result == '++++'
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def get_a_hint
|
|
37
|
+
@hints -= 1
|
|
38
|
+
@hints_used += 1
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def code_view_with_hint
|
|
42
|
+
@secret_code.slice(0, @hints_used) <<
|
|
43
|
+
@secret_code.slice(@hints_used, @secret_code.size).tr(@secret_code, '*')
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
private
|
|
47
|
+
|
|
48
|
+
def code_generator
|
|
49
|
+
(1..4).map { rand(1..6) }.join
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def find_cows_and_bulls(input_code)
|
|
53
|
+
@match_result = ''
|
|
54
|
+
input_code.each_char.with_index do |elem, i|
|
|
55
|
+
@match_result << if @secret_code.include?(elem)
|
|
56
|
+
if input_code[i] == @secret_code[i]
|
|
57
|
+
'+'
|
|
58
|
+
else
|
|
59
|
+
'-'
|
|
60
|
+
end
|
|
61
|
+
else
|
|
62
|
+
' '
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def data_checking(input_code)
|
|
68
|
+
@turn_statistic[@turn] = input_code
|
|
69
|
+
raise ArgumentError, 'Type only integers from 1 to 6' if input_code =~ /[^0-6]/
|
|
70
|
+
raise ArgumentError, 'Type exactly 4 integer' unless input_code.length == 4
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
require 'yaml'
|
|
2
|
+
module Codebreaker
|
|
3
|
+
# Interface for console game 'Codebreacker''
|
|
4
|
+
class GameConsole
|
|
5
|
+
def initialize
|
|
6
|
+
@game = Codebreaker::Game.new
|
|
7
|
+
@path_to_file = PATH_TO_LOG_FILES
|
|
8
|
+
@status = false
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def start_game
|
|
12
|
+
show_congrats
|
|
13
|
+
@game = Codebreaker::Game.new
|
|
14
|
+
play_session
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def play_session
|
|
18
|
+
until @game.total_attempts.zero?
|
|
19
|
+
show_statistic
|
|
20
|
+
case user_input = input_data
|
|
21
|
+
when 'rules' then show_rules
|
|
22
|
+
when 'hint' then @game.get_a_hint
|
|
23
|
+
else show result_on_input_data(user_input)
|
|
24
|
+
end
|
|
25
|
+
break if @game.winner? || @game.hints.zero?
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
@game.winner? ? the_view_for_the_winner : the_view_for_the_loser
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def input_data
|
|
32
|
+
gets.chomp.downcase
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def show_statistic
|
|
36
|
+
# show GAME_TURN + @game.turn.to_s
|
|
37
|
+
puts 'Total attepts = (' + @game.total_attempts.to_s + ')'
|
|
38
|
+
show LINE
|
|
39
|
+
puts "Secret code (decorate) = [#{@game.code_view_with_hint}]".center(60)
|
|
40
|
+
puts "Result (hit statistics) = [#{@game.match_result}]".center(60)
|
|
41
|
+
puts "Try to break the code 'input code' or ask for a 'hint'(#{@game.hints})".center(60)
|
|
42
|
+
show LINE
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def the_view_for_the_winner
|
|
46
|
+
show WON
|
|
47
|
+
@status = true
|
|
48
|
+
finish_or_reset_game
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def the_view_for_the_loser
|
|
52
|
+
show THE_HINTS_ENDED
|
|
53
|
+
puts "Secret code = [#{@game.code_view_with_hint}]"
|
|
54
|
+
show LOOS
|
|
55
|
+
finish_or_reset_game
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def finish_or_reset_game
|
|
59
|
+
save_result
|
|
60
|
+
show RESTART_OR_BREAK
|
|
61
|
+
start_game if input_data == 'y'
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def save_result
|
|
65
|
+
File.open(@path_to_file, 'a') do |f|
|
|
66
|
+
f.puts get_data_to_save_statistic
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def get_data_to_save_statistic
|
|
71
|
+
user_name = get_user_name
|
|
72
|
+
game_result = @status ? 'Win' : 'Loos'
|
|
73
|
+
session_statistic = @game.turn_statistic
|
|
74
|
+
log = { user_name.to_s => [
|
|
75
|
+
"Date: #{session_statistic}",
|
|
76
|
+
'hints geting' => @game.hints_used,
|
|
77
|
+
'Status of game' => game_result
|
|
78
|
+
] }
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def get_user_name
|
|
82
|
+
show NAME_USER
|
|
83
|
+
gets.chomp
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def show(str)
|
|
87
|
+
puts str
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def result_on_input_data(input_data)
|
|
91
|
+
begin
|
|
92
|
+
@game.validate_turn input_data
|
|
93
|
+
rescue ArgumentError
|
|
94
|
+
'ArgumentError message: invalid value, try retrying!'
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def show_congrats
|
|
99
|
+
show GREETING_MESSAGE
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def show_rules
|
|
103
|
+
show RULES
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
data/scores.yml
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
{"Morpheus"=>["Date: {1=>\"1234\", 2=>\"4562\", 3=>\"5346\", 4=>\"6215\", 5=>\"6435\", 6=>\"6655\"}", {"hints geting"=>0, "Status of game"=>"Win"}]}
|
|
2
|
+
{"Morpheus"=>["Date: {1=>\"1234\", 2=>\"5446\", 3=>\"2314\", 4=>\"1234\", 5=>\"1234\", 6=>\"5612\"}", {"hints geting"=>2, "Status of game"=>"Loos"}]}
|
metadata
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: morph_codebreaker
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- MorpheusFR
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2018-07-12 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
|
+
description: A game based on bull and cow rules.
|
|
56
|
+
email:
|
|
57
|
+
- Creatorsk@gmail.com
|
|
58
|
+
executables: []
|
|
59
|
+
extensions: []
|
|
60
|
+
extra_rdoc_files: []
|
|
61
|
+
files:
|
|
62
|
+
- ".gitignore"
|
|
63
|
+
- ".rspec"
|
|
64
|
+
- ".travis.yml"
|
|
65
|
+
- CODE_OF_CONDUCT.md
|
|
66
|
+
- Gemfile
|
|
67
|
+
- Gemfile.lock
|
|
68
|
+
- LICENSE.txt
|
|
69
|
+
- README.md
|
|
70
|
+
- Rakefile
|
|
71
|
+
- bin/console
|
|
72
|
+
- bin/setup
|
|
73
|
+
- codebreaker.gemspec
|
|
74
|
+
- lib/codebreaker.rb
|
|
75
|
+
- lib/codebreaker/constants.rb
|
|
76
|
+
- lib/codebreaker/game.rb
|
|
77
|
+
- lib/codebreaker/game_console.rb
|
|
78
|
+
- lib/codebreaker/version.rb
|
|
79
|
+
- scores.yml
|
|
80
|
+
homepage: https://github.com/MorpheusFR/codebreaker.git
|
|
81
|
+
licenses:
|
|
82
|
+
- MIT
|
|
83
|
+
metadata: {}
|
|
84
|
+
post_install_message:
|
|
85
|
+
rdoc_options: []
|
|
86
|
+
require_paths:
|
|
87
|
+
- lib
|
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
89
|
+
requirements:
|
|
90
|
+
- - ">="
|
|
91
|
+
- !ruby/object:Gem::Version
|
|
92
|
+
version: '0'
|
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
|
+
requirements:
|
|
95
|
+
- - ">="
|
|
96
|
+
- !ruby/object:Gem::Version
|
|
97
|
+
version: '0'
|
|
98
|
+
requirements: []
|
|
99
|
+
rubyforge_project:
|
|
100
|
+
rubygems_version: 2.7.6
|
|
101
|
+
signing_key:
|
|
102
|
+
specification_version: 4
|
|
103
|
+
summary: My codebreaker
|
|
104
|
+
test_files: []
|