codebreaker234 0.1.0 → 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 +4 -4
- data/lib/codebreaker234/game.rb +25 -10
- data/lib/codebreaker234/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 99296c1d34150f88b7ee85ed38cea9e85811f2c3
|
|
4
|
+
data.tar.gz: ed780aa2cc8ecbec7a115da5ea3b71a28e2dc7fc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 82ea1191e89fae6e1341a7d5b57dae706e7ffaba7d45859d73f505cc1f9ab072e623320dea74d0dd1c089aef4cec651f580c4232bd06c3188e61a8dea91e3435
|
|
7
|
+
data.tar.gz: 8510fed324151e97783de171e0bd1bc693b40753e0022e7927d397cdad6bb9d74752d7aaf177bc4ead45db927a87ca561499ee333b871f571eb71fbe70a91a45
|
data/lib/codebreaker234/game.rb
CHANGED
|
@@ -22,27 +22,42 @@ module Codebreaker234
|
|
|
22
22
|
|
|
23
23
|
def mark_user_guess(user_input)
|
|
24
24
|
answer = ""
|
|
25
|
-
tmp_code = ""
|
|
26
25
|
tmp_input = ""
|
|
26
|
+
tmp_code = ""
|
|
27
27
|
for i in 0...SECRET_CODE_LENGTH
|
|
28
28
|
if user_input[i] == @secret_code[i]
|
|
29
|
-
|
|
30
|
-
tmp_input << "+"
|
|
29
|
+
answer << "+"
|
|
31
30
|
else
|
|
32
31
|
tmp_input << user_input[i]
|
|
33
32
|
tmp_code << @secret_code[i]
|
|
34
33
|
end
|
|
35
34
|
end
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
35
|
+
if tmp_code.size > 0
|
|
36
|
+
for i in 0...tmp_code.size
|
|
37
|
+
if tmp_code.include? tmp_input[i]
|
|
38
|
+
answer << "-"
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
43
42
|
return answer
|
|
44
43
|
end
|
|
45
44
|
|
|
45
|
+
def analize(user_input)
|
|
46
|
+
marked_guess = mark_user_guess(user_input)
|
|
47
|
+
if user_input.match(/^[1-6]{4}$/)
|
|
48
|
+
user_guesses_and_answers << {user_input => marked_guess}
|
|
49
|
+
decrease_avaliable_turns
|
|
50
|
+
else
|
|
51
|
+
user_guesses_and_answers << {user_input => "Wrong guess. Pls enter exectly 4 numbers. Each from 1 to 6."}
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
if marked_guess == "++++"
|
|
55
|
+
game_status = "win"
|
|
56
|
+
elsif number_of_turns <= 0
|
|
57
|
+
game_status = "lose"
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
46
61
|
def hint
|
|
47
62
|
hint = "****"
|
|
48
63
|
hint[@hint_position] = @secret_code[@hint_position]
|