Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
gisikw committed Aug 5, 2010
0 parents commit dab4374
Show file tree
Hide file tree
Showing 20 changed files with 333 additions and 0 deletions.
20 changes: 20 additions & 0 deletions LICENSE
@@ -0,0 +1,20 @@
Copyright (c) 2010 Kevin W. Gisi

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 changes: 20 additions & 0 deletions README.rdoc
@@ -0,0 +1,20 @@
= Rubinstein

Rubinstein is a text-adventure game engine written in Ruby

== Installation and Usage

In order to use Rubinstein, simply install the gem:

gem install rubinstein

Then to run a Rubinstein game, just run:

rubinstein my_game.rb

== Coming Soon

This is a very new project - detailed stuff coming soon.

== Copyright
Copyright (c) 2010 Kevin W. Gisi. Released under the MIT License
41 changes: 41 additions & 0 deletions Rakefile
@@ -0,0 +1,41 @@
require 'echoe'
require 'rake/rdoctask'
require 'cucumber/rake/task'
require 'spec/rake/spectask'

Echoe.new "rubinstein", File.read("VERSION").chomp do |m|
m.author = "Kevin W. Gisi"
m.email = "kevin@kevingisi.com"
m.summary = "Ruby text-adventure game engine"
m.url = "http://gisikw.github.com/my"
m.development_dependencies << "cucumber >=0.7.2"
m.development_dependencies << "aruba >=0.1.9"
m.development_dependencies << "rspec >=1.3.0"
end

Spec::Rake::SpecTask.new(:spec) do |spec|
spec.libs << 'lib' << 'spec'
spec.spec_files = FileList['spec/**/*_spec.rb']
end

Spec::Rake::SpecTask.new(:rcov) do |spec|
spec.libs << 'lib' << 'spec'
spec.spec_files = FileList['spec/**/*_spec.rb']
spec.rcov = true
spec.rcov_opts = ["-T"]
end

Cucumber::Rake::Task.new do |t|
t.cucumber_opts = %w{--format pretty}
end

Rake::RDocTask.new do |rdoc|
version = File.exist?('VERSION') ? File.read('VERSION') : ""
rdoc.rdoc_dir = 'rdoc'
rdoc.title = "Rubinstein #{version}"
rdoc.main = 'README.rdoc'
rdoc.rdoc_files.include('README.rdoc')
rdoc.rdoc_files.include('lib/**/*.rb')
end

task :default => :spec
1 change: 1 addition & 0 deletions VERSION
@@ -0,0 +1 @@
0.0.1
5 changes: 5 additions & 0 deletions bin/rubinstein
@@ -0,0 +1,5 @@
#!/usr/bin/env ruby

require File.join(File.dirname(__FILE__),'..','lib','rubinstein.rb')

Rubinstein::Game.run(Rubinstein.class_eval(File.read(ARGV[0])))
22 changes: 22 additions & 0 deletions example.rb
@@ -0,0 +1,22 @@
World.new("My First Text Adventure") do


location "hallway" do
description "A dark and quiet hallway"
north "kitchen"
end

location "kitchen" do
description "An abandoned kitchen"
north "hall"
south "hallway"
end

location "hall" do
description "A banquet hall...strangely deserted"
south "kitchen"
end

start "hallway"

end
42 changes: 42 additions & 0 deletions features/support/aruba_interactive.rb
@@ -0,0 +1,42 @@
require 'open3'

Before '@aruba_interactive' do
@stdout_stream = nil
@stderr_stream = nil
@stdout = ""
@stdin = ""

@stdout_listener = Thread.new do
Thread.stop
loop do
@stdout << @stdout_stream.readpartial(1)
end
end

@stderr_listener = Thread.new do
Thread.stop
loop do
@stderr << @stderr_stream.readpartial(1)
end
end
end

When /^I run "([^\"]*)" interactively$/ do |arg1|
old_dir = Dir.pwd
Dir.chdir("tmp/aruba") unless Dir.pwd.split('/')[-1] == "aruba"
@stdin_stream, @stdout_stream, @stderr_stream = Open3.popen3(arg1)
Dir.chdir(old_dir)
sleep 1
@stdout_listener.run
@stderr_listener.run
end

When /^I type "([^\"]*)"$/ do |arg1|
@stdin_stream.puts arg1
sleep 0.5
end

Then /^the program should prompt "([^\"]*)"$/ do |arg1|
sleep 0.5
@stdout.should include(arg1)
end
9 changes: 9 additions & 0 deletions features/support/env.rb
@@ -0,0 +1,9 @@
$:.unshift(File.dirname(__FILE__)+'/../../lib')
require 'aruba'
require 'rubinstein'

