codebreaker-Bulatkin 0.1.0 → 0.1.1
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/Gemfile.lock +1 -1
- data/lib/codebreaker/console.rb +3 -4
- data/lib/codebreaker/game.rb +1 -5
- data/lib/codebreaker/player.rb +3 -3
- data/lib/codebreaker/version.rb +1 -1
- data/lib/locales/en.yml +3 -1
- data/lib/modules/storage.rb +30 -17
- data/lib/modules/validation.rb +0 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3c4436b52cd092b50d56261fd4e89105673c713b8d852afbb5516c3375d1759
|
4
|
+
data.tar.gz: 19113c0674f6871613e15958771f5146b7defc44c2595c4a54c1efcab0f7a4cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f59057c66e41b47a073ce0ab4faa1f24db127c8e36800b38742b839212aaa4c460d59e02d80248cdc7c79be3622e0364da6c943196ea1869b4997b538ae22204
|
7
|
+
data.tar.gz: 459e0db583ac0711c40fa15383b6cafb4d9f8972dc2a2aacb89f302212f3769f119c66a7e731d2e4dadcdc7006df163f483308c0795a4e10cec25dfacbb45739
|
data/Gemfile.lock
CHANGED
data/lib/codebreaker/console.rb
CHANGED
@@ -19,8 +19,7 @@ module Codebreaker
|
|
19
19
|
case user_input
|
20
20
|
when I18n.t(:start) then start_game_preparations
|
21
21
|
when I18n.t(:rule) then output(:rules)
|
22
|
-
when I18n.t(:stats) then statistic(sort_player
|
23
|
-
when I18n.t(:exit) then exit
|
22
|
+
when I18n.t(:stats) then statistic(sort_player)
|
24
23
|
else output(:wrong_command)
|
25
24
|
end
|
26
25
|
end
|
@@ -49,7 +48,7 @@ module Codebreaker
|
|
49
48
|
round_menu
|
50
49
|
@guess = user_input
|
51
50
|
hint_menu if guess == I18n.t(:hint)
|
52
|
-
mark if game.
|
51
|
+
mark if game.guess_valid?(guess)
|
53
52
|
won if game.won?(guess)
|
54
53
|
end
|
55
54
|
lost
|
@@ -89,7 +88,7 @@ module Codebreaker
|
|
89
88
|
|
90
89
|
def save_result
|
91
90
|
output(:save)
|
92
|
-
|
91
|
+
game.save(game.to_yaml(player.name)) if user_input == 'yes'
|
93
92
|
end
|
94
93
|
|
95
94
|
def play_again
|
data/lib/codebreaker/game.rb
CHANGED
@@ -54,12 +54,8 @@ module Codebreaker
|
|
54
54
|
@attempts -= 1
|
55
55
|
end
|
56
56
|
|
57
|
-
def validate_guess(guess)
|
58
|
-
guess_valid?(guess)
|
59
|
-
end
|
60
|
-
|
61
57
|
def guess(guess)
|
62
|
-
|
58
|
+
'+' * exact_match_count(guess) + '-' * number_match_count(guess)
|
63
59
|
end
|
64
60
|
|
65
61
|
private
|
data/lib/codebreaker/player.rb
CHANGED
@@ -15,9 +15,9 @@ module Codebreaker
|
|
15
15
|
|
16
16
|
def validate
|
17
17
|
@errors = []
|
18
|
-
|
19
|
-
errors << '
|
20
|
-
errors << '
|
18
|
+
|
19
|
+
errors << I18n.t('errors.blank') if name.empty?
|
20
|
+
errors << I18n.t('errors.size') unless size_correct?(name)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
data/lib/codebreaker/version.rb
CHANGED
data/lib/locales/en.yml
CHANGED
@@ -28,7 +28,9 @@ en:
|
|
28
28
|
hints_left: 'You have %{hints} hints more'
|
29
29
|
no_hints_left: 'No hints left'
|
30
30
|
game_end: "Want to play one more game?\n"
|
31
|
-
errors:
|
31
|
+
errors:
|
32
|
+
blank: 'Name cannot be blank'
|
33
|
+
size: 'Should be between 3-20 chars'
|
32
34
|
wrong_command: "You have passed unexpected command. Please choose one from listed commands\n"
|
33
35
|
output_name: 'Write your name, please:'
|
34
36
|
output_difficulty: "\nChoose desired mode:\n-- [hell]\n-- [medium]\n-- [easy]\n"
|
data/lib/modules/storage.rb
CHANGED
@@ -1,24 +1,37 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Codebreaker
|
4
|
-
PATH = './db'
|
5
|
-
FILE_NAME = 'data.yml'
|
6
4
|
module Storage
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
5
|
+
PATH = 'db'
|
6
|
+
FILE_NAME = 'data.yml'
|
7
|
+
|
8
|
+
def save(results)
|
9
|
+
FileUtils.mkdir_p(PATH) unless Dir.exist?(PATH)
|
10
|
+
data = load_database << results
|
11
|
+
write_data(data)
|
12
|
+
end
|
13
|
+
|
14
|
+
def load_database
|
15
|
+
YAML.safe_load(File.read(file_path))
|
16
|
+
end
|
17
|
+
|
18
|
+
def sort_player
|
19
|
+
create_storage unless File.exist?(file_path)
|
20
|
+
load_database.sort_by { |game| [game[:difficulty], game[:attempts_used], game[:hints_used]] }
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def file_path
|
26
|
+
File.join(Dir.pwd, PATH, FILE_NAME)
|
27
|
+
end
|
28
|
+
|
29
|
+
def create_storage
|
30
|
+
write_data([])
|
31
|
+
end
|
32
|
+
|
33
|
+
def write_data(data)
|
34
|
+
File.open(file_path, 'w') { |file| file.write(data.to_yaml) }
|
22
35
|
end
|
23
36
|
end
|
24
37
|
end
|
data/lib/modules/validation.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codebreaker-Bulatkin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yevhenii Bulatkin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-11-
|
11
|
+
date: 2019-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|