codebreaker_marian 0.1.6 → 0.2.1
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/.rubocop.yml +0 -3
- data/Gemfile.lock +1 -1
- data/lib/codebreaker_marian/entities/game.rb +1 -0
- data/lib/codebreaker_marian/version.rb +1 -1
- metadata +2 -9
- data/autoload.rb +0 -14
- data/database/.gitignore +0 -4
- data/index.rb +0 -5
- data/lib/codebreaker_marian/entities/menu.rb +0 -163
- data/lib/codebreaker_marian/i18n_config.rb +0 -4
- data/lib/codebreaker_marian/locales/en.yml +0 -39
- data/lib/codebreaker_marian/modules/validator.rb +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4df317ed21910c221234f243cb07775c2ad1a04e64da37442b80f854df8f774b
|
4
|
+
data.tar.gz: 92bb22c5a104fbd0bc00fcce304714d1ce748330dfa63e0523e26b6a4d67851f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee6c030eacac766315c780294f7eb7bd0fa523c3f4fee7597ee82175765c0b6afc5bb41560f277667dea81fd04915a68f3948e3bc8d5b918af1d28de57b9cd8e
|
7
|
+
data.tar.gz: 407b66467bbcf5b07a0d7d4adf6783203488881fd93f62595ab6983b7180983c7b3ceb299e5015483ab57ae1be8235eee0e1e2b38a702d4c990325da2412bc76
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codebreaker_marian
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marian Rebeha
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -169,22 +169,15 @@ files:
|
|
169
169
|
- Gemfile.lock
|
170
170
|
- README.md
|
171
171
|
- Rakefile
|
172
|
-
- autoload.rb
|
173
172
|
- bin/console
|
174
173
|
- bin/setup
|
175
174
|
- codebreaker_marian.gemspec
|
176
|
-
- database/.gitignore
|
177
|
-
- index.rb
|
178
175
|
- lib/codebreaker_marian.rb
|
179
176
|
- lib/codebreaker_marian/entities/data_storage.rb
|
180
177
|
- lib/codebreaker_marian/entities/game.rb
|
181
|
-
- lib/codebreaker_marian/entities/menu.rb
|
182
178
|
- lib/codebreaker_marian/entities/processor.rb
|
183
179
|
- lib/codebreaker_marian/entities/renderer.rb
|
184
180
|
- lib/codebreaker_marian/entities/statistics.rb
|
185
|
-
- lib/codebreaker_marian/i18n_config.rb
|
186
|
-
- lib/codebreaker_marian/locales/en.yml
|
187
|
-
- lib/codebreaker_marian/modules/validator.rb
|
188
181
|
- lib/codebreaker_marian/version.rb
|
189
182
|
homepage: https://github.com/marikrebega/RubyGarage_2_Codebreaker_gem
|
190
183
|
licenses: []
|
data/autoload.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'i18n'
|
4
|
-
require 'yaml'
|
5
|
-
require_relative 'lib/codebreaker_marian/i18n_config'
|
6
|
-
require_relative 'lib/codebreaker_marian/modules/validator'
|
7
|
-
require_relative 'lib/codebreaker_marian/entities/game'
|
8
|
-
require_relative 'lib/codebreaker_marian/entities/game'
|
9
|
-
require_relative 'lib/codebreaker_marian/entities/data_storage'
|
10
|
-
require_relative 'lib/codebreaker_marian/entities/processor'
|
11
|
-
require_relative 'lib/codebreaker_marian/entities/menu'
|
12
|
-
require_relative 'lib/codebreaker_marian/entities/renderer'
|
13
|
-
require_relative 'lib/codebreaker_marian/entities/statistics'
|
14
|
-
require_relative 'lib/codebreaker_marian/version'
|
data/database/.gitignore
DELETED
data/index.rb
DELETED
@@ -1,163 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Codebreaker
|
4
|
-
module Entities
|
5
|
-
class Menu
|
6
|
-
include Modules::Validator
|
7
|
-
attr_reader :storage, :renderer, :game, :guess
|
8
|
-
|
9
|
-
COMMANDS = {
|
10
|
-
start: 'start',
|
11
|
-
exit: 'exit',
|
12
|
-
rules: 'rules',
|
13
|
-
stats: 'stats'
|
14
|
-
}.freeze
|
15
|
-
CHOOSE_COMMANDS = {
|
16
|
-
yes: 'yes'
|
17
|
-
}.freeze
|
18
|
-
HINT_COMMAND = 'hint'
|
19
|
-
MIN_SIZE_VALUE = 3
|
20
|
-
MAX_SIZE_VALUE = 20
|
21
|
-
|
22
|
-
def initialize
|
23
|
-
@storage = DataStorage.new
|
24
|
-
@renderer = Renderer.new
|
25
|
-
@game = Game.new
|
26
|
-
@statistics = Statistics.new
|
27
|
-
end
|
28
|
-
|
29
|
-
def game_menu
|
30
|
-
renderer.start_message
|
31
|
-
|
32
|
-
choice_menu_process(ask(:choice_options, commands: COMMANDS.keys.join(' | ')))
|
33
|
-
end
|
34
|
-
|
35
|
-
private
|
36
|
-
|
37
|
-
def rules
|
38
|
-
renderer.rules
|
39
|
-
game_menu
|
40
|
-
end
|
41
|
-
|
42
|
-
def start
|
43
|
-
@name = registrate_user
|
44
|
-
level_choice
|
45
|
-
game_process
|
46
|
-
end
|
47
|
-
|
48
|
-
def stats
|
49
|
-
scores = storage.load
|
50
|
-
render_stats(@statistics.stats(scores)) if scores
|
51
|
-
game_menu
|
52
|
-
end
|
53
|
-
|
54
|
-
def ask(phrase_key = nil, options = {})
|
55
|
-
renderer.message(phrase_key, options) if phrase_key
|
56
|
-
gets.chomp
|
57
|
-
end
|
58
|
-
|
59
|
-
def save_result
|
60
|
-
storage.save_game_result(game.to_h(@name)) if ask(:save_result_message) == CHOOSE_COMMANDS[:yes]
|
61
|
-
end
|
62
|
-
|
63
|
-
def registrate_user
|
64
|
-
loop do
|
65
|
-
name = ask(:registration)
|
66
|
-
|
67
|
-
return name if name_valid?(name)
|
68
|
-
|
69
|
-
renderer.registration_name_length_error
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def name_valid?(name)
|
74
|
-
!check_emptyness(name) && check_length(name, MIN_SIZE_VALUE, MAX_SIZE_VALUE)
|
75
|
-
end
|
76
|
-
|
77
|
-
def level_choice
|
78
|
-
loop do
|
79
|
-
level = ask(:hard_level, levels: Game::DIFFICULTIES.keys.join(' | '))
|
80
|
-
|
81
|
-
return generate_game(Game::DIFFICULTIES[level.to_sym]) if Game::DIFFICULTIES[level.to_sym]
|
82
|
-
return game_menu if level == COMMANDS[:exit]
|
83
|
-
|
84
|
-
renderer.command_error
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
def generate_game(difficulty)
|
89
|
-
game.generate(difficulty)
|
90
|
-
renderer.message(:difficulty, hints: difficulty[:hints], attempts: difficulty[:attempts])
|
91
|
-
end
|
92
|
-
|
93
|
-
def game_process
|
94
|
-
while game.attempts.positive?
|
95
|
-
@guess = ask
|
96
|
-
return handle_win if game.win?(guess)
|
97
|
-
|
98
|
-
choice_code_process
|
99
|
-
end
|
100
|
-
handle_lose
|
101
|
-
end
|
102
|
-
|
103
|
-
def choice_code_process
|
104
|
-
case guess
|
105
|
-
when HINT_COMMAND then hint_process
|
106
|
-
when COMMANDS[:exit] then game_menu
|
107
|
-
else handle_command
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
def handle_command
|
112
|
-
return renderer.command_error unless check_command_range(guess)
|
113
|
-
|
114
|
-
p game.start_process(guess)
|
115
|
-
renderer.round_message
|
116
|
-
game.decrease_attempts!
|
117
|
-
end
|
118
|
-
|
119
|
-
def handle_win
|
120
|
-
renderer.win_game_message
|
121
|
-
save_result
|
122
|
-
game_menu
|
123
|
-
end
|
124
|
-
|
125
|
-
def handle_lose
|
126
|
-
renderer.lost_game_message(game.code)
|
127
|
-
game_menu
|
128
|
-
end
|
129
|
-
|
130
|
-
def hint_process
|
131
|
-
return renderer.no_hints_message? if game.hints_spent?
|
132
|
-
|
133
|
-
renderer.print_hint_number(game.take_a_hint!)
|
134
|
-
end
|
135
|
-
|
136
|
-
def exit_from_game
|
137
|
-
renderer.goodbye_message
|
138
|
-
exit
|
139
|
-
end
|
140
|
-
|
141
|
-
def choice_menu_process(command_name)
|
142
|
-
case command_name
|
143
|
-
when COMMANDS[:start] then start
|
144
|
-
when COMMANDS[:exit] then exit_from_game
|
145
|
-
when COMMANDS[:rules] then rules
|
146
|
-
when COMMANDS[:stats] then stats
|
147
|
-
else
|
148
|
-
renderer.command_error
|
149
|
-
game_menu
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
def render_stats(list)
|
154
|
-
index = 0
|
155
|
-
while index < list.size
|
156
|
-
puts "#{index + 1}: "
|
157
|
-
list[index].each { |param, value| puts "#{param}:#{value}" }
|
158
|
-
index += 1
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
en:
|
2
|
-
start_message: "Welcome to CodeBreaker"
|
3
|
-
choice_options: "Choose option:
|
4
|
-
%{commands}"
|
5
|
-
hard_level: "Which level you do you want to play?
|
6
|
-
%{levels}"
|
7
|
-
goodbye_message: "We are waiting for you. Come back!"
|
8
|
-
command_error: "You have passed unexpected command. Please choose one from listed commands"
|
9
|
-
rules: "Codebreaker is a logic game in which a code-breaker tries to break a secret code created by a code-maker. 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.
|
10
|
-
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. The codemaker then marks the guess with up to 4 signs - + or - or empty spaces.
|
11
|
-
|
12
|
-
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:
|
13
|
-
Secret number - 1234
|
14
|
-
Input number - 6264
|
15
|
-
Number of pluses - 2 (second and fourth position)
|
16
|
-
|
17
|
-
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:
|
18
|
-
Secret number - 1234
|
19
|
-
Input number - 6462
|
20
|
-
Number of minuses - 2 (second and fourth position)
|
21
|
-
|
22
|
-
An empty space indicates that there is not a current digit in a secret number.
|
23
|
-
|
24
|
-
If codebreaker inputs the exact number as a secret number - codebreaker wins the game. If all attempts are spent - codebreaker loses.
|
25
|
-
|
26
|
-
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.
|
27
|
-
"
|
28
|
-
registration: "Before start, enter your name, please "
|
29
|
-
difficulty: "You had to %{hints} hints and %{attempts} attempts"
|
30
|
-
round_message: "1. Enter your secret code
|
31
|
-
2. hint
|
32
|
-
3. exit "
|
33
|
-
guess: "Opps, secret code must to be from four digits in range from 1 to 6"
|
34
|
-
lost_game_message: "Oh, your attempts ended... Your code was: %{code}"
|
35
|
-
win_game_message: "Yayy, u won the game! Congrats!"
|
36
|
-
save_results_message: "Do you want to save result? 1. yes 2. no"
|
37
|
-
have_no_hints_message: "Oh, your hints ended"
|
38
|
-
print_hint_number: "Hint number: %{code}"
|
39
|
-
registration_name_length_error: "It must be more than 3 and less than 20 symbols."
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Codebreaker
|
4
|
-
module Modules
|
5
|
-
module Validator
|
6
|
-
VALUE_FORMAT = /^[1-6]{4}$/.freeze
|
7
|
-
|
8
|
-
def check_emptyness(value)
|
9
|
-
value.empty?
|
10
|
-
end
|
11
|
-
|
12
|
-
def check_length(value, min_size, max_size)
|
13
|
-
value.size.between?(min_size, max_size)
|
14
|
-
end
|
15
|
-
|
16
|
-
def check_command_range(command)
|
17
|
-
command =~ VALUE_FORMAT
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|