codebreaker_captainjns 0.2.1 → 0.3.0

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: 0f008643217366ac9d30fe37ee7b984abad4dea44d3e3750d5c9f074080943f4
4
- data.tar.gz: a0ee1229688b730cff4ae65ec1e7b9c7de6f55ccd313286e57f6a826b8c510c9
3
+ metadata.gz: 6b2e66d91a31a575dde95e0c1592dfec1808fcdf1bd58e19e4c5d5cfdde1ad2c
4
+ data.tar.gz: 1bedaa8ce6ce756825a3abe6963348e9fb68ef6e2406e5a824bc826b4b479473
5
5
  SHA512:
6
- metadata.gz: cfc717e6854c15dcf40a5610a15bf2a032cb487144ae61434fc65baa8f9b9a85dbf182babc7a20ecca9e16a1d8b9cb08a413ccce1de89da33801d28f8953d40b
7
- data.tar.gz: 3c98c243921299082e3cf68d80ca546139afc450e3179bcdccdf1a47657c1340234d99847333d6b9eb0f475668f3f10958d81826eece7c850588f104982b22be
6
+ metadata.gz: da38978d24f8e1396d130abcb7a36ee600ee680f807cc3a0a650161d6a5877ae8cca47598dfe682e9e3eb88d678877015e8fec8897502ea5d9ec43dccc43fd73
7
+ data.tar.gz: 461d939c68bc7ff294a94f5d4486c217e89e6957369ecf0fe3a67e775855ca01ff666d9bca2def52305ac1615b79a95bac402bb680d3a582f4b3e86878499b9d
data/Gemfile CHANGED
@@ -1,5 +1,7 @@
1
- source "https://rubygems.org"
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in codebreaker_captainjns.gemspec
4
6
  gemspec
