codebreakergem 0.1.4 → 0.1.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f5e411f388225f963b8a43b635a2f90c12604edcbb66b185780196bd60af15fb
4
- data.tar.gz: 28a90a9ac3d9a4dca055d627db670e3b2873f5693bb232e56a7ef9778ed7f568
3
+ metadata.gz: 2e9c327984befd015e4cec054aff67ce2029ab3daaec0edf871c0c0e762c896c
4
+ data.tar.gz: d1578f083dbe6c1a0b43642d2a5e20244594fd05a0373920561a6e08e13ea90f
5
5
  SHA512:
6
- metadata.gz: 9c0460713b4383f1d8a0932353492f909d7c6dece9d1440c6912f52c9367eb188f8128e4b7f87fed883042279f8015c9e2365bfcfe822cf7e961557813df42fd
7
- data.tar.gz: 9faf46727710374ec534ab5478c30aecd541552fca8e84f9e504b53b6f98d401bb8b8a5d7eb5c21b47607ac1eb9852aeaa840c8726ffe667a42961fe98f06ea5
6
+ metadata.gz: bd84bb3416395b7ec73326fcf66402374b4ac20eb743394b980552a4965750f7373c6d24f9aeeff62b40e392fcb07261e7bbe721d17b1e2e2b3330be7f77c777
7
+ data.tar.gz: 851e28b9b47f99c24470f194603de61017017d639e7064e6ec37704507ccc87a1a8b6b4784a6b4bc9744c2e2772379e3b51e1bf937e6148d6fdfd6bc843ddcdf
@@ -0,0 +1 @@
1
+ --- Hello world
@@ -22,7 +22,7 @@ module Codebreakergem
22
22
  COMMANDS = %w[hint exit].freeze
23
23
  GUESS_PLACE = '+'
24
24
  GUESS_PRESENCE = '-'
25
- FILE = 'lib\data\data.yml'
25
+ FILE = File.expand_path(__dir__ + '/data/data.yml')
26
26
 
27
27
  attr_reader :secret_code, :user
28
28
  attr_accessor :difficulty, :statistics
@@ -42,8 +42,6 @@ module Codebreakergem
42
42
  end
43
43
 
44
44
  def try_guess(guess)
45
- return I18n.t(:out_of_attempts) unless difficulty.attempts.positive?
46
-
47
45
  if guess == secret_code
48
46
  save
49
47
  difficulty.attempts = 0
@@ -51,6 +49,8 @@ module Codebreakergem
51
49
  end
52
50
 
53
51
  difficulty.attempts -= 1
52
+ return I18n.t(:out_of_attempts) unless difficulty.attempts.positive?
53
+
54
54
  make_guess(guess)
55
55
  end
56
56
 
@@ -73,22 +73,22 @@ module Codebreakergem
73
73
  end
74
74
 
75
75
  def stats
76
- index = 1
76
+ index = 0
77
77
  result = I18n.t(:stats_header)
78
- data = FileWorker.read_from_file(FILE)
79
- return unless data
80
-
81
- if data.is_a?(Array)
82
- sorted_data = data.select { |item| item.is_a? Statistic }.sort_by { |item| [item.difficulty.order, item.attempts_used, item.hints_used] }
83
- sorted_data.each do |item|
84
- result += "#{index}\t #{item.name}\t #{item.difficulty.name}\t #{item.attempts_total}\t #{item.attempts_used}\t #{item.hints_total}\t #{item.hints_used}\n"
85
- index += 1
86
- end
87
- else
88
- result += "1\t #{data.name}\t #{data.difficulty.name}\t #{data.attempts_total}\t #{data.attempts_used}\t #{data.hints_total}\t #{data.hints_used}\n"
89
- end
78
+ data = Array(FileWorker.read_from_file(FILE))
79
+ return result unless data
80
+
81
+ sorted_data = data.sort_by { |item| [item.difficulty.order, item.attempts_used, item.hints_used] }
82
+ sorted_data.each { |item| result += stats_constructor(index += 1, item) }
90
83
  result
91
84
  end
85
+
86
+ private
87
+
88
+ def stats_constructor(index, item)
89
+ "#{index}\t #{item.name}\t #{item.difficulty.name}\t #{item.attempts_total}\t " \
90
+ "#{item.attempts_used}\t #{item.hints_total}\t #{item.hints_used}\n"
91
+ end
92
92
  end
93
93
 
