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 +4 -4
- data/lib/codebreaker/console.rb +16 -29
- data/lib/codebreaker/localization.rb +1 -1
- data/lib/codebreaker/message.rb +1 -0
- data/lib/codebreaker/motivation.rb +1 -0
- data/lib/codebreaker/score.rb +1 -1
- data/lib/codebreaker/storage.rb +6 -3
- data/lib/codebreaker/user_score.rb +19 -0
- data/lib/codebreaker/version.rb +1 -1
- data/lib/codebreaker.rb +1 -0
- 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: 00ea58537c3077f4a1e42e014774cfcb738ea935ea9d2cee613797602ac240d6
|
4
|
+
data.tar.gz: 9a7ef487af42f4b4a14a8dfdad34c3e5bc138b81f36c8418660c7afe3755986e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5013a43f848a620046e86131b91d2a4c225c819d5b40a17391f7511e27fd25886fd2f64541dc1c9dfa8b47ca4d58525a082ca01b4ba853656ff3ef632bda0a08
|
7
|
+
data.tar.gz: 354570b2147657593251fe140a3b2ac04fbe8c127bcb09b6958bf743d91fa4537d6fbf0c96928cc06e89f7a1fe31b583973ce9b19fed28bf22d20cdf6f98fb99
|
data/lib/codebreaker/console.rb
CHANGED
@@ -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
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
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
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
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
|
data/lib/codebreaker/message.rb
CHANGED
data/lib/codebreaker/score.rb
CHANGED
data/lib/codebreaker/storage.rb
CHANGED
@@ -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.
|
11
|
+
if external_path && !Dir.exist?(external_path)
|
10
12
|
raise ArgumentError, 'Invalid external path.'
|
11
13
|
end
|
12
|
-
@storage_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.
|
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
|
data/lib/codebreaker/version.rb
CHANGED
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.
|
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-
|
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:
|