codebracker_simb 0.2.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fdaa035c89a4e37517274a684ab53be0bf78784b6720f12483be57c004ae3348
4
- data.tar.gz: 2728cb48ae9a344d4de629fe3ea24a5ce8b39e35164266513cfe0a883bda7377
3
+ metadata.gz: 41d2ae7582e4269dd938a13388bde20ae9a730d253f1f2840fa1a640a51fbfb1
4
+ data.tar.gz: 2eb8ae53ad3e1c7c96e413f048f3af593d6571fdcc2a75bec5ff465ef7187255
5
5
  SHA512:
6
- metadata.gz: 0154f9d73aa24bd7847500d2059725d20ee989a748b19db4c59a0d52899dda0c0463dc55600c36cb9e09aa1077d795a56209eb4809355b6fe2ec67da0241c0f9
7
- data.tar.gz: 4696e2fcfe0169f7de36cbdffdd8c699c729cf3b1d6c2a8294a6eb0cbe5657eddfb6701efe24136ac4782bed3afbd5a51f0977630174c6b45e422297427d28d3
6
+ metadata.gz: 0a67a32536b83cd6bf595fc3cf3a110d53439f208975777a552e5cea68a1afba782855dd8ca3c5854943747c13ccab1c1d6f2879a609e09d170c979e5a8f8986
7
+ data.tar.gz: dcca1b7a53e9ce24bfc10f05049cd04b91b2ad62f5ae6281d14f76065891d4ba54f722db98a3adf4a63d533dacca44a9e3d11e63010e8cb118c32077153f73ba
@@ -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
@@ -11,30 +11,28 @@ module CodebrackerSimb
11
11
  attr_reader :player
12
12
  attr_accessor :answer
13
13
 
14
+ include Codebracker::CodeValidator
15
+ include Codebracker::NameValidator
16
+
14
17
  ERR_UNEXPECTED_COMPLEXITY = 'complexity could be easy, medium or hard'
15
18
  IS_OVER = 'Game is over, you lose'
16
19
  GREETING = 'Hello! Welcome to CodeBracker Game! Have fun!'
17
20
  CONGRATULATIONS = 'Congratulations! You broked a code, master!'
18
21
 
19
22
  def initialize(complexity, player)
20
- @attempts = set_attempts(complexity)
23
+ @attempts = set_options(complexity)[:attempts]
24
+ @hints = set_options(complexity)[:hints]
21
25
  @player = player
22
26
  end
23
27
 
24
- def play
25
- define_code
26
- loop do
27
- input_answer
28
- result = Checker.new(code, answer).compare
29
- refresh_attempts_quantity
30
- break if win? || @attempts == 0
31
- end
32
- end
33
-
34
28
  def input_answer(input)
35
29
  @answer = Code.new(input)
36
30
  end
37
31
 
32
+ def check_answer
33
+ Checker.new(code, answer).compare
34
+ end
35
+
38
36
  def define_code
39
37
  @code = Array.new(4) { rand(1..6) }
40
38
  end
@@ -49,15 +47,17 @@ module CodebrackerSimb
49
47
  message = "#{@attempts} left"
50
48
  end
51
49
  end
50
+
51
+ private
52
52
 
53
- def set_attempts(complexity)
53
+ def set_options(complexity)
54
54
  case complexity
55
55
  when 'easy'
56
- 14
56
+ {attempts: 14, hints: 2}
57
57
  when 'medium'
58
- 10
58
+ {attempts: 10, hints: 1}
59
59
  when 'hard'
60
- 5
60
+ {attempts: 5, hints: 1}
61
61
  else
62
62
  raise ERR_UNEXPECTED_COMPLEXITY
63
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.2.0"
4
+ VERSION = "0.2.1"
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.2.0
4
+ version: 0.2.1
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: