rubinstein 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Kevin W. Gisi
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Manifest ADDED
@@ -0,0 +1,21 @@
1
+ LICENSE
2
+ README.rdoc
3
+ Rakefile
4
+ VERSION
5
+ bin/rubinstein
6
+ example.rb
7
+ features/support/aruba_interactive.rb
8
+ features/support/env.rb
9
+ features/usage.feature
10
+ lib/rubinstein.rb
11
+ lib/rubinstein/actions.rb
12
+ lib/rubinstein/actions/movement.rb
13
+ lib/rubinstein/game.rb
14
+ lib/rubinstein/location.rb
15
+ lib/rubinstein/player.rb
16
+ lib/rubinstein/runner.rb
17
+ lib/rubinstein/world.rb
18
+ simple.rb
19
+ spec/spec.opts
20
+ spec/spec_helper.rb
21
+ Manifest
data/README.rdoc ADDED
@@ -0,0 +1,20 @@
1
+ = Rubinstein
2
+
3
+ Rubinstein is a text-adventure game engine written in Ruby
4
+
5
+ == Installation and Usage
6
+
7
+ In order to use Rubinstein, simply install the gem:
8
+
9
+ gem install rubinstein
10
+
11
+ Then to run a Rubinstein game, just run:
12
+
13
+ rubinstein my_game.rb
14
+
15
+ == Coming Soon
16
+
17
+ This is a very new project - detailed stuff coming soon.
18
+
19
+ == Copyright
20
+ Copyright (c) 2010 Kevin W. Gisi. Released under the MIT License
data/Rakefile ADDED
@@ -0,0 +1,41 @@
1
+ require 'echoe'
2
+ require 'rake/rdoctask'
3
+ require 'cucumber/rake/task'
4
+ require 'spec/rake/spectask'
5
+
6
+ Echoe.new "rubinstein", File.read("VERSION").chomp do |m|
7
+ m.author = "Kevin W. Gisi"
8
+ m.email = "kevin@kevingisi.com"
9
+ m.summary = "Ruby text-adventure game engine"
10
+ m.url = "http://gisikw.github.com/my"
11
+ m.development_dependencies << "cucumber >=0.7.2"
12
+ m.development_dependencies << "aruba >=0.1.9"
13
+ m.development_dependencies << "rspec >=1.3.0"
14
+ end
15
+
16
+ Spec::Rake::SpecTask.new(:spec) do |spec|
17
+ spec.libs << 'lib' << 'spec'
18
+ spec.spec_files = FileList['spec/**/*_spec.rb']
19
+ end
20
+
21
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
22
+ spec.libs << 'lib' << 'spec'
23
+ spec.spec_files = FileList['spec/**/*_spec.rb']
24
+ spec.rcov = true
25
+ spec.rcov_opts = ["-T"]
26
+ end
27
+
28
+ Cucumber::Rake::Task.new do |t|
29
+ t.cucumber_opts = %w{--format pretty}
30
+ end
31
+
32
+ Rake::RDocTask.new do |rdoc|
33
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
34
+ rdoc.rdoc_dir = 'rdoc'
35
+ rdoc.title = "Rubinstein #{version}"
36
+ rdoc.main = 'README.rdoc'
37
+ rdoc.rdoc_files.include('README.rdoc')
38
+ rdoc.rdoc_files.include('lib/**/*.rb')
39
+ end
40
+
41
+ task :default => :spec
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/bin/rubinstein ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.join(File.dirname(__FILE__),'..','lib','rubinstein.rb')
4
+
5
+ Rubinstein::Game.run(Rubinstein.class_eval(File.read(ARGV[0])))
data/example.rb ADDED
@@ -0,0 +1,22 @@
1
+ World.new("My First Text Adventure") do
2
+
3
+
4
+ location "hallway" do
5
+ description "A dark and quiet hallway"
6
+ north "kitchen"
7
+ end
8
+
9
+ location "kitchen" do
10
+ description "An abandoned kitchen"
11
+ north "hall"
12
+ south "hallway"
13
+ end
14
+
15
+ location "hall" do
16
+ description "A banquet hall...strangely deserted"
17
+ south "kitchen"
18
+ end
19
+
20
+ start "hallway"
21
+
22
+ end
@@ -0,0 +1,42 @@
1
+ require 'open3'
2
+
3
+ Before '@aruba_interactive' do
4
+ @stdout_stream = nil
5
+ @stderr_stream = nil
6
+ @stdout = ""
7
+ @stdin = ""
8
+
9
+ @stdout_listener = Thread.new do
10
+ Thread.stop
11
+ loop do
12
+ @stdout << @stdout_stream.readpartial(1)
13
+ end
14
+ end
15
+
16
+ @stderr_listener = Thread.new do
17
+ Thread.stop
18
+ loop do
19
+ @stderr << @stderr_stream.readpartial(1)
20
+ end
21
+ end
22
+ end
23
+
24
+ When /^I run "([^\"]*)" interactively$/ do |arg1|
25
+ old_dir = Dir.pwd
26
+ Dir.chdir("tmp/aruba") unless Dir.pwd.split('/')[-1] == "aruba"
27
+ @stdin_stream, @stdout_stream, @stderr_stream = Open3.popen3(arg1)
28
+ Dir.chdir(old_dir)
29
+ sleep 1
30
+ @stdout_listener.run
31
+ @stderr_listener.run
32
+ end
33
+
34
+ When /^I type "([^\"]*)"$/ do |arg1|
35
+ @stdin_stream.puts arg1
36
+ sleep 0.5
37
+ end
38
+
39
+ Then /^the program should prompt "([^\"]*)"$/ do |arg1|
40
+ sleep 0.5
41
+ @stdout.should include(arg1)
42
+ end
@@ -0,0 +1,9 @@
1
+ $:.unshift(File.dirname(__FILE__)+'/../../lib')
2
+ require 'aruba'
3
+ require 'rubinstein'
4
+
5
+ begin
6
+ require 'rspec/expectations'
7
+ rescue LoadError
8
+ require 'spec/expectations'
9
+ end
@@ -0,0 +1,9 @@
1
+ Feature: Help
2
+ As a user of the Rubinstein gem
3
+ I want to view the usage information
4
+ So I can use the gem effectively
5
+
6
+ Scenario: Viewing the usage information implicitly
7
+ When I run "../../bin/rubinstein"
8
+ Then I should see "Rubinstein"
9
+ And I should see "USAGE: rubinstein my_game.rb"
@@ -0,0 +1,20 @@
1
+ module Rubinstein
2
+ module Actions
3
+ module Movement
4
+
5
+ def walk(*args)
6
+ args.flatten!
7
+ if !args[0]
8
+ __puts "Which way?"
9
+ elsif @__world.player.location.exits[args[0]]
10
+ @__world.player.location = @__world.locations[@__world.player.location.exits[args[0]]]
11
+ look
12
+ else
13
+ __puts "You can't go that way"
14
+ end
15
+ __handle!
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,9 @@
1
+ require 'lib/rubinstein/actions/movement'
2
+
3
+ module Rubinstein
4
+ module Actions
5
+ def self.included(base)
6
+ base.send(:include,Rubinstein::Actions::Movement)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,16 @@
1
+ module Rubinstein
2
+ class Game
3
+
4
+ def self.run(world)
5
+ runner = Runner.new(world)
6
+ puts "Welcome to the text adventure game!"
7
+ print "> "
8
+ until (input = $stdin.gets.chomp) == "exit"
9
+ runner.__execute(input.downcase)
10
+ print "> "
11
+ end
12
+ puts "Thanks for playing"
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,26 @@
1
+ module Rubinstein
2
+ class Location
3
+
4
+ attr_accessor :name, :description, :exits
5
+
6
+ def initialize(name,&block)
7
+ @name = name
8
+ @exits = {}
9
+
10
+ instance_eval &block
11
+ end
12
+
13
+ def description(prose)
14
+ @description = prose
15
+ end
16
+
17
+ ["north","south","east","west"].each do |direction|
18
+ class_eval <<-END
19
+ def #{direction}(location)
20
+ @exits["#{direction}"] = location
21
+ end
22
+ END
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,7 @@
1
+ module Rubinstein
2
+ class Player
3
+
4
+ attr_accessor :location
5
+
6
+ end
7
+ end
@@ -0,0 +1,42 @@
1
+ require 'lib/rubinstein/actions'
2
+
3
+ module Rubinstein
4
+ class Runner < BasicObject
5
+ class << self
6
+ def const_missing(name)
7
+ Kernel.const_get(name)
8
+ end
9
+ end
10
+ include Rubinstein::Actions
11
+
12
+ attr_accessor :__world, :__handled
13
+
14
+ def initialize(world)
15
+ @__world = world
16
+ end
17
+
18
+ def __handle!
19
+ @__handled = true
20
+ end
21
+
22
+ def __execute(string)
23
+ @__handled = false
24
+ instance_eval(string)
25
+ __puts "I don't understand" unless @__handled
26
+ end
27
+
28
+ def __puts(message)
29
+ $stdout.puts(message)
30
+ end
31
+
32
+ def method_missing(name,*args)
33
+ return *args.flatten.unshift(name.to_s)
34
+ end
35
+
36
+ def look(*args)
37
+ __puts @__world.player.location.instance_eval(:@description)
38
+ __handle!
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,23 @@
1
+ module Rubinstein
2
+ class World
3
+
4
+ attr_accessor :name, :locations, :player
5
+
6
+ def initialize(name,&block)
7
+ @name = name
8
+ @locations = {}
9
+ @player = Player.new
10
+
11
+ instance_eval &block
12
+ end
13
+
14
+ def location(name,&block)
15
+ @locations[name] = Location.new(name,&block)
16
+ end
17
+
18
+ def start(location)
19
+ @player.location = @locations[location]
20
+ end
21
+
22
+ end
23
+ end
data/lib/rubinstein.rb ADDED
@@ -0,0 +1,7 @@
1
+ $:.unshift(File.dirname(__FILE__)+'/../lib')
2
+
3
+ require 'rubinstein/runner'
4
+ require 'rubinstein/location'
5
+ require 'rubinstein/player'
6
+ require 'rubinstein/game'
7
+ require 'rubinstein/world'
@@ -0,0 +1,41 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{rubinstein}
5
+ s.version = "0.0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Kevin W. Gisi"]
9
+ s.date = %q{2010-08-05}
10
+ s.default_executable = %q{rubinstein}
11
+ s.description = %q{Ruby text-adventure game engine}
12
+ s.email = %q{kevin@kevingisi.com}
13
+ s.executables = ["rubinstein"]
14
+ s.extra_rdoc_files = ["LICENSE", "README.rdoc", "bin/rubinstein", "lib/rubinstein.rb", "lib/rubinstein/actions.rb", "lib/rubinstein/actions/movement.rb", "lib/rubinstein/game.rb", "lib/rubinstein/location.rb", "lib/rubinstein/player.rb", "lib/rubinstein/runner.rb", "lib/rubinstein/world.rb"]
15
+ s.files = ["LICENSE", "README.rdoc", "Rakefile", "VERSION", "bin/rubinstein", "example.rb", "features/support/aruba_interactive.rb", "features/support/env.rb", "features/usage.feature", "lib/rubinstein.rb", "lib/rubinstein/actions.rb", "lib/rubinstein/actions/movement.rb", "lib/rubinstein/game.rb", "lib/rubinstein/location.rb", "lib/rubinstein/player.rb", "lib/rubinstein/runner.rb", "lib/rubinstein/world.rb", "simple.rb", "spec/spec.opts", "spec/spec_helper.rb", "Manifest", "rubinstein.gemspec"]
16
+ s.homepage = %q{http://gisikw.github.com/my}
17
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Rubinstein", "--main", "README.rdoc"]
18
+ s.require_paths = ["lib"]
19
+ s.rubyforge_project = %q{rubinstein}
20
+ s.rubygems_version = %q{1.3.7}
21
+ s.summary = %q{Ruby text-adventure game engine}
22
+
23
+ if s.respond_to? :specification_version then
24
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
+ s.specification_version = 3
26
+
27
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
28
+ s.add_development_dependency(%q<cucumber>, [">= 0.7.2"])
29
+ s.add_development_dependency(%q<aruba>, [">= 0.1.9"])
30
+ s.add_development_dependency(%q<rspec>, [">= 1.3.0"])
31
+ else
32
+ s.add_dependency(%q<cucumber>, [">= 0.7.2"])
33
+ s.add_dependency(%q<aruba>, [">= 0.1.9"])
34
+ s.add_dependency(%q<rspec>, [">= 1.3.0"])
35
+ end
36
+ else
37
+ s.add_dependency(%q<cucumber>, [">= 0.7.2"])
38
+ s.add_dependency(%q<aruba>, [">= 0.1.9"])
39
+ s.add_dependency(%q<rspec>, [">= 1.3.0"])
40
+ end
41
+ end
data/simple.rb ADDED
@@ -0,0 +1,2 @@
1
+ World.new("Simple") do
2
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color --format nested
@@ -0,0 +1,11 @@
1
+ $:.unshift(File.dirname(__FILE__))
2
+ $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ require 'rubinstein'
8
+
9
+ Spec::Runner.configure do |config|
10
+ config.mock_with :mocha
11
+ end
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubinstein
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Kevin W. Gisi
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-08-05 00:00:00 -05:00
19
+ default_executable: rubinstein
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: cucumber
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 7
30
+ segments:
31
+ - 0
32
+ - 7
33
+ - 2
34
+ version: 0.7.2
35
+ type: :development
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: aruba
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 9
46
+ segments:
47
+ - 0
48
+ - 1
49
+ - 9
50
+ version: 0.1.9
51
+ type: :development
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: rspec
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 27
62
+ segments:
63
+ - 1
64
+ - 3
65
+ - 0
66
+ version: 1.3.0
67
+ type: :development
68
+ version_requirements: *id003
69
+ description: Ruby text-adventure game engine
70
+ email: kevin@kevingisi.com
71
+ executables:
72
+ - rubinstein
73
+ extensions: []
74
+
75
+ extra_rdoc_files:
76
+ - LICENSE
77
+ - README.rdoc
78
+ - bin/rubinstein
79
+ - lib/rubinstein.rb
80
+ - lib/rubinstein/actions.rb
81
+ - lib/rubinstein/actions/movement.rb
82
+ - lib/rubinstein/game.rb
83
+ - lib/rubinstein/location.rb
84
+ - lib/rubinstein/player.rb
85
+ - lib/rubinstein/runner.rb
86
+ - lib/rubinstein/world.rb
87
+ files:
88
+ - LICENSE
89
+ - README.rdoc
90
+ - Rakefile
91
+ - VERSION
92
+ - bin/rubinstein
93
+ - example.rb
94
+ - features/support/aruba_interactive.rb
95
+ - features/support/env.rb
96
+ - features/usage.feature
97
+ - lib/rubinstein.rb
98
+ - lib/rubinstein/actions.rb
99
+ - lib/rubinstein/actions/movement.rb
100
+ - lib/rubinstein/game.rb
101
+ - lib/rubinstein/location.rb
102
+ - lib/rubinstein/player.rb
103
+ - lib/rubinstein/runner.rb
104
+ - lib/rubinstein/world.rb
105
+ - simple.rb
106
+ - spec/spec.opts
107
+ - spec/spec_helper.rb
108
+ - Manifest
109
+ - rubinstein.gemspec
110
+ has_rdoc: true
111
+ homepage: http://gisikw.github.com/my
112
+ licenses: []
113
+
114
+ post_install_message:
115
+ rdoc_options:
116
+ - --line-numbers
117
+ - --inline-source
118
+ - --title
119
+ - Rubinstein
120
+ - --main
121
+ - README.rdoc
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ none: false
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ hash: 3
130
+ segments:
131
+ - 0
132
+ version: "0"
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ none: false
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ hash: 11
139
+ segments:
140
+ - 1
141
+ - 2
142
+ version: "1.2"
143
+ requirements: []
144
+
145
+ rubyforge_project: rubinstein
146
+ rubygems_version: 1.3.7
147
+ signing_key:
148
+ specification_version: 3
149
+ summary: Ruby text-adventure game engine
150
+ test_files: []
151
+