codeguessing 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2aa815c7d607d3b1c7a5f00d2312ac694dedeabd
4
- data.tar.gz: 00187427fe2182cea4d61b922d488212c1b32cbe
3
+ metadata.gz: 7ece0753557c94c9f27962f4be47bf9a65c87e07
4
+ data.tar.gz: 0f954cb55e92f23112bf842a425a0492f7e271be
5
5
  SHA512:
6
- metadata.gz: bc1463e1b945dd6e7946169202a7d44e8168c690a8b70f8d05084948a870de8c5be0a10dae6f114e7fb961e0197e1dc216aa4a916e5dba3010c99ab906a1d4b1
7
- data.tar.gz: 71191db403855ddc8de890760bcb088357b3d1ee7a90973e30b7762550f21e3b79bd2bd86d271f12cc30e601bd411ea4fa3a84e6b75f1ebf1cd0bdad448b7ab9
6
+ metadata.gz: 806954eb7f9db130340e8f878179afb0bd9a09dfde1a051dfe68d14e90f9816b253ddae63b2e43194ec38c6a438cc208e510450aae8c3edd0415e6e2dd507c3d
7
+ data.tar.gz: 7dac3cc93fb7fcad15a6a4d74b01a0479f57339e82df3a6b3db7c54649819075e2945ea98addb26408ab077e85ebe7bdc94be7f849211cf3233be41c16613730
@@ -81,6 +81,7 @@ module Codeguessing
81
81
 
82
82
  def loose
83
83
  puts 'You loose!'
84
+ puts "Secret code was #{@game.secret_code}"
84
85
  again?
85
86
  end
86
87
 
@@ -16,15 +16,19 @@ module Codeguessing
16
16
  def guess(code)
17
17
  loose unless check?(use_attempt)
18
18
  hash = {}
19
- res = ''
20
- code.each_char.with_index do |char, i|
19
+ res = ''
20
+ remaine_chars = code
21
+ right_chars = []
22
+ secret_code.each_char.with_index do |char, i|
21
23
  case
22
- when char == secret_code[i]
23
- res += '+'
24
- when secret_code.count(char) == 1 &&
25
- code.count(char) == 1
26
- hash[char] = '-'
27
- end
24
+ when code[i] == char
25
+ res += '+'
26
+ right_chars << char
27
+ remaine_chars[i] = '*'
28
+ hash.delete(char) if right_chars.include?(char)
29
+ when remaine_chars.include?(char)
30
+ hash[char] = '-'
31
+ end
28
32
  end
29
33
  res += hash.values.join('')
30
34
  win if res == '++++'
@@ -19,3 +19,7 @@
19
19
  :attempts: 4
20
20
  :hint_count: 0
21
21
  :name: Ivan
22
+ - :secret_code: '3234'
23
+ :attempts: 3
24
+ :hint_count: 0
25
+ :name: Ivan
@@ -1,3 +1,3 @@
1
1
  module Codeguessing
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codeguessing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - bezrukavyi