codeguessing 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/codeguessing/game.rb +6 -4
- data/lib/codeguessing/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8bd4ea46cffddc9ac2c2b8f477b10e0b3954f77e
|
4
|
+
data.tar.gz: 78c4704c19a987743c9ef6e425c8dd59abf07010
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33cdfbbf867d5a0b03a714aee3c2336ebd810db0db61cf081f8100dbe0722851d3e13ddabd3b6b41dddff9dce0ee1d47832758cb44af6256a02c5b35caf1df11
|
7
|
+
data.tar.gz: fb09f6de2f4a84390614d962822c1eb19b0ce0bf04082e44e70becfa12b83044c52ada50f54cc9cff7b4db8f715c2e49a24bae9c9e44793c0b5c766ab82632ea
|
data/lib/codeguessing/game.rb
CHANGED
@@ -4,6 +4,7 @@ module Codeguessing
|
|
4
4
|
|
5
5
|
MAX_HINT = 2
|
6
6
|
MAX_ATTEMPTS = 5
|
7
|
+
MAX_SIZE = 4
|
7
8
|
|
8
9
|
def initialize(opt = {})
|
9
10
|
@secret_code = opt[:secret_code] || random
|
@@ -15,6 +16,7 @@ module Codeguessing
|
|
15
16
|
|
16
17
|
def guess(code)
|
17
18
|
loose unless check?(use_attempt)
|
19
|
+
return false unless valid?(code)
|
18
20
|
hash = {}
|
19
21
|
res = ''
|
20
22
|
remaine_chars = code
|
@@ -31,13 +33,13 @@ module Codeguessing
|
|
31
33
|
end
|
32
34
|
end
|
33
35
|
res += hash.values.join('')
|
34
|
-
win if res == '
|
36
|
+
win if res == '+' * MAX_SIZE
|
35
37
|
@answer = res
|
36
38
|
end
|
37
39
|
|
38
40
|
def hint
|
39
41
|
res = ''
|
40
|
-
need_index = rand(0...
|
42
|
+
need_index = rand(0...MAX_SIZE)
|
41
43
|
secret_code.each_char.with_index do |char, index|
|
42
44
|
if index == need_index
|
43
45
|
res += char
|
@@ -69,7 +71,7 @@ module Codeguessing
|
|
69
71
|
end
|
70
72
|
|
71
73
|
def valid?(code)
|
72
|
-
return true if code =~ /^[1-6]{
|
74
|
+
return true if code =~ /^[1-6]{#{MAX_SIZE}}$/s
|
73
75
|
false
|
74
76
|
end
|
75
77
|
|
@@ -96,7 +98,7 @@ module Codeguessing
|
|
96
98
|
|
97
99
|
def random
|
98
100
|
code = ''
|
99
|
-
|
101
|
+
MAX_SIZE.times { code += rand(1..6).to_s }
|
100
102
|
code
|
101
103
|
end
|
102
104
|
|
data/lib/codeguessing/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codeguessing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bezrukavyi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|