begin
require 'rspec/expectations'
rescue LoadError
require 'spec/expectations'
end
9 changes: 9 additions & 0 deletions features/usage.feature
@@ -0,0 +1,9 @@
Feature: Help
As a user of the Rubinstein gem
I want to view the usage information
So I can use the gem effectively

Scenario: Viewing the usage information implicitly
When I run "../../bin/rubinstein"
Then I should see "Rubinstein"
And I should see "USAGE: rubinstein my_game.rb"
7 changes: 7 additions & 0 deletions lib/rubinstein.rb
@@ -0,0 +1,7 @@
$:.unshift(File.dirname(__FILE__)+'/../lib')

require 'rubinstein/runner'
require 'rubinstein/location'
require 'rubinstein/player'
require 'rubinstein/game'
require 'rubinstein/world'
9 changes: 9 additions & 0 deletions lib/rubinstein/actions.rb
@@ -0,0 +1,9 @@
require 'lib/rubinstein/actions/movement'

module Rubinstein
module Actions
def self.included(base)
base.send(:include,Rubinstein::Actions::Movement)
end
end
end
20 changes: 20 additions & 0 deletions lib/rubinstein/actions/movement.rb
@@ -0,0 +1,20 @@
module Rubinstein
module Actions
module Movement

def walk(*args)
args.flatten!
if !args[0]
__puts "Which way?"
elsif @__world.player.location.exits[args[0]]
@__world.player.location = @__world.locations[@__world.player.location.exits[args[0]]]
look
else
__puts "You can't go that way"
end
__handle!
end

end
end
end
16 changes: 16 additions & 0 deletions lib/rubinstein/game.rb
@@ -0,0 +1,16 @@
module Rubinstein
class Game

def self.run(world)
runner = Runner.new(world)
puts "Welcome to the text adventure game!"
print "> "
until (input = $stdin.gets.chomp) == "exit"
runner.__execute(input.downcase)
print "> "
end
puts "Thanks for playing"
end

end
end
26 changes: 26 additions & 0 deletions lib/rubinstein/location.rb
@@ -0,0 +1,26 @@
module Rubinstein
class Location

attr_accessor :name, :description, :exits

def initialize(name,&block)
@name = name
@exits = {}

instance_eval &block
end

def description(prose)
@description = prose
end

["north","south","east","west"].each do |direction|
class_eval <<-END
def #{direction}(location)
@exits["#{direction}"] = location
end
END
end

end
end
7 changes: 7 additions & 0 deletions lib/rubinstein/player.rb
@@ -0,0 +1,7 @@
module Rubinstein
class Player

attr_accessor :location

end
end
42 changes: 42 additions & 0 deletions lib/rubinstein/runner.rb
@@ -0,0 +1,42 @@
require 'lib/rubinstein/actions'

module Rubinstein
class Runner < BasicObject
class << self
def const_missing(name)
Kernel.const_get(name)
end
end
include Rubinstein::Actions

attr_accessor :__world, :__handled

def initialize(world)
@__world = world
end

def __handle!
@__handled = true
end

def __execute(string)
@__handled = false
instance_eval(string)
__puts "I don't understand" unless @__handled
end

def __puts(message)
$stdout.puts(message)
end

def method_missing(name,*args)
return *args.flatten.unshift(name.to_s)
end

def look(*args)
__puts @__world.player.location.instance_eval(:@description)
__handle!
end

end
end
23 changes: 23 additions & 0 deletions lib/rubinstein/world.rb
@@ -0,0 +1,23 @@
module Rubinstein
class World

attr_accessor :name, :locations, :player

def initialize(name,&block)
@name = name
@locations = {}
@player = Player.new

instance_eval &block
end

def location(name,&block)
@locations[name] = Location.new(name,&block)
end

def start(location)
@player.location = @locations[location]
end

end
end
2 changes: 2 additions & 0 deletions simple.rb
@@ -0,0 +1,2 @@
World.new("Simple") do
end
1 change: 1 addition & 0 deletions spec/spec.opts
@@ -0,0 +1 @@
--color --format nested
11 changes: 11 additions & 0 deletions spec/spec_helper.rb
@@ -0,0 +1,11 @@
$:.unshift(File.dirname(__FILE__))
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))

require 'spec'
require 'spec/autorun'

require 'rubinstein'

Spec::Runner.configure do |config|
config.mock_with :mocha
end

0 comments on commit dab4374

Please sign in to comment.