94
94
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Codebreakergem
4
- VERSION = '0.1.4'
4
+ VERSION = '0.1.5'
5
5
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- I18n.load_path = Dir[File.expand_path('lib/locales') + '/*.yml']
3
+ I18n.load_path = Dir[File.expand_path(__dir__ + '/locales') + '/*.yml']
4
4
  I18n.config.available_locales = :en
5
5
  I18n.locale = :en
data/main.rb ADDED
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require './lib/codebreakergem.rb'
4
+ include Codebreakergem
5
+
6
+ def hello_message
7
+ puts 'Hello'
8
+ end
9
+
10
+ def menu
11
+ puts "Chose action:\n 1) Start\n 2) Rules\n 3) Stats\n 4) Exit\n"
12
+ end
13
+
14
+ def goodbye_message
15
+ puts "Thank you for playing\nSee you next time"
16
+ end
17
+
18
+ def play_game
19
+ user = nil
20
+ user_input = ''
21
+ puts "Input player's name:"
22
+
23
+ loop do
24
+ user = User.new(gets.chomp)
25
+ break if user.validate?
26
+ end
27
+ game = Game.new(user)
28
+
29
+ difficulties = Game::DIFFICULTIES.map(&:name)
30
+
31
+ loop do
32
+ puts "Chose difficulty"
33
+ difficulties.each {|key| puts " -#{key}"}
34
+ user_input = gets.chomp
35
+ break if difficulties.include? user_input
36
+ puts "Input one of proposed options"
37
+ end
38
+ game.difficulty = Game::DIFFICULTIES.find{|item| item.name == user_input}.dup
39
+
40
+
41
+ while game.difficulty.attempts.positive? do
42
+ puts 'Input your guess:'
43
+ user_input = gets.chomp
44
+ next unless game.validate_guess(user_input)
45
+ if user_input == "hint"
46
+ puts game.show_hint
47
+ elsif user_input == "exit"
48
+ break
49
+ else
50
+ puts game.try_guess(user_input)
51
+ end
52
+ end
53
+ end
54
+
55
+ def game_process
56
+ hello_message
57
+ loop do
58
+ menu
59
+ case gets.chomp
60
+ when "Start" then play_game
61
+ when "Rules" then puts Game.rules
62
+ when "Stats" then puts Game.stats
63
+ when "Exit" then break
64
+ else puts "You have passed unexpected command. Please choose one from listed commands"
65
+ end
66
+ end
67
+ goodbye_message
68
+ end
69
+
70
+ def write_to_file(filename, data)
71
+ File.open(filename, 'w') { |file| file.write(data.to_yaml) }
72
+ end
73
+
74
+ #puts(File.expand_path('lib/data'))
75
+ #write_to_file(File.expand_path('lib/data') + 'data.yml', "Hello world")
76
+ game_process
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codebreakergem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sasha
@@ -73,10 +73,8 @@ files:
73
73
  - Rakefile
74
74
  - bin/console
75
75
  - bin/setup
76
- - codebreakergem-0.1.0.gem
77
- - codebreakergem-0.1.1.gem
78
- - codebreakergem-0.1.2.gem
79
76
  - codebreakergem.gemspec
77
+ - datadata.yml
80
78
  - lib/classes/difficulty.rb
81
79
  - lib/classes/file_worker.rb
82
80
  - lib/classes/statistic.rb
@@ -85,10 +83,10 @@ files:
85
83
  - lib/codebreakergem/version.rb
86
84
  - lib/config.rb
87
85
  - lib/data/.gitkeep
88
- - lib/data/data.yml
89
86
  - lib/locales/en.yml
90
87
  - lib/locales/ru.yml
91
88
  - lib/modules/check_module.rb
89
+ - main.rb
92
90
  homepage: https://github.com/SashaZhuravskiy/CodebreakerGemRepo/
93
91
  licenses:
94
92
  - MIT
Binary file
Binary file
Binary file
@@ -1,23 +0,0 @@
1
- ---
2
- - !ruby/object:Codebreakergem::Statistic
3
- name: Alex
4
- difficulty: !ruby/object:Codebreakergem::Difficulty
5
- name: Easy
6
- attempts: 8
7
- hints: 1
8
- order: 3
9
- attempts_total: 15
10
- attempts_used: 7
11
- hints_total: 2
12
- hints_used: 1
13
- - !ruby/object:Codebreakergem::Statistic
14
- name: Alex
15
- difficulty: !ruby/object:Codebreakergem::Difficulty
16
- name: Medium
17
- attempts: 5
18
- hints: 1
19
- order: 2
20
- attempts_total: 10
21
- attempts_used: 5
22
- hints_total: 1
23
- hints_used: 0