codebreakergem 0.1.12 → 0.1.13

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.
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Codebreakergem
4
+ class InformationPresenter
5
+ class << self
6
+ def rules
7
+ I18n.t(:rules)
8
+ end
9
+
10
+ def stats
11
+ result = I18n.t(:stats_header)
12
+ stats_from_file = FileWorker.read_from_file(Game::FILE)
13
+ return result unless stats_from_file
14
+
15
+ if stats_from_file.is_a? Array
16
+ sorted_data = stats_from_file.sort_by { |item| [item[:order], item[:attempts_used], item[:hints_used]] }
17
+ sorted_data.each_with_index { |item, index| result += stats_constructor(index + 1, item) }
18
+ else
19
+ result += stats_constructor(1, stats_from_file)
20
+ end
21
+ result
22
+ end
23
+
24
+ private
25
+
26
+ def stats_constructor(index, item)
27
+ "#{index}\t #{item[:name]}\t #{item[:difficulty]}\t #{item[:attempts_total]}\t " \
28
+ "#{item[:attempts_used]}\t #{item[:hints_total]}\t #{item[:hints_used]}\n"
29
+ end
30
+ end
31
+ end
32
+ end
data/lib/classes/user.rb CHANGED
@@ -1,17 +1,17 @@
1
- # frozen_string_literal: true
2
-
3
- module Codebreakergem
4
- class User
5
- include Checker
6
-
7
- attr_accessor :name
8
-
9
- def initialize(name)
10
- @name = name
11
- end
12
-
13
- def validate?
14
- validate_string_length(name)
15
- end
16
- end
17
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Codebreakergem
4
+ class User
5
+ include Checker
6
+
7
+ attr_accessor :name
8
+
9
+ def initialize(name)
10
+ @name = name
11
+ end
12
+
13
+ def valid?
14
+ validate_string_length(name)
15
+ end
16
+ end
17
+ end
@@ -1,19 +1,19 @@
1
- # frozen_string_literal: true
2
-
3
- require 'yaml'
4
- require 'i18n'
5
- require 'pry'
6
- require 'modules/check_module.rb'
7
- require 'classes/difficulties/difficulty.rb'
8
- require 'classes/difficulties/Easy.rb'
9
- require 'classes/difficulties/Medium.rb'
10
- require 'classes/difficulties/Hell.rb'
11
- require 'classes/user.rb'
12
- require 'classes/game.rb'
13
- require 'classes/statistic.rb'
14
- require 'classes/file_worker'
15
- require 'config.rb'
16
- require 'codebreakergem/version.rb'
17
-
18
- module Codebreakergem
19
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+ require 'i18n'
5
+ require 'pry'
6
+ require 'modules/check_module.rb'
7
+ require 'classes/difficulties/difficulty.rb'
8
+ require 'classes/difficulties/easy.rb'
9
+ require 'classes/difficulties/medium.rb'
10
+ require 'classes/difficulties/hell.rb'
11
+ require 'classes/user.rb'
12
+ require 'classes/game.rb'
13
+ require 'classes/information_presenter.rb'
14
+ require 'classes/file_worker'
15
+ require 'config.rb'
16
+ require 'codebreakergem/version.rb'
17
+
18
+ module Codebreakergem
19
+ end
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
-
3
- module Codebreakergem
4
- VERSION = '0.1.12'
5
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Codebreakergem
4
+ VERSION = '0.1.13'
5
+ end
data/lib/config.rb CHANGED
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
-
3
- I18n.load_path = Dir[File.expand_path(__dir__ + '/locales') + '/*.yml']
4
- I18n.config.available_locales = :en
5
- I18n.locale = :en
1
+ # frozen_string_literal: true
2
+
3
+ I18n.load_path = Dir[File.expand_path(__dir__ + '/locales') + '/*.yml']
4
+ I18n.config.available_locales = :en
5
+ I18n.locale = :en
data/lib/locales/en.yml CHANGED
@@ -1,50 +1,53 @@
1
- en:
2
- class_error: 'Wrong type of variable'
3
- length_error: 'Length of the string is not in allowed range'
4
- no_hints: 'You have no more hints'
5
- hello_message: 'Hello player! Welcome to codebreaker'
6
- stats_header: "Rating Name Difficulty Attempts Total Attempts Used Hints Total Hints Used\n"
7
- menu: "Chose action:\n
8
- 1) Start\n
9
- 2) Rules\n
10
- 3) Stats\n
11
- 4) Exit\n"
12
- victory_message: 'Congratulations!!! YOU WON!!!'
13
- goodbye_message: "Thank you for playing\nSee you next time"
14
- input_name: "Input player's name:"
15
- difficulty: 'Chose difficulty'
16
- invalid_command: 'You have passed unexpected command. Please choose one from listed commands'
17
- out_of_attempts: 'Unfortunately you have no more attempts'
18
- rules: " ____________________________________________________________________________________________\n
19
- | |\n
20
- | Rules |\n
21
- |____________________________________________________________________________________________|\n
22
- | |\n
23
- | * Codebreaker is a logic game in which a code-breaker tries to break a secret code |\n
24
- | created by a code-maker. The codemaker, which will be played by the application we’re |\n
25
- | going to write, creates a secret code of four numbers between 1 and 6. |\n
26
- | |\n
27
- | * The codebreaker gets some number of chances to break the code (depends on chosen |\n
28
- | difficulty). In each turn, the codebreaker makes a guess of 4 numbers. The codemaker |\n
29
- | then marks the guess with up to 4 signs - '+' or '-' or empty spaces. |\n
30
- | |\n
31
- | * A + indicates an exact match: one of the numbers in the guess is the same as one of the |\n
32
- | numbers in the secret code and in the same position. For example: |\n
33
- | Secret number - 1234 |\n
34
- | Input number - 6264 |\n
35
- | Number of pluses - 2 (second and fourth position) |\n
36
- | |\n
37
- | * A - indicates a number match: one of the numbers in the guess is the same as one of the |\n
38
- | numbers in the secret code but in a different position. For example: |\n
39
- | Secret number - 1234 |\n
40
- | Input number - 6462 |\n
41
- | Number of minuses - 2 (second and fourth position) |\n
42
- | |\n
43
- | * An empty space indicates that there is not a current digit in a secret number. |\n
44
- | |\n
45
- | * If codebreaker inputs the exact number as a secret number - codebreaker wins the |\n
46
- | game. If all attempts are spent - codebreaker loses. |\n
47
- | |\n
48
- | * Codebreaker also has some number of hints(depends on chosen difficulty). If a user |\n
49
- | takes a hint - he receives back a separate digit of the secret code. |\n
50
- |____________________________________________________________________________________________|"
1
+ en:
2
+ class_error: 'Wrong type of variable'
3
+ length_error: 'Length of the string is not in allowed range'
4
+ no_hints: 'You have no more hints'
5
+ hello_message: 'Hello player! Welcome to codebreaker'
6
+ stats_header: "Rating Name Difficulty Attempts Total Attempts Used Hints Total Hints Used\n"
7
+ menu: "Chose action:\n
8
+ 1) Start\n
9
+ 2) Rules\n
10
+ 3) Stats\n
11
+ 4) Exit\n"
12
+ victory_message: 'Congratulations!!! YOU WON!!!'
13
+ goodbye_message: "Thank you for playing\nSee you next time"
14
+ input_name: "Input player's name:"
15
+ difficulty: "Chose difficulty:\n
16
+ - Easy\n
17
+ - Medium\n
18
+ - Hell\n"
19
+ invalid_command: 'You have passed unexpected command. Please choose one from listed commands'
20
+ out_of_attempts: 'Unfortunately you have no more attempts'
21
+ rules: " ____________________________________________________________________________________________\n
22
+ | |\n
23
+ | Rules |\n
24
+ |____________________________________________________________________________________________|\n
25
+ | |\n
26
+ | * Codebreaker is a logic game in which a code-breaker tries to break a secret code |\n
27
+ | created by a code-maker. The codemaker, which will be played by the application we’re |\n
28
+ | going to write, creates a secret code of four numbers between 1 and 6. |\n
29
+ | |\n
30
+ | * The codebreaker gets some number of chances to break the code (depends on chosen |\n
31
+ | difficulty). In each turn, the codebreaker makes a guess of 4 numbers. The codemaker |\n
32
+ | then marks the guess with up to 4 signs - '+' or '-' or empty spaces. |\n
33
+ | |\n
34
+ | * A + indicates an exact match: one of the numbers in the guess is the same as one of the |\n
35
+ | numbers in the secret code and in the same position. For example: |\n
36
+ | Secret number - 1234 |\n
37
+ | Input number - 6264 |\n
38
+ | Number of pluses - 2 (second and fourth position) |\n
39
+ | |\n
40
+ | * A - indicates a number match: one of the numbers in the guess is the same as one of the |\n
41
+ | numbers in the secret code but in a different position. For example: |\n
42
+ | Secret number - 1234 |\n
43
+ | Input number - 6462 |\n
44
+ | Number of minuses - 2 (second and fourth position) |\n
45
+ | |\n
46
+ | * An empty space indicates that there is not a current digit in a secret number. |\n
47
+ | |\n
48
+ | * If codebreaker inputs the exact number as a secret number - codebreaker wins the |\n
49
+ | game. If all attempts are spent - codebreaker loses. |\n
50
+ | |\n
51
+ | * Codebreaker also has some number of hints(depends on chosen difficulty). If a user |\n
52
+ | takes a hint - he receives back a separate digit of the secret code. |\n
53
+ |____________________________________________________________________________________________|"
@@ -1,11 +1,11 @@
1
- # frozen_string_literal: true
2
-
3
- module Codebreakergem
4
- module Checker
5
- ALLOWED_LENGTH = (3..21).freeze
6
-
7
- def validate_string_length(incoming_string)
8
- ALLOWED_LENGTH.include?(incoming_string.to_s.length) ? true : false
9
- end
10
- end
11
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Codebreakergem
4
+ module Checker
5
+ ALLOWED_LENGTH = (3..21).freeze
6
+
7
+ def validate_string_length(incoming_string)
8
+ ALLOWED_LENGTH.include?(incoming_string.to_s.length)
9
+ end
10
+ end
11
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codebreakergem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.12
4
+ version: 0.1.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sasha
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-02 00:00:00.000000000 Z
11
+ date: 2020-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -81,14 +81,13 @@ files:
81
81
  - lib/classes/difficulties/medium.rb
