codebreaker_marian 0.1.5 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b2fab79cea8eddbaf7005de8ee122e76cf0debd9490fc8e73d150e4f78a334ae
4
- data.tar.gz: 5c355f6fb8c3fe20a504b6aa6d16ccfc1fe7e3f6ea6c6873d4442db6a69bd6c7
3
+ metadata.gz: 861f455524d0228228b732277beb3cc032797899176860dfb923de4512bdf9bf
4
+ data.tar.gz: 103f80869c92057b115fd6cd2e34f7c6dafbc3d424fe3b51cc4af324bed5cb0d
5
5
  SHA512:
6
- metadata.gz: 18dd9a7af8263d81a6ac85fabb1ab9a4328781e372d72a2b016741139dd41613a7e0c3a0e18cba1f68c52fb47417085b8010e58c7c3115fbaf0d5b12a35cb02c
7
- data.tar.gz: e6eccd2a50248555d32a26e35f0f20a51f49e3d1f8a063ce529db7da1276a1220cc74f000f4a70af94630bbe1117f4d33c8adece98d6ca0c0d1cd38a978149ae
6
+ metadata.gz: 64d587067a2842a61cbd3d24298d96d167054055ce962de408ddb4ee20f636f1018d13714cce62d5fbd89a4675a74187c554ec6b94b747dabc9bf716b3c8a5ad
7
+ data.tar.gz: 8dfd25ddbaade6893464b5b528fcb73733ba0f3b3fc440af1cccd412423b777a83ea4790f4fc8f916641aafd30494d52c1836efbe664f66fd279a4ebfbd9b306
@@ -6,9 +6,6 @@ AllCops:
6
6
  Metrics/LineLength:
7
7
  Max: 120
8
8
 
9
- Metrics/ClassLength:
10
- Max: 125
11
-
12
9
  Metrics/BlockLength:
13
10
  ExcludedMethods: ['describe', 'context']
14
11
 
@@ -1 +1 @@
1
- rg-codebreaker
1
+ codebreaker_marian
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- codebreaker_marian (0.1.5)
4
+ codebreaker_marian (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -9,7 +9,7 @@ TODO: Delete this and the text above, and describe your gem
9
9
  Add this line to your application's Gemfile:
10
10
 
11
11
  ```ruby
12
- gem 'codebreaker'
12
+ gem 'codebreaker_marian'
13
13
  ```
14
14
 
15
15
  And then execute:
@@ -2,13 +2,8 @@
2
2
 
3
3
  require 'i18n'
4
4
  require 'yaml'
5
- require_relative 'lib/codebreaker/i18n_config'
6
- require_relative 'lib/codebreaker/modules/validator'
7
- require_relative 'lib/codebreaker/entities/game'
8
- require_relative 'lib/codebreaker/entities/game'
9
- require_relative 'lib/codebreaker/entities/data_storage'
10
- require_relative 'lib/codebreaker/entities/processor'
11
- require_relative 'lib/codebreaker/entities/menu'
12
- require_relative 'lib/codebreaker/entities/renderer'
13
- require_relative 'lib/codebreaker/entities/statistics'
14
- require_relative 'lib/codebreaker/version'
5
+ require_relative 'lib/codebreaker_marian/entities/game'
6
+ require_relative 'lib/codebreaker_marian/entities/data_storage'
7
+ require_relative 'lib/codebreaker_marian/entities/processor'
8
+ require_relative 'lib/codebreaker_marian/entities/statistics'
9
+ require_relative 'lib/codebreaker_marian/version'
@@ -3,7 +3,7 @@
3
3
  #!/usr/bin/env ruby
4
4
 
5
5
  require 'bundler/setup'
6
- require 'codebreaker'
6
+ require 'codebreaker_marian'
7
7
 
8
8
  # You can add fixtures and/or initialization code here to make experimenting
9
9
  # with your gem easier. You can also use a different console, if you like.
@@ -2,7 +2,7 @@
2
2
 
3
3
  lib = File.expand_path('lib', __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require_relative 'lib/codebreaker/version'
5
+ require_relative 'lib/codebreaker_marian/version'
6
6
 
7
7
  Gem::Specification.new do |spec|
8
8
  spec.name = 'codebreaker_marian'
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.authors = ['Marian Rebeha']
11
11
  spec.email = ['marikrebega@gmail.com']
12
12
 
13
- spec.summary = 'Codebreaker app'
13
+ spec.summary = 'CodebreakerMarian app'
14
14
  spec.description = 'Logic game'
15
15
  spec.homepage = 'https://github.com/marikrebega/RubyGarage_2_Codebreaker_gem'
16
16
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'codebreaker/version'
3
+ require 'codebreaker_marian/version'
4
4
  require_relative '../autoload'
5
5
 
6
6
  module Codebreaker
@@ -34,6 +34,7 @@ module Codebreaker
34
34
  end
35
35
 
36
36
  def start_process(command)
37
+ decrease_attempts!
37
38
  @process.secret_code_proc(code.join, command)
38
39
  end
39
40
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Codebreaker
4
- VERSION = '0.1.5'
4
+ VERSION = '0.2.0'
5
5
  end
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.5
4
+ version: 0.2.0
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-28 00:00:00.000000000 Z
11
+ date: 2020-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -172,20 +172,15 @@ files:
172
172
  - autoload.rb
173
173
  - bin/console
174
174
  - bin/setup
175
- - codebreaker.gemspec
176
- - database/.gitignore
175
+ - codebreaker_marian.gemspec
177
176
  - index.rb
178
- - lib/codebreaker.rb
179
- - lib/codebreaker/entities/data_storage.rb
180
- - lib/codebreaker/entities/game.rb
181
- - lib/codebreaker/entities/menu.rb
182
- - lib/codebreaker/entities/processor.rb
183
- - lib/codebreaker/entities/renderer.rb
184
- - lib/codebreaker/entities/statistics.rb
185
- - lib/codebreaker/i18n_config.rb
186
- - lib/codebreaker/locales/en.yml
187
- - lib/codebreaker/modules/validator.rb
188
- - lib/codebreaker/version.rb
177
+ - lib/codebreaker_marian.rb
178
+ - lib/codebreaker_marian/entities/data_storage.rb
179
+ - lib/codebreaker_marian/entities/game.rb
180
+ - lib/codebreaker_marian/entities/processor.rb
181
+ - lib/codebreaker_marian/entities/renderer.rb
182
+ - lib/codebreaker_marian/entities/statistics.rb
183
+ - lib/codebreaker_marian/version.rb
189
184
  homepage: https://github.com/marikrebega/RubyGarage_2_Codebreaker_gem
190
185
  licenses: []
191
186
  metadata:
@@ -208,5 +203,5 @@ requirements: []
208
203
  rubygems_version: 3.1.4
209
204
  signing_key:
210
205
  specification_version: 4
211
- summary: Codebreaker app
206
+ summary: CodebreakerMarian app
212
207
  test_files: []
@@ -1,4 +0,0 @@
1
- # Ignore everything in this directory
2
- *
3
- # Except this file
4
- !.gitignore
@@ -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,4 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- I18n.load_path << Dir[File.expand_path('lib/codebreaker/locales/') + '/*.yml']
4
- I18n.config.available_locales = :en
@@ -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