5
- # gem 'i18n', '~> 1.6'
7
+ # gem 'i18n', '~> 1.6'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- codebreaker_captainjns (0.2.1)
4
+ codebreaker_captainjns (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task :default => :spec
8
+ task default: :spec
data/bin/console CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "bundler/setup"
4
- require "codebreaker_captainjns"
4
+ require 'bundler/setup'
5
+ require 'codebreaker_captainjns'
5
6
 
6
7
  # You can add fixtures and/or initialization code here to make experimenting
7
8
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +11,5 @@ require "codebreaker_captainjns"
10
11
  # require "pry"
11
12
  # Pry.start
12
13
 
13
- require "irb"
14
+ require 'irb'
14
15
  IRB.start(__FILE__)
@@ -1,18 +1,19 @@
1
+ # frozen_string_literal: true
1
2
 
2
- lib = File.expand_path("../lib", __FILE__)
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "codebreaker_captainjns/version"
5
+ require 'codebreaker_captainjns/version'
5
6
 
6
7
  Gem::Specification.new do |spec|
7
- spec.name = "codebreaker_captainjns"
8
+ spec.name = 'codebreaker_captainjns'
8
9
  spec.version = CodebreakerCaptainjns::VERSION
9
- spec.authors = ["Jason"]
10
- spec.email = ["sereda9623@gmail.com"]
10
+ spec.authors = ['Jason']
11
+ spec.email = ['sereda9623@gmail.com']
11
12
 
12
- spec.summary = "Codebreaker gem for Ruby Garage from CaptainJNS"
13
+ spec.summary = 'Codebreaker gem for Ruby Garage from CaptainJNS'
13
14
  # spec.description = %q{TODO: Write a longer description or delete this line.}
14
- spec.homepage = "http://mygemserver.com"
15
- spec.license = "MIT"
15
+ spec.homepage = 'http://mygemserver.com'
16
+ spec.license = 'MIT'
16
17
 
17
18
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
19
  # to allow pushing to a single host or delete this section to allow pushing to any host.
@@ -29,15 +30,15 @@ Gem::Specification.new do |spec|
29
30
 
30
31
  # Specify which files should be added to the gem when it is released.
31
32
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
32
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
33
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
33
34
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
34
35
  end
35
- spec.bindir = "exe"
36
+ spec.bindir = 'exe'
36
37
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
- spec.require_paths = ["lib"]
38
+ spec.require_paths = ['lib']
38
39
 
39
- spec.add_development_dependency "bundler", "~> 2.0"
40
- spec.add_development_dependency "rake", "~> 10.0"
41
- spec.add_development_dependency "rspec", "~> 3.0"
40
+ spec.add_development_dependency 'bundler', '~> 2.0'
42
41
  spec.add_development_dependency 'i18n', '~> 1.6'
42
+ spec.add_development_dependency 'rake', '~> 10.0'
43
+ spec.add_development_dependency 'rspec', '~> 3.0'
43
44
  end
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  I18n.load_path << Dir[File.dirname(__FILE__) + '/locales/*.yml']
@@ -1,38 +1,39 @@
1
1
  en:
2
- greeting: "Welcome to codebreaker!\n"
3
- goodbye: "Goodbye!\n"
4
- rules: "GAME RULES\n
5
- # Codebreaker is a logic game in which a code-breaker tries to break a secret code created by a code-maker. The\n codemaker, which will be played by the application we’re going to write, creates a secret code of four numbers between\n 1 and 6.\n
6
- # The codebreaker gets some number of chances to break the code (depends on chosen difficulty). In each turn, the\n codebreaker makes a guess of 4 numbers. The codemaker then marks the guess with up to 4 signs - + or - or empty\n spaces.\n
7
- # A + indicates an exact match: one of the numbers in the guess is the same as one of the numbers in the secret code\n and in the same position. For example:\n
8
- Secret number - 1234\n
9
- Input number - 6264\n
10
- Number of pluses - 2 (second and fourth position)\n
11
- # A - indicates a number match: one of the numbers in the guess is the same as one of the numbers in the secret code\n but in a different position. For example:\n
12
- Secret number - 1234\n
13
- Input number - 6462\n
14
- Number of minuses - 2 (second and fourth position)\n
15
- # An empty space indicates that there is not a current digit in a secret number.\n
16
- # If codebreaker inputs the exact number as a secret number - codebreaker wins the game. If all attempts are spent -\n codebreaker loses.\n
17
- # Codebreaker also has some number of hints(depends on chosen difficulty). If a user takes a hint - he receives back a\n
18
- separate digit of the secret code.\n"
19
- menu: "Choose one of next scenarios: 'start', 'rules', 'stats', 'exit'"
20
- choose_difficulty: "Choose difficulty: easy, medium, hard, HELL"
21
- choose_name: "Choose your name"
22
- win: "Congratulations! You win!"
23
- lose: "Sorry, you lose. Maybe another time."
24
- wrong_difficulty: "There is no such difficulty. Please choose one from listed"
25
- wrong_name: "Choosen name is invalid. Name must be between 3 and 20 characters.\nPlease choose another one"
26
- wrong_process: "There is no such command or your number is invalid. You can try use hint or exit"
27
- wrong_run: "You have passed unexpected command. Please choose one from listed commands"
28
- easy: "Easy"
29
- medium: "Medium"
30
- hard: "Hard"
31
- hell: "HELL"
32
- no_hints: "You have no hints"
33
- game_process: "%{attempts} attempts and %{hints} hints left. Guess a secret code"
34
- secret: "The secret code was %{secret}"
35
- save: "Print 'save' if you want to save your result: "
36
- game_over: "Game Over"
37
- stats: "Player %{name} played with difficulty level %{difficulty} (%{att_total} attempts, %{hints_total} hints) and won with %{att_used} attempts and %{hints_used} hints used."
38
- no_stats: "Sorry, you have not any saves yet."
2
+ game:
3
+ greeting: "Welcome to codebreaker!\n"
4
+ goodbye: "Goodbye!\n"
5
+ rules: "GAME RULES\n
6
+ # Codebreaker is a logic game in which a code-breaker tries to break a secret code created by a code-maker. The\n codemaker, which will be played by the application we’re going to write, creates a secret code of four numbers between\n 1 and 6.\n
7
+ # The codebreaker gets some number of chances to break the code (depends on chosen difficulty). In each turn, the\n codebreaker makes a guess of 4 numbers. The codemaker then marks the guess with up to 4 signs - + or - or empty\n spaces.\n
8
+ # A + indicates an exact match: one of the numbers in the guess is the same as one of the numbers in the secret code\n and in the same position. For example:\n
9
+ Secret number - 1234\n
10
+ Input number - 6264\n
11
+ Number of pluses - 2 (second and fourth position)\n
12
+ # A - indicates a number match: one of the numbers in the guess is the same as one of the numbers in the secret code\n but in a different position. For example:\n
13
+ Secret number - 1234\n
14
+ Input number - 6462\n
15
+ Number of minuses - 2 (second and fourth position)\n
16
+ # An empty space indicates that there is not a current digit in a secret number.\n
17
+ # If codebreaker inputs the exact number as a secret number - codebreaker wins the game. If all attempts are spent -\n codebreaker loses.\n
18
+ # Codebreaker also has some number of hints(depends on chosen difficulty). If a user takes a hint - he receives back a\n
19
+ separate digit of the secret code.\n"
20
+ menu: "Choose one of next scenarios: 'start', 'rules', 'stats', 'exit'"
21
+ choose_difficulty: "Choose difficulty: easy, medium, hard, HELL"
22
+ choose_name: "Choose your name"
23
+ win: "Congratulations! You win!"
24
+ lose: "Sorry, you lose. Maybe another time."
25
+ wrong_difficulty: "There is no such difficulty. Please choose one from listed"
26
+ wrong_name: "Choosen name is invalid. Name must be between 3 and 20 characters.\nPlease choose another one"
27
+ wrong_process: "There is no such command or your number is invalid. You can try use hint or exit"
28
+ wrong_run: "You have passed unexpected command. Please choose one from listed commands"
29
+ easy: "Easy"
30
+ medium: "Medium"
31
+ hard: "Hard"
32
+ hell: "HELL"
33
+ no_hints: "You have no hints"
34
+ game_process: "%{attempts} attempts and %{hints} hints left. Guess a secret code"
35
+ secret: "The secret code was %{secret}"
36
+ save: "Print 'save' if you want to save your result: "
37
+ game_over: "Game Over"
38
+ stats: "Player %{name} played with difficulty level %{difficulty} (%{att_total} attempts, %{hints_total} hints) and won with %{att_used} attempts and %{hints_used} hints used."
39
+ no_stats: "Sorry, you have not any saves yet."
@@ -5,25 +5,25 @@ module CodebreakerCaptainjns
5
5
 
6
6
  attr_reader :att_total, :attempts, :difficulty, :hints_total, :hints, :name, :win, :secret
7
7
 
8
- def initialize(name:, difficulty:)
9
- @name = name
10
- @difficulty = difficulty
11
- @attempts = calc_attempts_and_hints(difficulty)[0]
12
- @hints = calc_attempts_and_hints(difficulty)[1]
8
+ def initialize(params)
9
+ @name = params['name']
10
+ @difficulty = params['difficulty']
11
+ @attempts = calc_attempts_and_hints(@difficulty)[0]
12
+ @hints = calc_attempts_and_hints(@difficulty)[1]
13
13
  @win = false
14
14
  @secret = make_number
15
15
  @unused_hints = @secret.chars
16
16
  end
17
-
17
+
18
18
  def check(number)
19
19
  @attempts -= 1
20
20
  result = check_numbers(@secret.chars, number.chars)
21
21
  @win = true if result == '++++'
22
22
  result
23
23
  end
24
-
24
+
25
25
  def use_hint
26
- return I18n.t(:no_hints) unless @hints.positive?
26
+ return I18n.t('game.no_hints') unless @hints.positive?
27
27
 
28
28
  @hints -= 1
29
29
  hint(@unused_hints)
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GameLogic
2
4
  include I18n
3
5
 
4
6
  DIFFICULTY_HASH = {
5
- I18n.t(:easy) => [15, 3],
6
- I18n.t(:medium) => [10, 2],
7
- I18n.t(:hard) => [5, 1],
8
- I18n.t(:hell) => [3, 0]
7
+ I18n.t('game.easy') => [15, 3],
8
+ I18n.t('game.medium') => [10, 2],
9
+ I18n.t('game.hard') => [5, 1],
10
+ I18n.t('game.hell') => [3, 0]
9
11
  }.freeze
10
12
 
11
13
  def make_number(chars = 4, numbers = 6)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CodebreakerCaptainjns
2
- VERSION = "0.2.1"
4
+ VERSION = '0.3.0'
3
5
  end
@@ -1,4 +1,6 @@
1
- require "codebreaker_captainjns/version"
1
+ # frozen_string_literal: true
2
+
3
+ require 'codebreaker_captainjns/version'
2
4
  require 'i18n'
3
5
  require_relative 'codebreaker_captainjns/config/i18n'
4
6
  require_relative 'codebreaker_captainjns/game_logic'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codebreaker_captainjns
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-08-08 00:00:00.000000000 Z
11
+ date: 2019-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -25,47 +25,47 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: i18n
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '1.6'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '1.6'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rspec
42
+ name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '3.0'
47
+ version: '10.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '3.0'
54
+ version: '10.0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: i18n
56
+ name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '1.6'
61
+ version: '3.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '1.6'
68
+ version: '3.0'
69
69
  description:
70
70
  email:
71
71
  - sereda9623@gmail.com