codebracker_simb 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 +7 -0
- data/codebracker_simb.gemspec +25 -0
- data/lib/codebracker_simb/checker.rb +49 -0
- data/lib/codebracker_simb/code.rb +11 -0
- data/lib/codebracker_simb/game.rb +66 -0
- data/lib/codebracker_simb/version.rb +5 -0
- data/lib/codebracker_simb.rb +8 -0
- metadata +50 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7fe4a40e22b03e2c3668530faf573991a5d07de2910a42035f51d3c67d1645d0
|
4
|
+
data.tar.gz: 631dd163fabac68706abf63fa7214a001bdf9625e96a48864e8fa53384bb1788
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fba5f6280b938ecb3a190b6d85a70f3e6eaab4b78e8e7999227192a6cfc9077bbdf5377c563bba292e283f3c6ae3025fec60fc6536f7e2ee7e31f8d16a827e8b
|
7
|
+
data.tar.gz: 638a3e900b8ca3c00dc5bce391c0ef0d45ca8107099eeb69126cfd3ca3e09fe5cdeacd4eff26c2f09997138a5d96abbce7e7f8653fab9d42a2165816fc21bbbd
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/codebracker_simb/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "codebracker_simb"
|
7
|
+
spec.version = CodebrackerSimb::VERSION
|
8
|
+
spec.authors = ["max"]
|
9
|
+
spec.email = ["laterty@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Write a short summary, because RubyGems requires one."
|
12
|
+
spec.description = "Write a longer description or delete this line."
|
13
|
+
spec.license = "MIT"
|
14
|
+
spec.required_ruby_version = ">= 2.6.0"
|
15
|
+
|
16
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
17
|
+
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
+
spec.files = Dir['README.md', 'LICENSE', 'lib/**/*.rb', 'lib/**/*.rake', 'Gemfile', 'Rakefile', 'codebracker_simb.gemspec', '.github/*.md', 'CHANGELOG.md']
|
21
|
+
spec.bindir = "exe"
|
22
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CodebrackerSimb
|
4
|
+
class Checker < Array
|
5
|
+
def initialize(code, ans)
|
6
|
+
@ans = ans
|
7
|
+
@code = code
|
8
|
+
@columns_with_plus = []
|
9
|
+
super([[nil, nil, nil, nil], [nil, nil, nil, nil], [nil, nil, nil, nil], [nil, nil, nil, nil]])
|
10
|
+
end
|
11
|
+
|
12
|
+
def compare
|
13
|
+
fill
|
14
|
+
output
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def fill
|
20
|
+
fill_with_plus
|
21
|
+
fill_with_minus
|
22
|
+
end
|
23
|
+
|
24
|
+
def output
|
25
|
+
output = []
|
26
|
+
each do |line|
|
27
|
+
output << '+' if line.include?(:plus)
|
28
|
+
output << '-' if line.include?(:minus) && !line.include?(:plus)
|
29
|
+
end
|
30
|
+
output.sort.join('')
|
31
|
+
end
|
32
|
+
def fill_with_plus
|
33
|
+
each_with_index do |line, i|
|
34
|
+
if @code[i] == @ans[i]
|
35
|
+
line[i] = :plus
|
36
|
+
@columns_with_plus << i
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def fill_with_minus
|
42
|
+
each_with_index do |line, i|
|
43
|
+
line.each_with_index do |_el, j|
|
44
|
+
line[j] = :minus if @code[i] == @ans[j] && !line[j] && !@columns_with_plus.include?(j)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './code'
|
4
|
+
require_relative './checker'
|
5
|
+
|
6
|
+
module CodebrackerSimb
|
7
|
+
# game cl
|
8
|
+
class Game
|
9
|
+
attr_reader :code
|
10
|
+
attr_accessor :answer
|
11
|
+
|
12
|
+
ERR_UNEXPECTED_COMPLEXITY = 'complexity could be easy, medium or hard'
|
13
|
+
IS_OVER = 'Game is over, you lose'
|
14
|
+
GREETING = 'Hello! Welcome to CodeBracker Game! Have fun!'
|
15
|
+
CONGRATULATIONS = 'Congratulations! You broked a code, master!'
|
16
|
+
|
17
|
+
def initialize(complexity, name)
|
18
|
+
@attempts = attempts(complexity)
|
19
|
+
@name = name
|
20
|
+
end
|
21
|
+
|
22
|
+
def play
|
23
|
+
define_code
|
24
|
+
loop do
|
25
|
+
input_answer
|
26
|
+
result = Checker.new(code, answer).compare
|
27
|
+
refresh_attempts_quantity
|
28
|
+
break if win? || @attempts == 0
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def input_answer(input)
|
35
|
+
@answer = Code.new(input)
|
36
|
+
end
|
37
|
+
|
38
|
+
def define_code
|
39
|
+
@code = Array.new(4) { rand(1..6) }
|
40
|
+
end
|
41
|
+
|
42
|
+
def win?(result)
|
43
|
+
result == '++++'
|
44
|
+
end
|
45
|
+
|
46
|
+
def refresh_attempts_quantity
|
47
|
+
if @attempts > 0
|
48
|
+
@attempts -= 1
|
49
|
+
message = "#{@attempts} left"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def attempts(complexity)
|
54
|
+
case complexity
|
55
|
+
when 'easy'
|
56
|
+
14
|
57
|
+
when 'medium'
|
58
|
+
10
|
59
|
+
when 'hard'
|
60
|
+
5
|
61
|
+
else
|
62
|
+
raise ERR_UNEXPECTED_COMPLEXITY
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
metadata
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: codebracker_simb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- max
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-08-26 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Write a longer description or delete this line.
|
14
|
+
email:
|
15
|
+
- laterty@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- codebracker_simb.gemspec
|
21
|
+
- lib/codebracker_simb.rb
|
22
|
+
- lib/codebracker_simb/checker.rb
|
23
|
+
- lib/codebracker_simb/code.rb
|
24
|
+
- lib/codebracker_simb/game.rb
|
25
|
+
- lib/codebracker_simb/version.rb
|
26
|
+
homepage:
|
27
|
+
licenses:
|
28
|
+
- MIT
|
29
|
+
metadata:
|
30
|
+
allowed_push_host: https://rubygems.org
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 2.6.0
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
requirements: []
|
46
|
+
rubygems_version: 3.2.3
|
47
|
+
signing_key:
|
48
|
+
specification_version: 4
|
49
|
+
summary: Write a short summary, because RubyGems requires one.
|
50
|
+
test_files: []
|