codebreaker_paratskiy 0.2.2 → 0.2.3

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: ec7ec95bb6e89a33ab0190224f5e0c70cda359e1d0816d1e210513197f554c50
4
- data.tar.gz: 4c09db722c5c0d47ed4faccc8862c8712e6678fb00aa902757b97e89f826760a
3
+ metadata.gz: a740c06c1d949e1351797d3ef0c2a7b72be6c4247061481dfc010ddce1f000ef
4
+ data.tar.gz: 8464c7f040eb4aa02afeb75cd00b70084a5f4626d9e993701ee6d2898b6971b1
5
5
  SHA512:
6
- metadata.gz: 175716fc24f2ad2209a35dc0ee6cd81917ebfa876c262483ab837e58c4d4332cdf8d3f155890a2c270bc927bfea410f8c1c7014d445b0c202493910827806fb2
7
- data.tar.gz: 72640b59eac91753c925fe0226ae7f5b14a0d6c30d0240a724550c857fcf5a9da4160de24771840ce3263e0aac9364c7d71fde3488fc5b4913b8ae3a660b8186
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 = DEFAULT_NAME, difficulty = DIFFICULTIES[:default])
4
- game = Game.new(name, difficulty)
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
@@ -1,3 +1,3 @@
1
1
  module CodebreakerParatskiy
2
- VERSION = '0.2.2'.freeze
2
+ VERSION = '0.2.3'.freeze
3
3
  end
@@ -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
@@ -3,7 +3,7 @@ class Console
3
3
  include CodebreakerParatskiy
4
4
  include Validating
5
5
  include Output
6
- attr_accessor :user_code, :game
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
- @game = CodebreakerParatskiy.run_game(_get_name, _get_difficulty_level)
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 DIFFICULTIES[answer.to_sym] if DIFFICULTIES.include?(answer.to_sym)
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
@@ -0,0 +1,9 @@
1
+ class CurrentGame
2
+ def initialize(game)
3
+ @@game = game
4
+ end
5
+
6
+ def self.game
7
+ @@game
8
+ end
9
+ end
@@ -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'
@@ -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 = DIFFICULTIES.key(difficulty).to_s
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
@@ -36,10 +36,10 @@ module Output
36
36
  row do
37
37
  column(player[:name])
38
38
  column(player[:difficulty])
39
- column(player[:attempts_total])
40
- column(player[:attempts_used])
41
- column(player[:hints_total])
42
- column(player[:hints_used])
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
- attr_reader :game
5
-
6
- def self.generate_stats(game)
7
- {
8
- name: game.player_name,
9
- difficulty: game.difficulty_name,
10
- attempts_total: DIFFICULTIES[game.difficulty_name.to_sym][:attempts],
11
- attempts_used: DIFFICULTIES[game.difficulty_name.to_sym][:attempts] - game.attempts,
12
- hints_total: DIFFICULTIES[game.difficulty_name.to_sym][:hints],
13
- hints_used: DIFFICULTIES[game.difficulty_name.to_sym][:hints] - game.hints,
14
- date: Time.now
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
- def self.sort_stats
19
- stats.sort_by { |player| [player[:attempts_total], player[:attempts_used], player[:hints_used]] }
20
- end
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
- def self.stats
23
- DbUtils.get(DB) || []
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.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-23 00:00:00.000000000 Z
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