cinch_hangman 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +5 -0
- data/Rakefile +1 -0
- data/cinch_hangman.gemspec +22 -0
- data/lib/cinch/plugins/hangman.rb +58 -0
- data/lib/cinch_hangman/version.rb +3 -0
- data/lib/cinch_hangman.rb +2 -0
- data/spec/hangman_spec.rb +68 -0
- metadata +82 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "cinch_hangman/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "cinch_hangman"
|
7
|
+
s.version = CinchHangman::VERSION
|
8
|
+
s.authors = ["Shanon McQuay"]
|
9
|
+
s.email = ["shanonmcquay@gmail.com"]
|
10
|
+
s.homepage = "https://github.com/compactcode/cinch_hangman"
|
11
|
+
s.summary = %q{Let your IRC bot conduct a game of hangman.}
|
12
|
+
|
13
|
+
s.rubyforge_project = "cinch_hangman"
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
s.add_dependency "cinch"
|
21
|
+
s.add_development_dependency "rspec"
|
22
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Cinch::Plugins
|
2
|
+
class Hangman
|
3
|
+
include Cinch::Plugin
|
4
|
+
match /hang guess (.*)/i, :method => :guess
|
5
|
+
match /hang new (.*) (.*)/i, :method => :new_game
|
6
|
+
match /hang status/i, :method => :status
|
7
|
+
def new_game(m, channel, answer)
|
8
|
+
@game = Game.new(answer)
|
9
|
+
Channel(channel).send(@game.describe)
|
10
|
+
end
|
11
|
+
def guess(m, guess)
|
12
|
+
@game.guess(guess)
|
13
|
+
m.reply @game.describe
|
14
|
+
end
|
15
|
+
def status(m)
|
16
|
+
m.reply @game.describe
|
17
|
+
end
|
18
|
+
end
|
19
|
+
class Game
|
20
|
+
def initialize(answer, max_guesses = 6)
|
21
|
+
@answer = answer
|
22
|
+
@max_guesses = max_guesses
|
23
|
+
@correct_guesses = []
|
24
|
+
@incorrect_guesses = []
|
25
|
+
end
|
26
|
+
def guess(guess)
|
27
|
+
if @answer.include?(guess)
|
28
|
+
@correct_guesses << guess
|
29
|
+
else
|
30
|
+
@incorrect_guesses << guess
|
31
|
+
end
|
32
|
+
end
|
33
|
+
def describe
|
34
|
+
if @correct_guesses.empty? && @incorrect_guesses.empty?
|
35
|
+
"(#{hint}) a new hangman riddle has started."
|
36
|
+
elsif won
|
37
|
+
"(#{hint}) that hangman riddle was solved, awesome!"
|
38
|
+
elsif lost
|
39
|
+
"(#{hint}) that hangman riddle was just too difficult, that sucks!"
|
40
|
+
else
|
41
|
+
"(#{hint}) #{guesses_left} guesses left on the current hangman riddle."
|
42
|
+
end
|
43
|
+
end
|
44
|
+
def won
|
45
|
+
@correct_guesses.join.include?(@answer)
|
46
|
+
end
|
47
|
+
def lost
|
48
|
+
guesses_left == 0
|
49
|
+
end
|
50
|
+
def guesses_left
|
51
|
+
@max_guesses - @incorrect_guesses.size
|
52
|
+
end
|
53
|
+
def hint
|
54
|
+
@answer.chars.map { |char| @correct_guesses.join.include?(char) ? char : "_" }.join(" ")
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), '..')
|
4
|
+
|
5
|
+
require 'cinch'
|
6
|
+
require 'cinch_hangman'
|
7
|
+
|
8
|
+
describe Cinch::Plugins::Game do
|
9
|
+
subject do
|
10
|
+
Cinch::Plugins::Game.new("oh")
|
11
|
+
end
|
12
|
+
describe 'game' do
|
13
|
+
it 'should have a start' do
|
14
|
+
subject.describe.should include 'new hangman'
|
15
|
+
end
|
16
|
+
describe 'guesses' do
|
17
|
+
it 'reduce after an incorrect guess' do
|
18
|
+
subject.guess("x")
|
19
|
+
subject.describe.should include '5 guesses'
|
20
|
+
subject.guess("lol")
|
21
|
+
subject.describe.should include '4 guesses'
|
22
|
+
end
|
23
|
+
it 'do not reduce after a correct guess' do
|
24
|
+
subject.guess("h")
|
25
|
+
subject.describe.should include '6 guesses'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
describe 'hints' do
|
29
|
+
it 'show the number of letters in the answer' do
|
30
|
+
subject.guess("x")
|
31
|
+
subject.describe.should include '_ _'
|
32
|
+
end
|
33
|
+
it 'show letters that have been guessed correctly' do
|
34
|
+
subject.guess("h")
|
35
|
+
subject.describe.should include '_ h'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
describe 'winning' do
|
39
|
+
it 'occurs when the answer is guessed using individual characters' do
|
40
|
+
subject.guess("o")
|
41
|
+
subject.guess("h")
|
42
|
+
subject.describe.should include 'awesome!'
|
43
|
+
end
|
44
|
+
it 'occurs when the answer is guessed in one go' do
|
45
|
+
subject.guess("oh")
|
46
|
+
subject.describe.should include 'awesome!'
|
47
|
+
end
|
48
|
+
it 'occurs when the answer is given with a mixture of approaches' do
|
49
|
+
subject.guess("o")
|
50
|
+
subject.guess("oh")
|
51
|
+
subject.describe.should include 'awesome!'
|
52
|
+
end
|
53
|
+
it 'should not be automatic for hassox' do
|
54
|
+
subject = Cinch::Plugins::Game.new("hassox")
|
55
|
+
subject.guess("s")
|
56
|
+
subject.describe.should_not include 'awesome!'
|
57
|
+
end
|
58
|
+
end
|
59
|
+
describe 'losing' do
|
60
|
+
it 'occurs when all the guesses run out' do
|
61
|
+
6.times do
|
62
|
+
subject.guess("z")
|
63
|
+
end
|
64
|
+
subject.describe.should include 'sucks!'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cinch_hangman
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Shanon McQuay
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-09-07 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: cinch
|
16
|
+
requirement: &2153646940 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2153646940
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &2153644200 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2153644200
|
36
|
+
description:
|
37
|
+
email:
|
38
|
+
- shanonmcquay@gmail.com
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- .gitignore
|
44
|
+
- Gemfile
|
45
|
+
- Rakefile
|
46
|
+
- cinch_hangman.gemspec
|
47
|
+
- lib/cinch/plugins/hangman.rb
|
48
|
+
- lib/cinch_hangman.rb
|
49
|
+
- lib/cinch_hangman/version.rb
|
50
|
+
- spec/hangman_spec.rb
|
51
|
+
homepage: https://github.com/compactcode/cinch_hangman
|
52
|
+
licenses: []
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
hash: 1342828520626394308
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
hash: 1342828520626394308
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project: cinch_hangman
|
77
|
+
rubygems_version: 1.8.6
|
78
|
+
signing_key:
|
79
|
+
specification_version: 3
|
80
|
+
summary: Let your IRC bot conduct a game of hangman.
|
81
|
+
test_files:
|
82
|
+
- spec/hangman_spec.rb
|