cinch_hangman 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cinch/plugins/hangman.rb +5 -5
- data/lib/cinch_hangman/version.rb +1 -1
- data/spec/hangman_spec.rb +23 -8
- metadata +8 -8
@@ -20,18 +20,18 @@ module Cinch::Plugins
|
|
20
20
|
def initialize(answer, max_guesses = 6)
|
21
21
|
@answer = answer
|
22
22
|
@max_guesses = max_guesses
|
23
|
-
@
|
23
|
+
@correct_chars = Set.new
|
24
24
|
@incorrect_guesses = []
|
25
25
|
end
|
26
26
|
def guess(guess)
|
27
27
|
if @answer.include?(guess)
|
28
|
-
@
|
28
|
+
@correct_chars.merge(guess.chars)
|
29
29
|
else
|
30
30
|
@incorrect_guesses << guess
|
31
31
|
end
|
32
32
|
end
|
33
33
|
def describe
|
34
|
-
if @
|
34
|
+
if @correct_chars.empty? && @incorrect_guesses.empty?
|
35
35
|
"(#{hint}) a new hangman riddle has started."
|
36
36
|
elsif won
|
37
37
|
"(#{hint}) that hangman riddle was solved, awesome!"
|
@@ -42,7 +42,7 @@ module Cinch::Plugins
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
def won
|
45
|
-
@
|
45
|
+
@correct_chars.superset?(Set.new(@answer.chars))
|
46
46
|
end
|
47
47
|
def lost
|
48
48
|
guesses_left == 0
|
@@ -51,7 +51,7 @@ module Cinch::Plugins
|
|
51
51
|
@max_guesses - @incorrect_guesses.size
|
52
52
|
end
|
53
53
|
def hint
|
54
|
-
@answer.chars.map { |char| @
|
54
|
+
@answer.chars.map { |char| @correct_chars.include?(char) ? char : "_" }.join(" ")
|
55
55
|
end
|
56
56
|
|
57
57
|
end
|
data/spec/hangman_spec.rb
CHANGED
@@ -14,15 +14,25 @@ describe Cinch::Plugins::Game do
|
|
14
14
|
subject.describe.should include 'new hangman'
|
15
15
|
end
|
16
16
|
describe 'guesses' do
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
describe 'correct' do
|
18
|
+
it 'when containing a single character in the answer' do
|
19
|
+
subject.guess("h")
|
20
|
+
subject.describe.should include '6 guesses'
|
21
|
+
end
|
22
22
|
end
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
describe 'incorrect' do
|
24
|
+
it 'when containing a single character not in the answer' do
|
25
|
+
subject.guess("x")
|
26
|
+
subject.describe.should include '5 guesses'
|
27
|
+
end
|
28
|
+
it 'when containing a word not in the answer' do
|
29
|
+
subject.guess("lol")
|
30
|
+
subject.describe.should include '5 guesses'
|
31
|
+
end
|
32
|
+
it 'when containing the correct answer in reverse' do
|
33
|
+
subject.guess("ho")
|
34
|
+
subject.describe.should include '5 guesses'
|
35
|
+
end
|
26
36
|
end
|
27
37
|
end
|
28
38
|
describe 'hints' do
|
@@ -50,6 +60,11 @@ describe Cinch::Plugins::Game do
|
|
50
60
|
subject.guess("oh")
|
51
61
|
subject.describe.should include 'awesome!'
|
52
62
|
end
|
63
|
+
it 'occurs no matter what order guesses are given' do
|
64
|
+
subject.guess("h")
|
65
|
+
subject.guess("o")
|
66
|
+
subject.describe.should include 'awesome!'
|
67
|
+
end
|
53
68
|
it 'should not be automatic for hassox' do
|
54
69
|
subject = Cinch::Plugins::Game.new("hassox")
|
55
70
|
subject.guess("s")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cinch_hangman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-09-
|
12
|
+
date: 2011-09-08 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cinch
|
16
|
-
requirement: &
|
16
|
+
requirement: &2153442480 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2153442480
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &2153441180 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2153441180
|
36
36
|
description:
|
37
37
|
email:
|
38
38
|
- shanonmcquay@gmail.com
|
@@ -62,7 +62,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
62
62
|
version: '0'
|
63
63
|
segments:
|
64
64
|
- 0
|
65
|
-
hash:
|
65
|
+
hash: 1370904378984459373
|
66
66
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
67
|
none: false
|
68
68
|
requirements:
|
@@ -71,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
71
|
version: '0'
|
72
72
|
segments:
|
73
73
|
- 0
|
74
|
-
hash:
|
74
|
+
hash: 1370904378984459373
|
75
75
|
requirements: []
|
76
76
|
rubyforge_project: cinch_hangman
|
77
77
|
rubygems_version: 1.8.6
|