codebreaker_PI 0.6.1 → 0.6.4

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: e2140afe7bcfec9de149823e1db587f43349a045a2931d66eb3c0172526ba539
4
- data.tar.gz: 4aaee8c9c38bab36211bae4d17fdff564cb643e2043f31e1ed3bbc60163ffde9
3
+ metadata.gz: b30612d628e14c6fc981b89a11a02741327163574297e655be631555ef4d1758
4
+ data.tar.gz: e7277141e4bf7e34c470bf0a11bb23d45805e2226d830e49ceb3522705895085
5
5
  SHA512:
6
- metadata.gz: aaf21264fd3253916af07bb325049b473ef98b04e940692b3f52ba56f602c0e2a569393c52e913cf3649d3d71b11bc917faeb536808924681b37f55eb84d916d
7
- data.tar.gz: 97b124f658011c7f4daa808ac750f61825f2ed155ec02b4d1ea17fbb9e9c1ef33af4602c8c1c8c8b08450b3c2aa5adab3bb0d5bc8ffe7e102da788503e40a65c
6
+ metadata.gz: 9200a8b67579819df23308bad2a02b85e0c44e4c9f469ff3b17d8a7c27aaf234aaa2d25689264f30af48a9dc0f8319823f334be579fb0d479e8dec23abfc7429
7
+ data.tar.gz: f5796badac894472b6a45485ce7656e8c079b9d3ccf628d4a5c3810b55bf52b0ac4a8a048ced0865d83fd235675dce43b5227a5f125a07dc6ff401533df007d7
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- codebreaker_PI (0.6.1)
4
+ codebreaker_PI (0.6.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,3 +1,3 @@
1
1
  module Codebreaker
2
- VERSION = "0.6.1"
2
+ VERSION = "0.6.4"
3
3
  end
@@ -24,6 +24,14 @@ module Codebreaker
24
24
  end
25
25
  end
26
26
 
27
+ def show_statistics
28
+ respondent.show(winners_load)
29
+ end
30
+
31
+ def winners_load
32
+ statistic.winners(load_db)
33
+ end
34
+
27
35
  private
28
36
 
29
37
  def player
@@ -113,13 +121,5 @@ module Codebreaker
113
121
  respondent.show_message(:leave)
114
122
  exit
115
123
  end
116
-
117
- def show_statistics
118
- respondent.show(winners_load)
119
- end
120
-
121
- def winners_load
122
- statistic.winners(load_db)
123
- end
124
124
  end
125
125
  end
data/lib/entities/game.rb CHANGED
@@ -2,17 +2,19 @@ module Codebreaker
2
2
  class Game
3
3
  include Validation
4
4
 
5
+ INCREMENT = 1
5
6
  AMOUNT_DIGITS = 4
6
- RANGE_DIGITS = 1..6
7
+ POSITIVE_DIGIT = '+'.freeze
8
+ NEGATIVE_DIGIT = '-'.freeze
7
9
  DIFFICULTIES = {
8
10
  easy: { attempts: 15, hints: 2, difficulty: 'easy' },
9
11
  hard: { attempts: 10, hints: 2, difficulty: 'hard' },
10
12
  expert: { attempts: 5, hints: 1, difficulty: 'expert' }
11
13
  }.freeze
12
- RANGE_OF_DIGITS = 0..4.freeze
14
+ RANGE_OF_DIGITS = 1..6.freeze
13
15
  GUESS_CODE = { hint: 'hint', leave: 'exit' }.freeze
14
16
 
15
- attr_reader :name, :hints_total, :have_hints, :attempts_total, :hints_used, :attempts_used, :difficulty, :winner, :attempts_left
17
+ attr_reader :got_hints, :secret_code, :name, :hints_total, :have_hints, :attempts_total, :hints_used, :attempts_used, :difficulty, :winner, :attempts_left
16
18
  attr_accessor :errors
17
19
 
18
20
  def game_options(user_difficulty:, player:)
@@ -70,12 +72,12 @@ module Codebreaker
70
72
  return unless validate_length(entity, length)
71
73
  return unless validate_match(entity)
72
74
 
73
- valid_digits?(entity, RANGE_DIGITS)
75
+ valid_digits?(entity, RANGE_OF_DIGITS)
74
76
  end
75
77
 
76
78
  def count_attempt
77
- @attempts_left -= 1
78
- @attempts_used += 1
79
+ @attempts_left -= INCREMENT
80
+ @attempts_used += INCREMENT
79
81
  end
80
82
 
81
83
  def use_hint
@@ -84,8 +86,8 @@ module Codebreaker
84
86
  end
85
87
 
86
88
  def count_tip
87
- @have_hints -= 1
88
- @hints_used += 1
89
+ @have_hints -= INCREMENT
90
+ @hints_used += INCREMENT
89
91
  @hints_array ||= secret_code.clone.shuffle
90
92
  hint = @hints_array.pop.to_s
91
93
  @got_hints += hint
@@ -103,7 +105,7 @@ module Codebreaker
103
105
 
104
106
  def guessing(user_code)
105
107
  count_attempt
106
- return @winner = true if compare_with_right_code(user_code)
108
+ @date = Time.new and return @winner = true if compare_with_right_code(user_code)
107
109
 
108
110
  pin = []
109
111
  clone_secret_code = secret_code.clone
@@ -111,13 +113,13 @@ module Codebreaker
111
113
  complex_code.map do |user_digit, secret_digit|
112
114
  next unless user_digit == secret_digit
113
115
 
114
- pin << '+'
116
+ pin << POSITIVE_DIGIT
115
117
  user_code.delete_at(user_code.index(user_digit))
116
118
  clone_secret_code.delete_at(clone_secret_code.index(secret_digit))
117
119
  end
118
120
  clone_secret_code.each do |digit|
119
121
  next unless user_code.include? digit
120
- pin << '-'
122
+ pin << NEGATIVE_DIGIT
121
123
  user_code.delete_at(user_code.index(digit))
122
124
  end
123
125
  pin.sort.join('')
@@ -9,8 +9,6 @@ module Codebreaker
9
9
  File.open(PATH, 'a+') { |f| f.write player.to_yaml }
10
10
  end
11
11
 
12
- private
13
-
14
12
  def load_db
15
13
  YAML.load_stream(File.open(PATH))
16
14
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codebreaker_PI
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Pauls
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-26 00:00:00.000000000 Z
11
+ date: 2019-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler