codebreaker_kirill 0.2.14 → 0.2.17

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: 0de2a53a4fe181807c25613515789140af1f979b44ef0bdf1b764b8180361c8c
4
- data.tar.gz: 1dc0fa0e432c13b0fc41522cfc6f02783b3472ba651e7b00b0b189e8f7420270
3
+ metadata.gz: ca2a9e18040569430affe912a91553e4b75111ac9e269b0c88a536a9ba9a3fe1
4
+ data.tar.gz: 3c4b4c50a303aba79aa4191f9c7fd7795acae84fa0eab6fa59ffa611cfec7e7b
5
5
  SHA512:
6
- metadata.gz: 16207ff585ee6b27b23332791a7ec74929fa84ad71811e4461ce5c718d2c52ef9a84dcb439b8bc8283d0eeb470605c7286b0a57143aa94f7da1d6bb39e141d78
7
- data.tar.gz: 2e9aa3cd9e2ae12bf31965e0fc24571a10259fbb98ab61525acc8555c0ea88f0ae5cd4866fd0cc11533c20ae64a2a67959a4739d52e0ac7bcd4e91d17f8cbc48
6
+ metadata.gz: e332c34663d075529458200c45e368068d2cd11763f24599bcd07a91faef64a4776b5cc1f2a8747223f2a72b840ec033da61fe43dcc68d2562bf965e2fbab139
7
+ data.tar.gz: f40c63b83eb5f3b67bdc103efe9c64e822db52efe3c8cb8542997008385714108d28df8bd5fee84ca2a0bf706f0e386ab84e30b4f5e26887077ce73fdbc03daa
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'settings'
2
4
 
3
5
  module CodeGenerator
@@ -23,7 +23,8 @@ class Game
23
23
 
24
24
  def give_a_hint
25
25
  return 0 if @user.hints[:used] >= @user.hints[:all]
26
+
26
27
  @user.hints[:used] += 1
27
- @secret_code[@hints[:used]]
28
+ @secret_code[@user.hints[:used]]
28
29
  end
29
30
  end
@@ -3,15 +3,14 @@
3
3
  module GuessHandler
4
4
  def respond_to_guess(game, input, code)
5
5
  validate_guess(input)
6
+ return game.give_a_hint if input == "hint"
6
7
  @result = []
7
8
  @code_clone = code.clone
8
9
  @numbers = input.split('').map(&:to_i)
9
10
  return 'win' if @numbers == code
10
11
 
11
12
  assess_guess(@code_clone, @numbers)
12
-
13
- game.attempts[:used] += 1
14
- game.attempts[:used] >= game.attempts[:all] ? 'loss' : @result.delete_if { |value| (1..6).include?(value) }.sort
13
+ attempts_handler(game)
15
14
  end
16
15
 
17
16
  def assess_guess(code, input)
@@ -27,4 +26,15 @@ module GuessHandler
27
26
  input.slice!(@numbers.index(el)) end
28
27
  end
29
28
  end
29
+
30
+ def attempts_handler(game)
31
+ game.user.attempts[:used] += 1
32
+ if game.user.attempts[:used] >= game.user.attempts[:all]
33
+ 'loss'
34
+ else
35
+ @result.delete_if do |value|
36
+ (1..6).include?(value)
37
+ end.sort
38
+ end
39
+ end
30
40
  end
@@ -1,11 +1,11 @@
1
- module Settings
1
+ # frozen_string_literal: true
2
2
 
3
+ module Settings
3
4
  LEVEL = {
4
5
  'easy' => { attempts: 15, hints: 2 },
5
6
  'medium' => { attempts: 10, hints: 1 },
6
7
  'hell' => { attempts: 5, hints: 1 }
7
- }
8
+ }.freeze
8
9
  CODE_LENGTH = 4
9
- RANDOM_RANGE = (1..6)
10
-
10
+ RANDOM_RANGE = (1..6).freeze
11
11
  end
@@ -1,13 +1,15 @@
1
- class Stats
1
+ # frozen_string_literal: true
2
+
3
+ class Stats
2
4
  def self.save_game(user)
3
- @data = File.exist?("stats.yml") ? YAML.load_file("stats.yml") : []
5
+ @data = File.exist?('stats.yml') ? YAML.load_file('stats.yml') : []
4
6
  @data << user
5
- File.new("stats.yml", 'w') unless File.exist?("stats.yml")
6
- File.open("stats.yml", 'w') { |file| file.write(@data.to_yaml) }
7
+ File.new('stats.yml', 'w') unless File.exist?('stats.yml')
8
+ File.open('stats.yml', 'w') { |file| file.write(@data.to_yaml) }
7
9
  end
8
10
 
9
11
  def self.show_stats
10
- @data = File.exist?("stats.yml") ? YAML.load_file("stats.yml") : []
12
+ @data = File.exist?('stats.yml') ? YAML.load_file('stats.yml') : []
11
13
  print @data
12
14
  end
13
15
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
- require_relative "validations"
3
- require_relative "settings"
2
+
3
+ require_relative 'validations'
4
+ require_relative 'settings'
4
5
 
5
6
  class User
6
7
  include Validations
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Validations
2
4
  def validate_name(name)
3
5
  raise "Name shouldn't be empty" if name.empty?
@@ -14,6 +16,8 @@ module Validations
14
16
 
15
17
  def validate_difficulty(difficulty)
16
18
  raise "Input shouldn't be empty" if difficulty.empty?
17
- raise 'You should enter one of the following options: easy, medium, hell' unless difficulty.match?(/easy|medium|hell/)
19
+ return if difficulty.match?(/easy|medium|hell/)
20
+
21
+ raise 'You should enter one of the following options: easy, medium, hell'
18
22
  end
19
23
  end
@@ -3,5 +3,5 @@
3
3
  require_relative 'game'
4
4
 
5
5
  module CodebreakerKirill
6
- VERSION = '0.2.14'
6
+ VERSION = '0.2.17'
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codebreaker_kirill
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.14
4
+ version: 0.2.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kirill Dudchenko