82
82
  - lib/classes/file_worker.rb
83
83
  - lib/classes/game.rb
84
- - lib/classes/statistic.rb
84
+ - lib/classes/information_presenter.rb
85
85
  - lib/classes/user.rb
86
86
  - lib/codebreakergem.rb
87
87
  - lib/codebreakergem/version.rb
88
88
  - lib/config.rb
89
89
  - lib/data/.gitkeep
90
90
  - lib/locales/en.yml
91
- - lib/locales/ru.yml
92
91
  - lib/modules/check_module.rb
93
92
  homepage: https://github.com/SashaZhuravskiy/CodebreakerGemRepo/
94
93
  licenses:
@@ -113,7 +112,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
112
  - !ruby/object:Gem::Version
114
113
  version: '0'
115
114
  requirements: []
116
- rubygems_version: 3.0.3
115
+ rubyforge_project:
116
+ rubygems_version: 2.7.6
117
117
  signing_key:
118
118
  specification_version: 4
119
119
  summary: Codebreaker gem
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Codebreakergem
4
- class Statistic
5
- attr_reader :name, :difficulty, :attempts_total,
6
- :attempts_used, :hints_total, :hints_used
7
-
8
- def initialize(name:, difficulty:, attempts_total:, hints_total:)
9
- @name = name
10
- @difficulty = difficulty
11
- @attempts_total = attempts_total
12
- @attempts_used = attempts_total - difficulty.attempts
13
- @hints_total = hints_total
14
- @hints_used = hints_total - difficulty.hints
15
- end
16
- end
17
- end
data/lib/locales/ru.yml DELETED
@@ -1,2 +0,0 @@
1
- ru:
2
- class_error: 'Неверный тип переменной'