codebreaker_paratskiy 0.2.2 → 0.2.3
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 +4 -4
- data/lib/codebreaker_paratskiy.rb +4 -4
- data/lib/codebreaker_paratskiy/version.rb +1 -1
- data/lib/config/constants.rb +1 -2
- data/lib/console.rb +7 -3
- data/lib/current_game.rb +9 -0
- data/lib/dependencies.rb +1 -0
- data/lib/game.rb +3 -3
- data/lib/modules/output.rb +4 -4
- data/lib/services/statistic_service.rb +46 -18
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a740c06c1d949e1351797d3ef0c2a7b72be6c4247061481dfc010ddce1f000ef
|
4
|
+
data.tar.gz: 8464c7f040eb4aa02afeb75cd00b70084a5f4626d9e993701ee6d2898b6971b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb59f3acd35765e86d82b59cb40c1b7ee1d1703fd780d4b1ada45690a4dfcae9c49fd3688c6bf3b80cb1335ae9a3226b04df5ebb19e076ba6dd05f8cea763756
|
7
|
+
data.tar.gz: 6278c095c690e9277d89787c41189c16e539b8a1a3cdffc3208536339cb0756cac2ae8c4c82614eba555869c4d6d6dfa82c2f39bf4335545a8cd495afae1b490
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require_relative 'game'
|
2
|
+
require_relative 'current_game'
|
2
3
|
module CodebreakerParatskiy
|
3
|
-
def self.run_game(name
|
4
|
-
|
5
|
-
game.run
|
6
|
-
game
|
4
|
+
def self.run_game(name, difficulty)
|
5
|
+
CurrentGame.new(Game.new(name, difficulty))
|
6
|
+
CurrentGame.game.run
|
7
7
|
end
|
8
8
|
end
|
data/lib/config/constants.rb
CHANGED
@@ -3,8 +3,7 @@ DB = 'stats.yml'.freeze
|
|
3
3
|
DIFFICULTIES = {
|
4
4
|
easy: { attempts: 15, hints: 2 },
|
5
5
|
medium: { attempts: 10, hints: 1 },
|
6
|
-
hell: { attempts: 5, hints: 1 }
|
7
|
-
default: { attempts: 0, hints: 0 }
|
6
|
+
hell: { attempts: 5, hints: 1 }
|
8
7
|
}.freeze
|
9
8
|
|
10
9
|
DEFAULT_NAME = 'default'.freeze
|
data/lib/console.rb
CHANGED
@@ -3,7 +3,7 @@ class Console
|
|
3
3
|
include CodebreakerParatskiy
|
4
4
|
include Validating
|
5
5
|
include Output
|
6
|
-
attr_accessor :user_code
|
6
|
+
attr_accessor :user_code
|
7
7
|
|
8
8
|
def initialize
|
9
9
|
@user_code = []
|
@@ -64,7 +64,7 @@ class Console
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def registration
|
67
|
-
|
67
|
+
CodebreakerParatskiy.run_game(_get_name, _get_difficulty_level)
|
68
68
|
end
|
69
69
|
|
70
70
|
def _get_name
|
@@ -80,7 +80,7 @@ class Console
|
|
80
80
|
def _get_difficulty_level
|
81
81
|
show_msg(:EnterDifficulty)
|
82
82
|
answer = user_enter
|
83
|
-
return
|
83
|
+
return answer if DIFFICULTIES.include?(answer.to_sym)
|
84
84
|
|
85
85
|
show_msg(:InvalidCommand)
|
86
86
|
_get_difficulty_level
|
@@ -115,4 +115,8 @@ class Console
|
|
115
115
|
def exit?(answer)
|
116
116
|
answer == EXIT_COMMAND
|
117
117
|
end
|
118
|
+
|
119
|
+
def game
|
120
|
+
CurrentGame.game
|
121
|
+
end
|
118
122
|
end
|
data/lib/current_game.rb
ADDED
data/lib/dependencies.rb
CHANGED
@@ -8,6 +8,7 @@ require_relative 'i18n_config'
|
|
8
8
|
require_relative 'error'
|
9
9
|
require_relative 'services/matching_service'
|
10
10
|
require_relative 'services/statistic_service'
|
11
|
+
require_relative 'current_game'
|
11
12
|
require_relative 'game'
|
12
13
|
require_relative 'modules/validating'
|
13
14
|
require_relative 'modules/output'
|
data/lib/game.rb
CHANGED
@@ -7,9 +7,9 @@ class Game
|
|
7
7
|
def initialize(player_name, difficulty)
|
8
8
|
@stats = Statistic.stats
|
9
9
|
@player_name = player_name
|
10
|
-
@difficulty_name =
|
11
|
-
@attempts = difficulty[:attempts]
|
12
|
-
@hints = difficulty[:hints]
|
10
|
+
@difficulty_name = difficulty
|
11
|
+
@attempts = DIFFICULTIES[difficulty.to_sym][:attempts]
|
12
|
+
@hints = DIFFICULTIES[difficulty.to_sym][:hints]
|
13
13
|
@db = DB
|
14
14
|
@secret_code_for_hint = []
|
15
15
|
end
|
data/lib/modules/output.rb
CHANGED
@@ -36,10 +36,10 @@ module Output
|
|
36
36
|
row do
|
37
37
|
column(player[:name])
|
38
38
|
column(player[:difficulty])
|
39
|
-
column(player[:
|
40
|
-
column(player[:
|
41
|
-
column(player[:
|
42
|
-
column(player[:
|
39
|
+
column(player[:total_attempts])
|
40
|
+
column(player[:used_attempts])
|
41
|
+
column(player[:total_hints])
|
42
|
+
column(player[:used_hints])
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
@@ -1,25 +1,53 @@
|
|
1
1
|
require_relative '../utils/db_utils'
|
2
2
|
require_relative '../config/constants'
|
3
3
|
class Statistic
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
4
|
+
class << self
|
5
|
+
def generate_stats(game)
|
6
|
+
{
|
7
|
+
name: player_name,
|
8
|
+
difficulty: difficulty_name,
|
9
|
+
total_attempts: total_attempts,
|
10
|
+
used_attempts: used_attempts,
|
11
|
+
total_hints: total_hints,
|
12
|
+
used_hints: used_hints,
|
13
|
+
date: Time.now
|
14
|
+
}
|
15
|
+
end
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
def sort_stats
|
18
|
+
stats.sort_by { |player| [player[:total_attempts], player[:used_attempts], player[:used_hints]] }
|
19
|
+
end
|
20
|
+
|
21
|
+
def stats
|
22
|
+
DbUtils.get(DB) || []
|
23
|
+
end
|
24
|
+
|
25
|
+
def total_attempts
|
26
|
+
DIFFICULTIES[game.difficulty_name.to_sym][:attempts]
|
27
|
+
end
|
28
|
+
|
29
|
+
def used_attempts
|
30
|
+
DIFFICULTIES[game.difficulty_name.to_sym][:attempts] - game.attempts
|
31
|
+
end
|
32
|
+
|
33
|
+
def total_hints
|
34
|
+
DIFFICULTIES[game.difficulty_name.to_sym][:hints]
|
35
|
+
end
|
36
|
+
|
37
|
+
def used_hints
|
38
|
+
DIFFICULTIES[game.difficulty_name.to_sym][:hints] - game.hints
|
39
|
+
end
|
40
|
+
|
41
|
+
def difficulty_name
|
42
|
+
game.difficulty_name
|
43
|
+
end
|
44
|
+
|
45
|
+
def player_name
|
46
|
+
game.player_name
|
47
|
+
end
|
21
48
|
|
22
|
-
|
23
|
-
|
49
|
+
def game
|
50
|
+
CurrentGame.game
|
51
|
+
end
|
24
52
|
end
|
25
53
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codebreaker_paratskiy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bogdan Paratskiy
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-09-
|
11
|
+
date: 2019-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -215,6 +215,7 @@ files:
|
|
215
215
|
- lib/codebreaker_paratskiy/version.rb
|
216
216
|
- lib/config/constants.rb
|
217
217
|
- lib/console.rb
|
218
|
+
- lib/current_game.rb
|
218
219
|
- lib/dependencies.rb
|
219
220
|
- lib/error.rb
|
220
221
|
- lib/game.rb
|