codebreaker_captainjns 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +4 -2
- data/Gemfile.lock +1 -1
- data/Rakefile +5 -3
- data/bin/console +4 -3
- data/codebreaker_captainjns.gemspec +15 -14
- data/lib/codebreaker_captainjns/config/i18n.rb +2 -0
- data/lib/codebreaker_captainjns/config/locales/en.yml +38 -37
- data/lib/codebreaker_captainjns/game.rb +8 -8
- data/lib/codebreaker_captainjns/game_logic.rb +6 -4
- data/lib/codebreaker_captainjns/version.rb +3 -1
- data/lib/codebreaker_captainjns.rb +3 -1
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b2e66d91a31a575dde95e0c1592dfec1808fcdf1bd58e19e4c5d5cfdde1ad2c
|
4
|
+
data.tar.gz: 1bedaa8ce6ce756825a3abe6963348e9fb68ef6e2406e5a824bc826b4b479473
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da38978d24f8e1396d130abcb7a36ee600ee680f807cc3a0a650161d6a5877ae8cca47598dfe682e9e3eb88d678877015e8fec8897502ea5d9ec43dccc43fd73
|
7
|
+
data.tar.gz: 461d939c68bc7ff294a94f5d4486c217e89e6957369ecf0fe3a67e775855ca01ff666d9bca2def52305ac1615b79a95bac402bb680d3a582f4b3e86878499b9d
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require
|
4
|
-
require
|
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
|
14
|
+
require 'irb'
|
14
15
|
IRB.start(__FILE__)
|
@@ -1,18 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
|
-
lib = File.expand_path(
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
5
|
+
require 'codebreaker_captainjns/version'
|
5
6
|
|
6
7
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
8
|
+
spec.name = 'codebreaker_captainjns'
|
8
9
|
spec.version = CodebreakerCaptainjns::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
10
|
+
spec.authors = ['Jason']
|
11
|
+
spec.email = ['sereda9623@gmail.com']
|
11
12
|
|
12
|
-
spec.summary =
|
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 =
|
15
|
-
spec.license =
|
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(
|
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 =
|
36
|
+
spec.bindir = 'exe'
|
36
37
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
37
|
-
spec.require_paths = [
|
38
|
+
spec.require_paths = ['lib']
|
38
39
|
|
39
|
-
spec.add_development_dependency
|
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,38 +1,39 @@
|
|
1
1
|
en:
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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(
|
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(
|
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(
|
6
|
-
I18n.t(
|
7
|
-
I18n.t(
|
8
|
-
I18n.t(
|
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)
|
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.
|
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-
|
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:
|
28
|
+
name: i18n
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
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: '
|
40
|
+
version: '1.6'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
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: '
|
54
|
+
version: '10.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
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: '
|
68
|
+
version: '3.0'
|
69
69
|
description:
|
70
70
|
email:
|
71
71
|
- sereda9623@gmail.com
|