codebreakergem 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.fasterer.yml +19 -0
- data/.rubocop.yml +13 -0
- data/.ruby-version +1 -0
- data/Gemfile.lock +70 -0
- data/codebreakergem-0.1.0.gem +0 -0
- data/codebreakergem-0.1.1.gem +0 -0
- data/codebreakergem-0.1.2.gem +0 -0
- data/lib/classes/difficulty.rb +15 -0
- data/lib/classes/file_worker.rb +31 -0
- data/lib/classes/statistic.rb +17 -0
- data/lib/classes/user.rb +17 -0
- data/lib/codebreakergem.rb +4 -6
- data/lib/codebreakergem/version.rb +1 -1
- data/lib/config.rb +5 -0
- data/lib/data/.gitkeep +0 -0
- data/lib/data/data.yml +23 -0
- data/lib/locales/en.yml +46 -0
- data/lib/locales/ru.yml +2 -0
- data/lib/modules/check_module.rb +14 -0
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0c5b1a584661b23298d2337e1d0530534f8d43c3a564c6afde060eafeb73295
|
4
|
+
data.tar.gz: 33288826820a0a21e89a7d8ac41817367e4ab7c557a2129975cb8c3b4c95c9b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec1cdefd9043a82198cb13861758019d4715431feadd7da274ef117b55255e5a1b495c208f292a9774db5c1088f364e739b6e0edf8971f418dc80204da3e34b8
|
7
|
+
data.tar.gz: ef317ec213410ef46b234ac9c1f35a327b225f8c1f410fcb2913f420ceb997517a2be882a8e741b8c620a5f6331080c1881f3a65a36bbe42617320f02b46e1ff
|
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/.rubocop.yml
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.6.5p114
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
ast (2.4.0)
|
5
|
+
byebug (9.1.0)
|
6
|
+
coderay (1.1.2)
|
7
|
+
colorize (0.8.1)
|
8
|
+
diff-lcs (1.3)
|
9
|
+
docile (1.1.5)
|
10
|
+
fasterer (0.8.1)
|
11
|
+
colorize (~> 0.7)
|
12
|
+
ruby_parser (>= 3.14.1)
|
13
|
+
i18n (0.7.0)
|
14
|
+
jaro_winkler (1.5.4)
|
15
|
+
json (2.3.0)
|
16
|
+
method_source (0.8.2)
|
17
|
+
parallel (1.19.1)
|
18
|
+
parser (2.6.5.0)
|
19
|
+
ast (~> 2.4.0)
|
20
|
+
pry (0.10.4)
|
21
|
+
coderay (~> 1.1.0)
|
22
|
+
method_source (~> 0.8.1)
|
23
|
+
slop (~> 3.4)
|
24
|
+
rainbow (3.0.0)
|
25
|
+
rspec (3.9.0)
|
26
|
+
rspec-core (~> 3.9.0)
|
27
|
+
rspec-expectations (~> 3.9.0)
|
28
|
+
rspec-mocks (~> 3.9.0)
|
29
|
+
rspec-core (3.9.0)
|
30
|
+
rspec-support (~> 3.9.0)
|
31
|
+
rspec-expectations (3.9.0)
|
32
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
33
|
+
rspec-support (~> 3.9.0)
|
34
|
+
rspec-mocks (3.9.0)
|
35
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
36
|
+
rspec-support (~> 3.9.0)
|
37
|
+
rspec-support (3.9.0)
|
38
|
+
rubocop (0.76.0)
|
39
|
+
jaro_winkler (~> 1.5.1)
|
40
|
+
parallel (~> 1.10)
|
41
|
+
parser (>= 2.6)
|
42
|
+
rainbow (>= 2.2.2, < 4.0)
|
43
|
+
ruby-progressbar (~> 1.7)
|
44
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
45
|
+
ruby-progressbar (1.10.1)
|
46
|
+
ruby_parser (3.14.1)
|
47
|
+
sexp_processor (~> 4.9)
|
48
|
+
sexp_processor (4.13.0)
|
49
|
+
simplecov (0.12.0)
|
50
|
+
docile (~> 1.1.0)
|
51
|
+
json (>= 1.8, < 3)
|
52
|
+
simplecov-html (~> 0.10.0)
|
53
|
+
simplecov-html (0.10.2)
|
54
|
+
slop (3.6.0)
|
55
|
+
unicode-display_width (1.6.0)
|
56
|
+
|
57
|
+
PLATFORMS
|
58
|
+
x64-mingw32
|
59
|
+
|
60
|
+
DEPENDENCIES
|
61
|
+
byebug (~> 9.0, >= 9.0.6)
|
62
|
+
fasterer (~> 0.8.0)
|
63
|
+
i18n (~> 0.7.0)
|
64
|
+
pry (~> 0.10.3)
|
65
|
+
rspec (~> 3.9)
|
66
|
+
rubocop (~> 0.76.0)
|
67
|
+
simplecov (~> 0.12.0)
|
68
|
+
|
69
|
+
BUNDLED WITH
|
70
|
+
1.17.2
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Codebreakergem
|
4
|
+
class Difficulty
|
5
|
+
attr_reader :name, :order
|
6
|
+
attr_accessor :attempts, :hints
|
7
|
+
|
8
|
+
def initialize(name:, attempts:, hints:, order:)
|
9
|
+
@name = name
|
10
|
+
@attempts = attempts
|
11
|
+
@hints = hints
|
12
|
+
@order = order
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Codebreakergem
|
4
|
+
class FileWorker
|
5
|
+
class << self
|
6
|
+
def read_from_file(filename)
|
7
|
+
permitted_class = [Statistic, Difficulty]
|
8
|
+
unless File.file?(Game::FILE)
|
9
|
+
puts 'File doesn\'t exist'
|
10
|
+
return
|
11
|
+
end
|
12
|
+
YAML.safe_load(File.read(filename), permitted_class, [], true)
|
13
|
+
end
|
14
|
+
|
15
|
+
def add_to_file(filename, data)
|
16
|
+
permitted_class = [Statistic, Difficulty]
|
17
|
+
data_in_file = YAML.safe_load(File.read(filename), permitted_class, [], true)
|
18
|
+
if data_in_file.is_a? Array
|
19
|
+
data_in_file << data
|
20
|
+
File.open(filename, 'w') { |file| file.write(data_in_file.to_yaml) }
|
21
|
+
else
|
22
|
+
File.open(filename, 'w') { |file| file.write([data_in_file, data].to_yaml) }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def write_to_file(filename, data)
|
27
|
+
File.open(filename, 'w') { |file| file.write(data.to_yaml) }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Codebreakergem
|
4
|
+
class Statistic
|
5
|
+
attr_accessor :name, :difficulty, :attempts_total,
|
6
|
+
:attempts_used, :hints_total, :hints_used
|
7
|
+
|
8
|
+
def initialize(name:, difficulty:, attempts_total:, hints_total:)
|
9
|
+
@name = name
|
10
|
+
@difficulty = difficulty
|
11
|
+
@attempts_total = attempts_total
|
12
|
+
@attempts_used = attempts_total - difficulty.attempts
|
13
|
+
@hints_total = hints_total
|
14
|
+
@hints_used = hints_total - difficulty.hints
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/classes/user.rb
ADDED
data/lib/codebreakergem.rb
CHANGED
@@ -1,17 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'yaml'
|
3
4
|
require 'i18n'
|
4
5
|
require 'pry'
|
5
6
|
require './lib/modules/check_module.rb'
|
6
7
|
require './lib/classes/difficulty.rb'
|
7
|
-
#require './lib/codebreakergem.rb'
|
8
8
|
require './lib/classes/user.rb'
|
9
|
-
require './lib/classes/file_worker.rb'
|
10
9
|
require './lib/classes/statistic.rb'
|
11
|
-
require './lib/
|
12
|
-
|
13
|
-
|
14
|
-
I18n.locale = :en
|
10
|
+
require './lib/classes/file_worker.rb'
|
11
|
+
require './lib/config.rb'
|
12
|
+
require './lib/codebreakergem/version.rb'
|
15
13
|
|
16
14
|
module Codebreakergem
|
17
15
|
class Game
|
data/lib/config.rb
ADDED
data/lib/data/.gitkeep
ADDED
File without changes
|
data/lib/data/data.yml
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
---
|
2
|
+
- !ruby/object:Codebreakergem::Statistic
|
3
|
+
name: Alex
|
4
|
+
difficulty: !ruby/object:Codebreakergem::Difficulty
|
5
|
+
name: Easy
|
6
|
+
attempts: 8
|
7
|
+
hints: 1
|
8
|
+
order: 3
|
9
|
+
attempts_total: 15
|
10
|
+
attempts_used: 7
|
11
|
+
hints_total: 2
|
12
|
+
hints_used: 1
|
13
|
+
- !ruby/object:Codebreakergem::Statistic
|
14
|
+
name: Alex
|
15
|
+
difficulty: !ruby/object:Codebreakergem::Difficulty
|
16
|
+
name: Medium
|
17
|
+
attempts: 5
|
18
|
+
hints: 1
|
19
|
+
order: 2
|
20
|
+
attempts_total: 10
|
21
|
+
attempts_used: 5
|
22
|
+
hints_total: 1
|
23
|
+
hints_used: 0
|
data/lib/locales/en.yml
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
en:
|
2
|
+
class_error: 'Wrong type of variable'
|
3
|
+
length_error: 'Length of the string is not in allowed range'
|
4
|
+
no_hints: 'You have no more hints'
|
5
|
+
hello_message: 'Hello player! Welcome to codebreaker'
|
6
|
+
stats_header: "Rating Name Difficulty Attempts Total Attempts Used Hints Total Hints Used\n"
|
7
|
+
menu: "Chose action:\n
|
8
|
+
1) Start\n
|
9
|
+
2) Rules\n
|
10
|
+
3) Stats\n
|
11
|
+
4) Exit\n"
|
12
|
+
victory_message: 'Congratulations!!! YOU WON!!!'
|
13
|
+
out_of_attempts: 'Unfortunately you have no more attempts'
|
14
|
+
rules: " ____________________________________________________________________________________________\n
|
15
|
+
| |\n
|
16
|
+
| Rules |\n
|
17
|
+
|____________________________________________________________________________________________|\n
|
18
|
+
| |\n
|
19
|
+
| * Codebreaker is a logic game in which a code-breaker tries to break a secret code |\n
|
20
|
+
| created by a code-maker. The codemaker, which will be played by the application we’re |\n
|
21
|
+
| going to write, creates a secret code of four numbers between 1 and 6. |\n
|
22
|
+
| |\n
|
23
|
+
| * The codebreaker gets some number of chances to break the code (depends on chosen |\n
|
24
|
+
| difficulty). In each turn, the codebreaker makes a guess of 4 numbers. The codemaker |\n
|
25
|
+
| then marks the guess with up to 4 signs - '+' or '-' or empty spaces. |\n
|
26
|
+
| |\n
|
27
|
+
| * A + indicates an exact match: one of the numbers in the guess is the same as one of the |\n
|
28
|
+
| numbers in the secret code and in the same position. For example: |\n
|
29
|
+
| Secret number - 1234 |\n
|
30
|
+
| Input number - 6264 |\n
|
31
|
+
| Number of pluses - 2 (second and fourth position) |\n
|
32
|
+
| |\n
|
33
|
+
| * A - indicates a number match: one of the numbers in the guess is the same as one of the |\n
|
34
|
+
| numbers in the secret code but in a different position. For example: |\n
|
35
|
+
| Secret number - 1234 |\n
|
36
|
+
| Input number - 6462 |\n
|
37
|
+
| Number of minuses - 2 (second and fourth position) |\n
|
38
|
+
| |\n
|
39
|
+
| * An empty space indicates that there is not a current digit in a secret number. |\n
|
40
|
+
| |\n
|
41
|
+
| * If codebreaker inputs the exact number as a secret number - codebreaker wins the |\n
|
42
|
+
| game. If all attempts are spent - codebreaker loses. |\n
|
43
|
+
| |\n
|
44
|
+
| * Codebreaker also has some number of hints(depends on chosen difficulty). If a user |\n
|
45
|
+
| takes a hint - he receives back a separate digit of the secret code. |\n
|
46
|
+
|____________________________________________________________________________________________|"
|
data/lib/locales/ru.yml
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Codebreakergem
|
4
|
+
module Checker
|
5
|
+
ALLOWED_LENGTH = (3..21).freeze
|
6
|
+
|
7
|
+
def validate_string_length(incoming_string)
|
8
|
+
return true if ALLOWED_LENGTH.include? incoming_string.to_s.length
|
9
|
+
|
10
|
+
puts I18n.t(:length_error)
|
11
|
+
false
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codebreakergem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sasha
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-12-
|
11
|
+
date: 2019-12-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -59,19 +59,36 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
+
- ".fasterer.yml"
|
62
63
|
- ".gitignore"
|
63
64
|
- ".rspec"
|
65
|
+
- ".rubocop.yml"
|
66
|
+
- ".ruby-version"
|
64
67
|
- ".travis.yml"
|
65
68
|
- CODE_OF_CONDUCT.md
|
66
69
|
- Gemfile
|
70
|
+
- Gemfile.lock
|
67
71
|
- LICENSE.txt
|
68
72
|
- README.md
|
69
73
|
- Rakefile
|
70
74
|
- bin/console
|
71
75
|
- bin/setup
|
76
|
+
- codebreakergem-0.1.0.gem
|
77
|
+
- codebreakergem-0.1.1.gem
|
78
|
+
- codebreakergem-0.1.2.gem
|
72
79
|
- codebreakergem.gemspec
|
80
|
+
- lib/classes/difficulty.rb
|
81
|
+
- lib/classes/file_worker.rb
|
82
|
+
- lib/classes/statistic.rb
|
83
|
+
- lib/classes/user.rb
|
73
84
|
- lib/codebreakergem.rb
|
74
85
|
- lib/codebreakergem/version.rb
|
86
|
+
- lib/config.rb
|
87
|
+
- lib/data/.gitkeep
|
88
|
+
- lib/data/data.yml
|
89
|
+
- lib/locales/en.yml
|
90
|
+
- lib/locales/ru.yml
|
91
|
+
- lib/modules/check_module.rb
|
75
92
|
homepage: https://github.com/SashaZhuravskiy/CodebreakerGemRepo/
|
76
93
|
licenses:
|
77
94
|
- MIT
|