codebreaker_rg_game 1.1 → 1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/codebreaker.gemspec +3 -4
- data/lib/codebreaker/version.rb +1 -1
- data/lib/dependency.rb +0 -5
- metadata +5 -30
- data/.circleci/config.yml +0 -46
- data/.fasterer.yml +0 -22
- data/.gitignore +0 -9
- data/.rubocop.yml +0 -9
- data/database/.keep +0 -0
- data/lib/codebreaker/entities/console.rb +0 -137
- data/lib/codebreaker/entities/statistics.rb +0 -31
- data/lib/codebreaker/utils/yaml_mapper.rb +0 -20
- data/lib/config/i18n_config.rb +0 -5
- data/lib/locales/en.yml +0 -49
- data/main.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7abda3870f0cd213a68d6e2ca1c0f438ec6c0e574dfac2971220ffed81fa792f
|
4
|
+
data.tar.gz: bfa7b539d33a4c3568c710062cbe281788b1a5de19c21e86026a6f05aa3f597f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 225e4530897b8eec606febd43f6a277aed07724168dddc327ab0ceb8f03e2157d50c2db596e931d7fb10812575733b1483356c08086ab5a4333faebfad795f10
|
7
|
+
data.tar.gz: 2a734ff1671f4d3ffb45f28a08169b8c5426027c21e1cdae9fb27600da08df2b2ef50e61feb3606146635f7e8e7cfb90995f288bbbe9a2e108102b4c2f397b79
|
data/codebreaker.gemspec
CHANGED
@@ -12,14 +12,14 @@ Gem::Specification.new do |spec|
|
|
12
12
|
|
13
13
|
spec.summary = 'Codebreaker'
|
14
14
|
spec.description = 'game'
|
15
|
-
spec.homepage = 'https://github.com/YaroslavZahoruiko/
|
15
|
+
spec.homepage = 'https://github.com/YaroslavZahoruiko/codebreaker-gem'
|
16
16
|
spec.license = 'MIT'
|
17
17
|
|
18
18
|
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
19
19
|
|
20
20
|
spec.metadata['homepage_uri'] = spec.homepage
|
21
|
-
spec.metadata['source_code_uri'] = 'https://github.com/YaroslavZahoruiko/
|
22
|
-
spec.metadata['changelog_uri'] = 'https://github.com/YaroslavZahoruiko/
|
21
|
+
spec.metadata['source_code_uri'] = 'https://github.com/YaroslavZahoruiko/codebreaker-gem'
|
22
|
+
spec.metadata['changelog_uri'] = 'https://github.com/YaroslavZahoruiko/codebreaker-gem/tree/devCHANGELOG.md'
|
23
23
|
|
24
24
|
# Specify which files should be added to the gem when it is released.
|
25
25
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
@@ -32,7 +32,6 @@ Gem::Specification.new do |spec|
|
|
32
32
|
|
33
33
|
spec.add_development_dependency 'bundler', '~> 2.0'
|
34
34
|
spec.add_development_dependency 'fasterer', '~> 0.5.1'
|
35
|
-
spec.add_development_dependency 'i18n', '~> 1.6'
|
36
35
|
spec.add_development_dependency 'pry', '~> 0.12.2'
|
37
36
|
spec.add_development_dependency 'rake', '~> 10.0'
|
38
37
|
spec.add_development_dependency 'rspec', '~> 3.8'
|
data/lib/codebreaker/version.rb
CHANGED
data/lib/dependency.rb
CHANGED
@@ -1,12 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'i18n'
|
4
3
|
require 'pry'
|
5
4
|
require_relative 'codebreaker/utils/verifier'
|
6
|
-
require_relative 'codebreaker/entities/console'
|
7
5
|
require_relative 'codebreaker/entities/player'
|
8
6
|
require_relative 'codebreaker/codebreaker'
|
9
|
-
require_relative 'codebreaker/utils/yaml_mapper'
|
10
|
-
require_relative 'config/i18n_config'
|
11
7
|
require_relative 'codebreaker/entities/difficulties'
|
12
|
-
require_relative 'codebreaker/entities/statistics'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codebreaker_rg_game
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '1.
|
4
|
+
version: '1.2'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yaroslav Zahoruiko
|
@@ -38,20 +38,6 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.5.1
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: i18n
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '1.6'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '1.6'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: pry
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -129,10 +115,6 @@ executables: []
|
|
129
115
|
extensions: []
|
130
116
|
extra_rdoc_files: []
|
131
117
|
files:
|
132
|
-
- ".circleci/config.yml"
|
133
|
-
- ".fasterer.yml"
|
134
|
-
- ".gitignore"
|
135
|
-
- ".rubocop.yml"
|
136
118
|
- CHANGELOG.mb
|
137
119
|
- CODE_OF_CONDUCT.md
|
138
120
|
- Gemfile
|
@@ -143,28 +125,21 @@ files:
|
|
143
125
|
- bin/console
|
144
126
|
- bin/setup
|
145
127
|
- codebreaker.gemspec
|
146
|
-
- database/.keep
|
147
128
|
- lib/codebreaker.rb
|
148
129
|
- lib/codebreaker/codebreaker.rb
|
149
|
-
- lib/codebreaker/entities/console.rb
|
150
130
|
- lib/codebreaker/entities/difficulties.rb
|
151
131
|
- lib/codebreaker/entities/player.rb
|
152
|
-
- lib/codebreaker/entities/statistics.rb
|
153
132
|
- lib/codebreaker/utils/verifier.rb
|
154
|
-
- lib/codebreaker/utils/yaml_mapper.rb
|
155
133
|
- lib/codebreaker/version.rb
|
156
|
-
- lib/config/i18n_config.rb
|
157
134
|
- lib/dependency.rb
|
158
|
-
|
159
|
-
- main.rb
|
160
|
-
homepage: https://github.com/YaroslavZahoruiko/Codebreaker
|
135
|
+
homepage: https://github.com/YaroslavZahoruiko/codebreaker-gem
|
161
136
|
licenses:
|
162
137
|
- MIT
|
163
138
|
metadata:
|
164
139
|
allowed_push_host: https://rubygems.org
|
165
|
-
homepage_uri: https://github.com/YaroslavZahoruiko/
|
166
|
-
source_code_uri: https://github.com/YaroslavZahoruiko/
|
167
|
-
changelog_uri: https://github.com/YaroslavZahoruiko/
|
140
|
+
homepage_uri: https://github.com/YaroslavZahoruiko/codebreaker-gem
|
141
|
+
source_code_uri: https://github.com/YaroslavZahoruiko/codebreaker-gem
|
142
|
+
changelog_uri: https://github.com/YaroslavZahoruiko/codebreaker-gem/tree/devCHANGELOG.md
|
168
143
|
post_install_message:
|
169
144
|
rdoc_options: []
|
170
145
|
require_paths:
|
data/.circleci/config.yml
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
version: 2
|
2
|
-
jobs:
|
3
|
-
build:
|
4
|
-
docker:
|
5
|
-
- image: circleci/ruby:2.6.0-node
|
6
|
-
environment:
|
7
|
-
BUNDLER_VERSION: 2.0.1
|
8
|
-
|
9
|
-
working_directory: ~/repo
|
10
|
-
|
11
|
-
steps:
|
12
|
-
- checkout
|
13
|
-
|
14
|
-
# Download and cache dependencies
|
15
|
-
- restore_cache:
|
16
|
-
keys:
|
17
|
-
- v1-dependencies-{{ checksum "Gemfile.lock" }}
|
18
|
-
# fallback to using the latest cache if no exact match is found
|
19
|
-
- v1-dependencies-
|
20
|
-
|
21
|
-
- run:
|
22
|
-
name: install dependencies
|
23
|
-
command: |
|
24
|
-
bundle install --jobs=4 --retry=3 --path vendor/bundle
|
25
|
-
gem update --system
|
26
|
-
gem install bundler
|
27
|
-
- save_cache:
|
28
|
-
paths:
|
29
|
-
- ./vendor/bundle
|
30
|
-
key: v1-dependencies-{{ checksum "Gemfile.lock" }}
|
31
|
-
|
32
|
-
# run tests!
|
33
|
-
- run:
|
34
|
-
name: run tests
|
35
|
-
command: |
|
36
|
-
mkdir /tmp/test-results
|
37
|
-
bundle exec rspec --format progress \
|
38
|
-
--out /tmp/test-results/rspec.xml \
|
39
|
-
--format progress \
|
40
|
-
$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)
|
41
|
-
# collect reports
|
42
|
-
- store_test_results:
|
43
|
-
path: /tmp/test-results
|
44
|
-
- store_artifacts:
|
45
|
-
path: /tmp/test-results
|
46
|
-
destination: test-results
|
data/.fasterer.yml
DELETED
@@ -1,22 +0,0 @@
|
|
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
|
20
|
-
|
21
|
-
exclude_paths:
|
22
|
-
- 'spec/**/*.rb'
|
data/.gitignore
DELETED
data/.rubocop.yml
DELETED
data/database/.keep
DELETED
File without changes
|
@@ -1,137 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class Console
|
4
|
-
include Codebreaker
|
5
|
-
COMMANDS = {
|
6
|
-
start: 'start',
|
7
|
-
rules: 'rules',
|
8
|
-
stats: 'stats',
|
9
|
-
exit: 'exit',
|
10
|
-
hint: 'hint',
|
11
|
-
yes: 'y',
|
12
|
-
no: 'n',
|
13
|
-
win: 'win'
|
14
|
-
}.freeze
|
15
|
-
|
16
|
-
def initialize
|
17
|
-
@state = :choice_main
|
18
|
-
end
|
19
|
-
|
20
|
-
def run
|
21
|
-
loop do
|
22
|
-
send(@state)
|
23
|
-
break if @state == :exit
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def welcome
|
28
|
-
show :welcome
|
29
|
-
end
|
30
|
-
|
31
|
-
def goodbye
|
32
|
-
show :goodbye
|
33
|
-
end
|
34
|
-
|
35
|
-
private
|
36
|
-
|
37
|
-
def choice_main
|
38
|
-
show(:menu)
|
39
|
-
case input
|
40
|
-
when COMMANDS[:start] then @state = :register_name
|
41
|
-
when COMMANDS[:rules] then @state = :rules
|
42
|
-
when COMMANDS[:stats] then @state = :output_stats
|
43
|
-
when COMMANDS[:exit] then @state = :exit
|
44
|
-
else show(:invalid_command)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def register_name
|
49
|
-
show(:name_request)
|
50
|
-
|
51
|
-
name = input
|
52
|
-
|
53
|
-
@player = Player.new(name)
|
54
|
-
@player.validate ? @state = :register_difficulty : show(:invalid_name)
|
55
|
-
end
|
56
|
-
|
57
|
-
def register_difficulty
|
58
|
-
show(:difficulty_request)
|
59
|
-
|
60
|
-
difficult = input.downcase
|
61
|
-
|
62
|
-
if Difficulties.valid_difficult(difficult)
|
63
|
-
@difficult = Difficulties.new(difficult)
|
64
|
-
@state = :create_game
|
65
|
-
else
|
66
|
-
show(:invalid_difficulty)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def create_game
|
71
|
-
@codebreaker = Game.new(@player, @difficult)
|
72
|
-
@state = :game_process
|
73
|
-
end
|
74
|
-
|
75
|
-
def game_process
|
76
|
-
return @state = :lose if @codebreaker.lose?
|
77
|
-
|
78
|
-
show(:game_process)
|
79
|
-
code = input
|
80
|
-
return @state = :hint if hint?(code)
|
81
|
-
|
82
|
-
return @state = :win if @codebreaker.win?(code)
|
83
|
-
|
84
|
-
result = @codebreaker.check_code(code)
|
85
|
-
return show(:invalid_code) if result.nil?
|
86
|
-
|
87
|
-
puts result
|
88
|
-
end
|
89
|
-
|
90
|
-
def win
|
91
|
-
show(:win_game_message)
|
92
|
-
@state = :save_stats
|
93
|
-
end
|
94
|
-
|
95
|
-
def lose
|
96
|
-
show(:lost_game_message, code: @codebreaker.number.join)
|
97
|
-
@state = :choice_main
|
98
|
-
end
|
99
|
-
|
100
|
-
def hint
|
101
|
-
@codebreaker.hints? ? show(:hint_message, hint: @codebreaker.hint) : show(:no_hints_message)
|
102
|
-
@state = :game_process
|
103
|
-
end
|
104
|
-
|
105
|
-
def rules
|
106
|
-
show(:rules)
|
107
|
-
@state = :choice_main
|
108
|
-
end
|
109
|
-
|
110
|
-
def save_stats
|
111
|
-
show(:save_result)
|
112
|
-
if input == COMMANDS[:yes]
|
113
|
-
Statistics.save(@codebreaker.to_h)
|
114
|
-
@state = :choice_main
|
115
|
-
elsif input == COMMANDS[:no]
|
116
|
-
@state = :choice_main
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
def output_stats
|
121
|
-
puts Statistics.output
|
122
|
-
@state = :choice_main
|
123
|
-
end
|
124
|
-
|
125
|
-
def hint?(code)
|
126
|
-
code == COMMANDS[:hint]
|
127
|
-
end
|
128
|
-
|
129
|
-
def show(message, optional = {})
|
130
|
-
puts I18n.t(message, optional)
|
131
|
-
end
|
132
|
-
|
133
|
-
def input
|
134
|
-
user_input = gets.chomp
|
135
|
-
user_input.downcase == COMMANDS[:exit] ? @state = :exit : user_input
|
136
|
-
end
|
137
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Codebreaker
|
4
|
-
class Statistics
|
5
|
-
class << self
|
6
|
-
def save(stats)
|
7
|
-
YamlMapper.save(stats)
|
8
|
-
end
|
9
|
-
|
10
|
-
def output
|
11
|
-
stats = load
|
12
|
-
sort(stats)
|
13
|
-
hash_stats = {}
|
14
|
-
stats.each_index do |index|
|
15
|
-
hash_stats[index] = stats[index].to_s
|
16
|
-
end
|
17
|
-
hash_stats.to_a
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
def sort(array_stats)
|
23
|
-
array_stats.sort_by! { |stats| [stats[:attempts_used], stats[:hints_used]] }.reverse
|
24
|
-
end
|
25
|
-
|
26
|
-
def load
|
27
|
-
YamlMapper.load
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Codebreaker
|
4
|
-
class YamlMapper
|
5
|
-
PATH = 'database/codebreaker_db.yml'
|
6
|
-
class << self
|
7
|
-
def save(object)
|
8
|
-
stats = load
|
9
|
-
stats << object
|
10
|
-
File.open(PATH, 'w') do |file|
|
11
|
-
file.write(stats.to_yaml)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def load
|
16
|
-
File.file?(PATH) ? YAML.load(File.read(PATH)) : []
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
data/lib/config/i18n_config.rb
DELETED
data/lib/locales/en.yml
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
en:
|
2
|
-
welcome: "Welcome to codebreaker game."
|
3
|
-
|
4
|
-
goodbye: "\nGoodbye!"
|
5
|
-
|
6
|
-
lost_game_message: "Oh, your attempts ended... Your code was: %{code}"
|
7
|
-
|
8
|
-
no_hints_message: "Oh, your hints ended"
|
9
|
-
|
10
|
-
win_game_message: "Yayy, u won the game! Congrats!"
|
11
|
-
|
12
|
-
menu: "\nStart\nStats\nRules\nExit\n"
|
13
|
-
|
14
|
-
hint_message: "\n hint: %{hint}"
|
15
|
-
|
16
|
-
name_request: "\nType your name"
|
17
|
-
|
18
|
-
difficulty_request: "\nChoose difficulty\nEasy\nMedium\nHell"
|
19
|
-
|
20
|
-
save_result: "\n\nAre you want to save your score? (Y/n)"
|
21
|
-
|
22
|
-
game_process: "\nChoose one from option below or type your guess
|
23
|
-
\nType 'hint'
|
24
|
-
\nType 'exit'
|
25
|
-
\nYour guess\n"
|
26
|
-
|
27
|
-
invalid_name: "\n Name must be between 3 and 20 characters long!"
|
28
|
-
|
29
|
-
invalid_difficulty: "\n Invalid difficulty!"
|
30
|
-
|
31
|
-
invalid_command: "\n You have passed unexpected command. Please choose one from listed commands"
|
32
|
-
|
33
|
-
invalid_code: "\n code must be number, required, length - 4 digits, each digit is a number in the range 1-6"
|
34
|
-
|
35
|
-
rules: "codebreaker is a logic game in which a code-breaker tries to break a secret code created by a code-maker.
|
36
|
-
\n The codemaker, which will be played by the application we’re going to write, creates a secret code of four numbers between 1 and 6.
|
37
|
-
\n The codebreaker gets some number of chances to break the code (depends on chosen difficulty). In each turn, the codebreaker makes a guess of 4 numbers.
|
38
|
-
\n The codemaker then marks the guess with up to 4 signs - + or - or empty spaces.
|
39
|
-
\n A + indicates an exact match: one of the numbers in the guess is the same as one of the numbers in the secret code and in the same position. For example:
|
40
|
-
\n Secret number - 1234
|
41
|
-
\n Input number - 6264
|
42
|
-
\n Number of pluses - 2 (second and fourth position)
|
43
|
-
\n A - 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. For example:
|
44
|
-
\n Secret number - 1234
|
45
|
-
\n Input number - 6462
|
46
|
-
\n Number of minuses - 2 (second and fourth position)
|
47
|
-
\n An empty space indicates that there is not a current digit in a secret number.
|
48
|
-
\n If codebreaker inputs the exact number as a secret number - codebreaker wins the game. If all attempts are spent - codebreaker loses.
|
49
|
-
\n codebreaker also has some number of hints(depends on chosen difficulty). If a user takes a hint - he receives back a separate digit of the secret code."
|