codebracker_simb 0.1.9 → 0.2.2

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: 3c91419e479ec42e9ca57ad655459e2d50f9558b45b1246711cdf5f3bfe9504d
4
- data.tar.gz: fa921e3507877635c8b66c233bc6c23efa71c8139ac69345915e528642d99237
3
+ metadata.gz: 1fc86e4117bd03864f4927c7ebcbb9974b16f8d4c88429c0ddbdef0bb1865749
4
+ data.tar.gz: 76824c21bc9c6391da63d9ea0b1cf44779fec756c10ec141cf299f73978986d9
5
5
  SHA512:
6
- metadata.gz: 45a3ec7a54873a90732d51e23f1fcf8e4adf0d9ed82e24b9fed8ebf1c7328de38a7faf45ba07803588cbf261d7ed70e6adfd194ae992e4be9b0e05967449271b
7
- data.tar.gz: 832a221b19079ebce35e426f8cfc4bc2468fde165c4017d135ef507fac3fa753c8545dbb37b3efbe5c31d1d24ab3841ea676fb3e87fb5f1425be19c3dce2e687
6
+ metadata.gz: bd06ef36a83aa8402b7280161cf3c2f2c9b561d7f0aee2742a49a0903f955e3a2e88d171465be849185eb16f11eae2940dd0ab2c74830498d2cfd8920f19c09c
7
+ data.tar.gz: 57e08886f41e8cadde7ff9dd11607ee293c98e7f6cf3a9c704a69a99769525d392c56538a8ab7c6a4626a9261edd5360595fc581ea1351ebe709f756209f956d
@@ -0,0 +1,13 @@
1
+ module CodebrackerSimb
2
+ class CodeValidator
3
+
4
+ def self.included(base)
5
+ base.extend(CodeValidator)
6
+ end
7
+
8
+ def valid_code?(code)
9
+ code =~ /^[1-6]{4}$/
10
+ end
11
+
12
+ end
13
+ end
@@ -8,31 +8,31 @@ module CodebrackerSimb
8
8
  class Game
9
9
  attr_reader :code
10
10
  attr_reader :attempts
11
+ attr_reader :player
11
12
  attr_accessor :answer
12
13
 
14
+ include ::CodebrackerSimb::CodeValidator
15
+ include ::CodebrackerSimb::NameValidator
16
+
13
17
  ERR_UNEXPECTED_COMPLEXITY = 'complexity could be easy, medium or hard'
14
18
  IS_OVER = 'Game is over, you lose'
15
19
  GREETING = 'Hello! Welcome to CodeBracker Game! Have fun!'
16
20
  CONGRATULATIONS = 'Congratulations! You broked a code, master!'
17
21
 
18
- def initialize(complexity)
19
- @attempts = set_attempts(complexity)
22
+ def initialize(complexity, player)
23
+ @attempts = set_options(complexity)[:attempts]
24
+ @hints = set_options(complexity)[:hints]
25
+ @player = player
20
26
  end
21
27
 
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
28
  def input_answer(input)
33
29
  @answer = Code.new(input)
34
30
  end
35
31
 
32
+ def check_answer
33
+ Checker.new(code, answer).compare
34
+ end
35
+
36
36
  def define_code
37
37
  @code = Array.new(4) { rand(1..6) }
38
38
  end
@@ -47,15 +47,17 @@ module CodebrackerSimb
47
47
  message = "#{@attempts} left"
48
48
  end
49
49
  end
50
+
51
+ private
50
52
 
51
- def set_attempts(complexity)
53
+ def set_options(complexity)
52
54
  case complexity
53
55
  when 'easy'
54
- 14
56
+ {attempts: 14, hints: 2}
55
57
  when 'medium'
56
- 10
58
+ {attempts: 10, hints: 1}
57
59
  when 'hard'
58
- 5
60
+ {attempts: 5, hints: 1}
59
61
  else
60
62
  raise ERR_UNEXPECTED_COMPLEXITY
61
63
  end
@@ -0,0 +1,13 @@
1
+ module CodebrackerSimb
2
+ class NameValidator
3
+
4
+ def self.included(base)
5
+ base.extend(NameValidator)
6
+ end
7
+
8
+ def valid_name?(name)
9
+ name.is_a?(String) && name.length > 3 && name.length < 20
10
+ end
11
+
12
+ end
13
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CodebrackerSimb
4
- VERSION = "0.1.9"
4
+ VERSION = "0.2.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codebracker_simb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - max
@@ -36,7 +36,9 @@ files:
36
36
  - lib/codebracker_simb.rb
37
37
  - lib/codebracker_simb/checker.rb
38
38
  - lib/codebracker_simb/code.rb
39
+ - lib/codebracker_simb/code_validator.rb
39
40
  - lib/codebracker_simb/game.rb
41
+ - lib/codebracker_simb/name_validator.rb
40
42
  - lib/codebracker_simb/version.rb
41
43
  homepage:
42
44
  licenses: