codebreaker2018 0.3.2.0 → 0.3.3.0

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: e939f4dbfde225f7704f87b6446a43d99c23c68bde623002b89f71c41c0d7b34
4
- data.tar.gz: 66c37dfbee641cad5eb61257aa39c5a930cb73bcb4d22a8a873db95b2491f3d3
3
+ metadata.gz: 00ea58537c3077f4a1e42e014774cfcb738ea935ea9d2cee613797602ac240d6
4
+ data.tar.gz: 9a7ef487af42f4b4a14a8dfdad34c3e5bc138b81f36c8418660c7afe3755986e
5
5
  SHA512:
6
- metadata.gz: fc2e54e5b4d281684ef89f39ed88889fa8ed9f256f35b892b380e840ca600c6282c6482df9e94758d47a7780a32f237dd5a542c6a8ed1a374e197b4aea5762af
7
- data.tar.gz: 2d4d14b053ffdb3b28c11cb7aab709bd2ad02f8d92fe85ab8e07840241f8f78a2683ef29852574fdd8995a4e1b8c453ef09903c49c29ddbbf6828894569ca5c0
6
+ metadata.gz: 5013a43f848a620046e86131b91d2a4c225c819d5b40a17391f7511e27fd25886fd2f64541dc1c9dfa8b47ca4d58525a082ca01b4ba853656ff3ef632bda0a08
7
+ data.tar.gz: 354570b2147657593251fe140a3b2ac04fbe8c127bcb09b6958bf743d91fa4537d6fbf0c96928cc06e89f7a1fe31b583973ce9b19fed28bf22d20cdf6f98fb99
@@ -5,6 +5,7 @@ module Codebreaker
5
5
  class Console
6
6
  include Message
7
7
  include Motivation
8
+ include UserScore
8
9
  include Storage
9
10
 
10
11
  DEMO = Game.new('Demo User', 5, 2, :middle, :en)
@@ -60,18 +61,18 @@ module Codebreaker
60
61
  def user_interaction(input = EMPTY_INPUT)
61
62
  return if game.attempts.zero?
62
63
  status, step = false, 0
63
- until status
64
- begin
65
- game.guess_valid?(input)
66
- status = true
67
- rescue => error
68
- puts error.to_s.red unless step.zero? || input == HINT
69
- puts "#{message['alerts']['guess']}:"
70
- input = gets.chomp
71
- step += 1
72
- show_hint if input == HINT
73
- end
64
+ until status
65
+ begin
66
+ game.guess_valid?(input)
67
+ status = true
68
+ rescue => error
69
+ puts error.to_s.red unless step.zero? || input == HINT
70
+ puts "#{message['alerts']['guess']}:"
71
+ input = gets.chomp
72
+ step += 1
73
+ show_hint if input == HINT
74
74
  end
75
+ end
75
76
  input
76
77
  end
77
78
 
@@ -98,10 +99,10 @@ module Codebreaker
98
99
 
99
100
  def input_selector
100
101
  input = EMPTY_INPUT
101
- until %w(y n).include?(input)
102
- print " (y/n) #{message['alerts']['yes_or_no']}:"
103
- input = gets.chomp
104
- end
102
+ until %w[y n].include?(input)
103
+ print " (y/n) #{message['alerts']['yes_or_no']}:"
104
+ input = gets.chomp
105
+ end
105
106
  input == YES
106
107
  end
107
108
 
@@ -117,20 +118,6 @@ module Codebreaker
117
118
  puts message['info']['successfully_saved'].green
118
119
  end
119
120
 
120
- def save_user_score
121
- scores << current_user_score
122
- end
123
-
124
- def current_user_score
125
- Score.new do |save|
126
- save.date = Time.now
127
- save.player_name = game.configuration.player_name
128
- save.winner = game.won?
129
- save.level = game.configuration.level
130
- save.score = game.score
131
- end
132
- end
133
-
134
121
  def new_game
135
122
  print message['alerts']['new_game']
