cb-core 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/config/locales/en.yml +5 -2
- data/lib/codebreaker.rb +0 -4
- data/lib/codebreaker/create_stat_service.rb +5 -5
- data/lib/codebreaker/errors/game_over_error.rb +1 -1
- data/lib/codebreaker/errors/game_save_error.rb +1 -1
- data/lib/codebreaker/errors/no_hints_error.rb +1 -1
- data/lib/codebreaker/errors/validation_length_error.rb +1 -1
- data/lib/codebreaker/game.rb +21 -11
- data/lib/codebreaker/mixins/validator.rb +1 -1
- data/lib/codebreaker/version.rb +1 -1
- metadata +2 -6
- data/lib/codebreaker/difficulty.rb +0 -11
- data/lib/codebreaker/difficulty_factory.rb +0 -16
- data/lib/codebreaker/difficulty_type.rb +0 -7
- data/lib/codebreaker/errors/invalid_difficulty_error.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 177b156f01c5212b23c6bef720dc6962a5103bd09dd79f9df40b84dd3312c57c
|
4
|
+
data.tar.gz: eb3c47dd6140adb217d3e64d4bf0c69446a555dd63944db0c0d09f04d29743c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9bd350d5b79d20591e5bd3911a9c4f13817f1639af878ec8d2d520a7eb3116c9e8d74800389c2669c5874c9bc55c587c764e6bece85d53385111ba96954f71ca
|
7
|
+
data.tar.gz: 1a0db0f64f89eb34ce758b84080c3b588663500e3199b2644232948bb07270a972a5c6946503769bfcc8f22ea8befb51d3f9f9af0c638128546797fd3dc6009d
|
data/Gemfile.lock
CHANGED
data/config/locales/en.yml
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
en:
|
2
2
|
errors:
|
3
|
-
|
4
|
-
|
3
|
+
validation_length_common: Invalid string length
|
4
|
+
validation_length_detailed: "Invalid length '%{value}'. min=%{min}, max=%{max}"
|
5
|
+
game_over: No attempts available or a player won the game
|
6
|
+
game_save: Only won game could be saved
|
7
|
+
no_hints: No hints available
|
data/lib/codebreaker.rb
CHANGED
@@ -4,12 +4,8 @@ require 'i18n'
|
|
4
4
|
|
5
5
|
require_relative '../config/i18n'
|
6
6
|
|
7
|
-
require_relative 'codebreaker/difficulty'
|
8
|
-
require_relative 'codebreaker/difficulty_factory'
|
9
|
-
require_relative 'codebreaker/difficulty_type'
|
10
7
|
require_relative 'codebreaker/errors/game_over_error'
|
11
8
|
require_relative 'codebreaker/errors/game_save_error'
|
12
|
-
require_relative 'codebreaker/errors/invalid_difficulty_error'
|
13
9
|
require_relative 'codebreaker/errors/no_hints_error'
|
14
10
|
require_relative 'codebreaker/errors/validation_length_error'
|
15
11
|
require_relative 'codebreaker/create_stat_service'
|
@@ -13,11 +13,11 @@ module Codebreaker
|
|
13
13
|
def stat_data
|
14
14
|
{
|
15
15
|
name: @game.player.name,
|
16
|
-
difficulty: @game.
|
17
|
-
attempts_total: @game.
|
18
|
-
attempts_used: @game.
|
19
|
-
hints_total: @game.
|
20
|
-
hints_used: @game.
|
16
|
+
difficulty: @game.difficulty_type,
|
17
|
+
attempts_total: @game.attempts_total,
|
18
|
+
attempts_used: @game.attempts_total - @game.attempts_left,
|
19
|
+
hints_total: @game.hints_total,
|
20
|
+
hints_used: @game.hints_total - @game.hints_left
|
21
21
|
}
|
22
22
|
end
|
23
23
|
end
|
data/lib/codebreaker/game.rb
CHANGED
@@ -1,11 +1,17 @@
|
|
1
1
|
module Codebreaker
|
2
2
|
class Game
|
3
|
-
attr_reader :player, :attempts_left
|
3
|
+
attr_reader :player, :difficulty_type, :attempts_left
|
4
|
+
|
5
|
+
DIFFICULTIES = {
|
6
|
+
easy: { attempts: 15, hints: 2, hardness: 1 },
|
7
|
+
medium: { attempts: 10, hints: 1, hardness: 2 },
|
8
|
+
hell: { attempts: 5, hints: 1, hardness: 3 }
|
9
|
+
}.freeze
|
4
10
|
|
5
11
|
def initialize(player, difficulty_type)
|
6
12
|
@player = player
|
7
13
|
@difficulty_type = difficulty_type
|
8
|
-
@attempts_left = difficulty
|
14
|
+
@attempts_left = difficulty[:attempts]
|
9
15
|
@is_win = false
|
10
16
|
end
|
11
17
|
|
@@ -13,10 +19,6 @@ module Codebreaker
|
|
13
19
|
@secret_code ||= SecretCodeGenerator.new.call
|
14
20
|
end
|
15
21
|
|
16
|
-
def difficulty
|
17
|
-
@difficulty ||= DifficultyFactory.build(@difficulty_type)
|
18
|
-
end
|
19
|
-
|
20
22
|
def take_hint
|
21
23
|
ensure_game_is_not_over
|
22
24
|
raise Errors::NoHintsError if hints.empty?
|
@@ -33,7 +35,7 @@ module Codebreaker
|
|
33
35
|
end
|
34
36
|
|
35
37
|
def lose?
|
36
|
-
|
38
|
+
attempts_left.zero? && !win?
|
37
39
|
end
|
38
40
|
|
39
41
|
def win?
|
@@ -44,6 +46,14 @@ module Codebreaker
|
|
44
46
|
win? || lose?
|
45
47
|
end
|
46
48
|
|
49
|
+
def attempts_total
|
50
|
+
difficulty[:attempts]
|
51
|
+
end
|
52
|
+
|
53
|
+
def hints_total
|
54
|
+
difficulty[:hints]
|
55
|
+
end
|
56
|
+
|
47
57
|
def hints_left
|
48
58
|
hints.count
|
49
59
|
end
|
@@ -56,12 +66,12 @@ module Codebreaker
|
|
56
66
|
|
57
67
|
private
|
58
68
|
|
59
|
-
def
|
60
|
-
@
|
69
|
+
def difficulty
|
70
|
+
DIFFICULTIES[@difficulty_type]
|
61
71
|
end
|
62
72
|
|
63
|
-
def
|
64
|
-
|
73
|
+
def hints
|
74
|
+
@hints ||= secret_code.sample(difficulty[:hints])
|
65
75
|
end
|
66
76
|
|
67
77
|
def ensure_game_is_not_over
|
@@ -5,7 +5,7 @@ module Codebreaker
|
|
5
5
|
return if value.instance_of?(String) && value.size.between?(min, max)
|
6
6
|
|
7
7
|
raise Codebreaker::Errors::ValidationLengthError,
|
8
|
-
I18n.t('errors.
|
8
|
+
I18n.t('errors.validation_length_detailed', value: value, min: min, max: max)
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
data/lib/codebreaker/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cb-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmytro Yakupov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
@@ -147,12 +147,8 @@ files:
|
|
147
147
|
- config/locales/en.yml
|
148
148
|
- lib/codebreaker.rb
|
149
149
|
- lib/codebreaker/create_stat_service.rb
|
150
|
-
- lib/codebreaker/difficulty.rb
|
151
|
-
- lib/codebreaker/difficulty_factory.rb
|
152
|
-
- lib/codebreaker/difficulty_type.rb
|
153
150
|
- lib/codebreaker/errors/game_over_error.rb
|
154
151
|
- lib/codebreaker/errors/game_save_error.rb
|
155
|
-
- lib/codebreaker/errors/invalid_difficulty_error.rb
|
156
152
|
- lib/codebreaker/errors/no_hints_error.rb
|
157
153
|
- lib/codebreaker/errors/validation_length_error.rb
|
158
154
|
- lib/codebreaker/game.rb
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module Codebreaker
|
2
|
-
class DifficultyFactory
|
3
|
-
def self.build(type)
|
4
|
-
case type
|
5
|
-
when DifficultyType::EASY
|
6
|
-
Difficulty.new(DifficultyType::EASY, 15, 2)
|
7
|
-
when DifficultyType::MEDIUM
|
8
|
-
Difficulty.new(DifficultyType::MEDIUM, 10, 1)
|
9
|
-
when DifficultyType::HELL
|
10
|
-
Difficulty.new(DifficultyType::HELL, 5, 1)
|
11
|
-
else
|
12
|
-
raise Errors::InvalidDifficultyError, I18n.t('errors.invalid_difficulty', type: type)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|