alex_codebreaker 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 26769c84cb57b5f1cd0c183b113399ed6ed2d552bcefc28d1ecf2af8dbb4de6a
4
- data.tar.gz: be13615fb5241f768943b66d5e78f8ae8fb0a2211e26aad4916ee0d22281dabc
3
+ metadata.gz: 31e7f606c615b97cc6f49e74138d611a9cbbff08e356bdda31b14c07d587d786
4
+ data.tar.gz: f8407fce826a3cc5be2ca8bb9faeee67df6b1dd121e62ce6d153d1417ff84865
5
5
  SHA512:
6
- metadata.gz: 89f4e1efaa071d08e2e7ad1f12f2dc8bcdefea304b3efd68d2268b6398104e16e51579c800c0a6254a233c623b09742180624246943f17060f3d6b58e21128d0
7
- data.tar.gz: b291bb4605a14c54bc45a99b23dd3b63ac64e26c9e378d6a331f81df09d923ed1d6c89059d15bc26b3ea3e859f7ecaf923e43161cb1fcf913e98394cf87bf3c6
6
+ metadata.gz: 43a221a965ad118e17e4a2356a89475a7d42480951c371251f1e8d236cba18f3bccf1f9b6008fbacbf4c2db959a383d198c6edb6c879b49b26a01d98f98735f0
7
+ data.tar.gz: 8c561f6bcdd0400b081b50c4607add61bf24c02391a2544f3fe5f6b35250b11563e488f031a8de4220d1ac5d2875585233639d77c1703d50e7f38e7a2472b96f
@@ -1,10 +1,11 @@
1
- require_relative 'config/gem.rb'
1
+ require 'yaml'
2
+
2
3
  require_relative 'alex_codebreaker/version'
3
4
  require_relative 'alex_codebreaker/modules/files'
4
5
  require_relative 'alex_codebreaker/modules/settings'
5
6
  require_relative 'alex_codebreaker/modules/difficulty_levels'
6
7
  require_relative 'alex_codebreaker/modules/validators/validators'
7
8
  require_relative 'alex_codebreaker/modules/validators/arguments_validation'
8
- require_relative 'alex_codebreaker/game'
9
9
  require_relative 'alex_codebreaker/players_rating'
10
10
  require_relative 'alex_codebreaker/session'
11
+ require_relative 'alex_codebreaker/game'
@@ -1,9 +1,11 @@
1
+ require_relative 'modules/validators/arguments_validation'
2
+
1
3
  class Game
2
4
  include ArgumentsValidation
3
5
 
4
- attr_reader :session
6
+ attr_reader :session, :win_status
5
7
 
6
- def start
8
+ def initialize
7
9
  @secret_code = Array.new(Settings::CODE_LENGTH) { rand(Settings::CODE_MIN_DIGIT..Settings::CODE_MAX_DIGIT) }
8
10
  @session = Session.new
9
11
  @win_status = false
@@ -26,21 +28,23 @@ class Game
26
28
  end
27
29
 
28
30
  def guess(user_input)
29
- return false unless guess_validation(user_input)
30
-
31
- return I18n.t(:no_attempts_left_message) if @session.attempts_used >= @session.attempts_total
31
+ return false if !guess_validation(user_input) || check_attempts
32
32
 
33
33
  @session.attempts_used += 1
34
34
  @win_status = true if user_input.to_i == @secret_code.join.to_i
35
35
  comparator(user_input)
36
36
  end
37
37
 
38
+ def check_attempts
39
+ @session.attempts_used >= @session.attempts_total
40
+ end
41
+
38
42
  def save_game
39
43
  @session.save_session_statistic if @win_status
40
44
  end
41
45
 
42
46
  def show_secret_code
43
- @secret_code.join if @win_status
47
+ @secret_code.join
44
48
  end
45
49
 
46
50
  private
@@ -2,9 +2,8 @@ class Session
2
2
  INITIAL_ATTEMPTS_USED = 0
3
3
  INITIAL_HINTS_USED = 0
4
4
 
5
- attr_reader :difficulty_name, :difficulty_level, :attempts_total, :hints_total
6
-
7
- attr_accessor :player_name, :attempts_used, :hints_used
5
+ attr_accessor :player_name, :attempts_used, :hints_used, :hints_total,
6
+ :difficulty_name, :attempts_total, :difficulty_level
8
7
 
9
8
  def initialize
10
9
  @attempts_used = INITIAL_ATTEMPTS_USED
@@ -1,3 +1,3 @@
1
1
  module AlexCodebreaker
2
- VERSION = '0.1.5'.freeze
2
+ VERSION = '0.1.6'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alex_codebreaker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oleksandr Loza
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-12-06 00:00:00.000000000 Z
11
+ date: 2019-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
@@ -169,8 +169,6 @@ files:
169
169
  - lib/alex_codebreaker/players_rating.rb
170
170
  - lib/alex_codebreaker/session.rb
171
171
  - lib/alex_codebreaker/version.rb
172
- - lib/config/gem.rb
173
- - lib/config/locales/en.yml
174
172
  homepage: https://github.com/Alexwell/codebreaker/tree/feature/initial-gem-settings
175
173
  licenses:
176
174
  - MIT
data/lib/config/gem.rb DELETED
@@ -1,5 +0,0 @@
1
- require 'yaml'
2
- require 'i18n'
3
-
4
- I18n.load_path << Dir[File.expand_path('locales', __dir__) + '/*.yml']
5
- I18n.default_locale = :en
@@ -1,13 +0,0 @@
1
- en:
2
- file_does_not_exist_message: "Stats file doesn't exist."
3
- invalid_digit_message: "All digits must be in the range 1-6."
4
- invalid_length_message: "Invalid argument length."
5
- no_attempts_left_message: "No attempts left."
6
- no_hints_left_message: "No hints left."
7
- wrong_class_message: "Wrong Class of argument."
8
- wrong_difficulty_message: "Chosen difficulty doesn't exist"
9
- value_instance_of: "Value must be instance of "
10
- invalid_argument_length: "Invalid argument length. Expected: "
11
- given: ". Given: "
12
- argument_length_long: "Argument length must be less than "
13
- argument_length_short: "Argument length must be more than "