136
123
  if input_selector
@@ -45,7 +45,7 @@ module Codebreaker
45
45
  end
46
46
 
47
47
  def localizations
48
- @localizations ||= Hash.new
48
+ @localizations ||= {}
49
49
  end
50
50
 
51
51
  def merge_localizations
@@ -1,6 +1,7 @@
1
1
  module Codebreaker
2
2
  module Message
3
3
  private
4
+
4
5
  def message
5
6
  @locale.localization
6
7
  end
@@ -1,6 +1,7 @@
1
1
  module Codebreaker
2
2
  module Motivation
3
3
  private
4
+
4
5
  def message_is_allowed?
5
6
  !game.won? && game.attempts == rand(1..game.configuration.max_attempts)
6
7
  end
@@ -2,6 +2,6 @@ module Codebreaker
2
2
  Score = Struct.new(:date, :player_name, :winner, :level, :score) do
3
3
  def initialize
4
4
  yield self if block_given?
5
- end
5
+ end
6
6
  end
7
7
  end
@@ -3,13 +3,16 @@ require 'yaml'
3
3
  module Codebreaker
4
4
  module Storage
5
5
  attr_reader :storage_path
6
+
6
7
  private
8
+
7
9
  def apply_external_path(external_path = false)
8
10
  yml_file = 'scores.yml'
9
- if external_path && !Dir.exists?(external_path)
11
+ if external_path && !Dir.exist?(external_path)
10
12
  raise ArgumentError, 'Invalid external path.'
11
13
  end
12
- @storage_path = if external_path
14
+ @storage_path =
15
+ if external_path
13
16
  "#{external_path}/#{yml_file}"
14
17
  else
15
18
  File.expand_path("./data/#{yml_file}", File.dirname(__FILE__))
@@ -22,7 +25,7 @@ module Codebreaker
22
25
 
23
26
  def prepare_storage_dir
24
27
  storage_dir = File.dirname(storage_path)
25
- Dir.mkdir(storage_dir) unless File.exists?(storage_dir)
28
+ Dir.mkdir(storage_dir) unless File.exist?(storage_dir)
26
29
  end
27
30
 
28
31
  def save_to_yml
@@ -0,0 +1,19 @@
1
+ module Codebreaker
2
+ module UserScore
3
+ private
4
+
5
+ def current_user_score
6
+ Score.new do |save|
7
+ save.date = Time.now
8
+ save.player_name = game.configuration.player_name
9
+ save.winner = game.won?
10
+ save.level = game.configuration.level
11
+ save.score = game.score
12
+ end
13
+ end
14
+
15
+ def save_user_score
16
+ scores << current_user_score
17
+ end
18
+ end
19
+ end
@@ -1,3 +1,3 @@
1
1
  module Codebreaker
2
- VERSION = '0.3.2.0'
2
+ VERSION = '0.3.3.0'
3
3
  end
data/lib/codebreaker.rb CHANGED
@@ -2,6 +2,7 @@ require_relative 'codebreaker/version'
2
2
  require_relative 'codebreaker/localization'
3
3
  require_relative 'codebreaker/message'
4
4
  require_relative 'codebreaker/motivation'
5
+ require_relative 'codebreaker/user_score'
5
6
  require_relative 'codebreaker/storage'
6
7
  require_relative 'codebreaker/game'
7
8
  require_relative 'codebreaker/score'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codebreaker2018
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2.0
4
+ version: 0.3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladislav Trotsenko
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-06-20 00:00:00.000000000 Z
11
+ date: 2018-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -97,6 +97,7 @@ files:
97
97
  - lib/codebreaker/motivation.rb
98
98
  - lib/codebreaker/score.rb
99
99
  - lib/codebreaker/storage.rb
100
+ - lib/codebreaker/user_score.rb
100
101
  - lib/codebreaker/version.rb
101
102
  homepage: https://github.com/bestwebua/homework-04-codebreaker
102
103
  licenses: