rubyquest 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +7 -0
- data/Gemfile.lock +32 -0
- data/README.md +2 -0
- data/bin/rubyquest +7 -0
- data/lib/rubyquest.rb +11 -0
- data/lib/rubyquest/cli.rb +54 -0
- data/lib/rubyquest/command.rb +48 -0
- data/lib/rubyquest/hero.rb +26 -0
- data/lib/rubyquest/map.rb +56 -0
- data/lib/rubyquest/output.rb +21 -0
- data/lib/rubyquest/quest.rb +29 -0
- data/rubyquest.gemspec +26 -0
- metadata +58 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.3)
|
5
|
+
ffi (1.0.11)
|
6
|
+
guard (1.0.1)
|
7
|
+
ffi (>= 0.5.0)
|
8
|
+
thor (~> 0.14.6)
|
9
|
+
guard-rspec (0.7.0)
|
10
|
+
guard (>= 0.10.0)
|
11
|
+
multi_json (1.3.2)
|
12
|
+
rspec (2.9.0)
|
13
|
+
rspec-core (~> 2.9.0)
|
14
|
+
rspec-expectations (~> 2.9.0)
|
15
|
+
rspec-mocks (~> 2.9.0)
|
16
|
+
rspec-core (2.9.0)
|
17
|
+
rspec-expectations (2.9.1)
|
18
|
+
diff-lcs (~> 1.1.3)
|
19
|
+
rspec-mocks (2.9.0)
|
20
|
+
simplecov (0.6.2)
|
21
|
+
multi_json (~> 1.3)
|
22
|
+
simplecov-html (~> 0.5.3)
|
23
|
+
simplecov-html (0.5.3)
|
24
|
+
thor (0.14.6)
|
25
|
+
|
26
|
+
PLATFORMS
|
27
|
+
ruby
|
28
|
+
|
29
|
+
DEPENDENCIES
|
30
|
+
guard-rspec
|
31
|
+
rspec (>= 2)
|
32
|
+
simplecov
|
data/README.md
ADDED
data/bin/rubyquest
ADDED
data/lib/rubyquest.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
module Rubyquest
|
2
|
+
|
3
|
+
class CLI
|
4
|
+
require 'readline'
|
5
|
+
require 'rubyquest/output'
|
6
|
+
require 'rubyquest/command'
|
7
|
+
require 'rubyquest/hero'
|
8
|
+
|
9
|
+
attr_reader :input, :output, :hero
|
10
|
+
|
11
|
+
def initialize input = ::Readline, output = Output
|
12
|
+
@input, @output = input, output
|
13
|
+
end
|
14
|
+
|
15
|
+
def start!
|
16
|
+
greetings
|
17
|
+
# Leave the game without a Ruby exception upon interruption
|
18
|
+
trap(:INT) { puts; exit }
|
19
|
+
set_user
|
20
|
+
console
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def greetings
|
26
|
+
output.message "Greeting stranger, welcome to Rubyquest! May I have your name?", :announce
|
27
|
+
end
|
28
|
+
|
29
|
+
def prompt
|
30
|
+
"Rubyquest ~> "
|
31
|
+
end
|
32
|
+
|
33
|
+
def set_user
|
34
|
+
until hero do
|
35
|
+
name = input.readline(prompt)
|
36
|
+
if ( @hero = Hero.find(name) )
|
37
|
+
output.message "Nice to meet you #{hero.name}. Type 'help' to see the available commands.", :announce
|
38
|
+
else
|
39
|
+
output.message "C'mon give me your name!", :announce
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def console
|
45
|
+
loop do
|
46
|
+
command = input.readline(prompt)
|
47
|
+
Readline::HISTORY.push(command)
|
48
|
+
Command.new command, hero
|
49
|
+
break if command == 'exit'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Rubyquest
|
2
|
+
|
3
|
+
class Command
|
4
|
+
require 'rubyquest/output'
|
5
|
+
require 'rubyquest/quest'
|
6
|
+
|
7
|
+
attr_reader :output
|
8
|
+
|
9
|
+
COMMANDS = [
|
10
|
+
'go to <place>',
|
11
|
+
'help',
|
12
|
+
'exit'
|
13
|
+
]
|
14
|
+
|
15
|
+
def initialize string, hero = nil
|
16
|
+
case string
|
17
|
+
when /^help$/
|
18
|
+
help
|
19
|
+
when /^exit$/
|
20
|
+
nil
|
21
|
+
when /^quests$/
|
22
|
+
Quest.load
|
23
|
+
when /^go to (\D*)$/
|
24
|
+
$1
|
25
|
+
go $1, hero.map
|
26
|
+
else
|
27
|
+
invalid string
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def invalid command
|
34
|
+
Output.message "'#{command}' is not a valid command. Type 'help' to see all available commands."
|
35
|
+
end
|
36
|
+
|
37
|
+
def help
|
38
|
+
commands = "Commands: " << COMMANDS.join(', ')
|
39
|
+
Output.message commands
|
40
|
+
end
|
41
|
+
|
42
|
+
def go location, map
|
43
|
+
map.travel location
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Rubyquest
|
2
|
+
|
3
|
+
class Hero
|
4
|
+
require 'rubyquest/map'
|
5
|
+
|
6
|
+
attr_reader :name, :level, :map
|
7
|
+
|
8
|
+
def initialize name
|
9
|
+
@name = name
|
10
|
+
@level = 1
|
11
|
+
@map = Map.new
|
12
|
+
end
|
13
|
+
|
14
|
+
# Latter it will find the user from some place
|
15
|
+
def self.find(name)
|
16
|
+
name.strip!
|
17
|
+
if !name.empty?
|
18
|
+
new(name)
|
19
|
+
else
|
20
|
+
nil
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Rubyquest
|
2
|
+
|
3
|
+
class Map
|
4
|
+
require 'rubyquest/output'
|
5
|
+
|
6
|
+
attr_reader :output, :current
|
7
|
+
|
8
|
+
def initialize(output = Output.new)
|
9
|
+
@output = output
|
10
|
+
end
|
11
|
+
|
12
|
+
def travel place
|
13
|
+
#if Place.find(place)
|
14
|
+
self.current = place
|
15
|
+
#else
|
16
|
+
#output.error "#{place} is not a valid place. Type 'map' to list all available places"
|
17
|
+
end
|
18
|
+
|
19
|
+
def list
|
20
|
+
message = ""
|
21
|
+
places.each_with_index do |place, i|
|
22
|
+
message << "#{i + 1}. #{place.name}"
|
23
|
+
end
|
24
|
+
output.action message
|
25
|
+
end
|
26
|
+
|
27
|
+
def add place
|
28
|
+
places.push place
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def current= place
|
34
|
+
if current == place
|
35
|
+
message = "You already are in #{place.name}"
|
36
|
+
elsif on_map? place
|
37
|
+
@current = place
|
38
|
+
message = "You have reached the #{place.name}"
|
39
|
+
else
|
40
|
+
message = "#{place.name.capitalize} is not on your map. Type 'map' to list all available places"
|
41
|
+
end
|
42
|
+
output.action message
|
43
|
+
end
|
44
|
+
|
45
|
+
# In the future needs to be a tree
|
46
|
+
def places
|
47
|
+
@places ||= []
|
48
|
+
end
|
49
|
+
|
50
|
+
def on_map? place
|
51
|
+
places.include? place
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Rubyquest
|
2
|
+
class Output
|
3
|
+
|
4
|
+
def self.message text, type = :action
|
5
|
+
output = new
|
6
|
+
message = output.instance_eval "#{type}(\"#{text}\")"
|
7
|
+
puts message
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def announce text
|
13
|
+
"** #{text} **"
|
14
|
+
end
|
15
|
+
|
16
|
+
def action text
|
17
|
+
text
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Rubyquest
|
2
|
+
|
3
|
+
class Quest
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
attr_reader :name
|
7
|
+
|
8
|
+
def initialize yaml
|
9
|
+
parse yaml
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.load path = './quests'
|
13
|
+
files = Dir.glob( path + '/*.yml')
|
14
|
+
files.each do |file|
|
15
|
+
quest = YAML.load_file file
|
16
|
+
new(quest)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def parse yaml
|
23
|
+
quest = yaml['quest']
|
24
|
+
@name = quest['name']
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
data/rubyquest.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'rubyquest'
|
3
|
+
s.version = '0.0.1'
|
4
|
+
s.date = '2012-04-28'
|
5
|
+
s.summary = 'Rubyquest is a text-based game made, well, in Ruby!'
|
6
|
+
s.description = 'The game development is still in its early days, the main goal is to provide a simple framework to create rpg quests in Ruby.'
|
7
|
+
s.authors = ['Luiz Branco']
|
8
|
+
s.email = 'me@luizbranco.com'
|
9
|
+
s.homepage = 'http://github.com/luizbranco/rubyquest'
|
10
|
+
s.executables = ['rubyquest']
|
11
|
+
s.files = [
|
12
|
+
'Gemfile',
|
13
|
+
'Gemfile.lock',
|
14
|
+
'README.md',
|
15
|
+
'bin/rubyquest',
|
16
|
+
'lib/rubyquest.rb',
|
17
|
+
'lib/rubyquest/cli.rb',
|
18
|
+
'lib/rubyquest/command.rb',
|
19
|
+
'lib/rubyquest/hero.rb',
|
20
|
+
'lib/rubyquest/map.rb',
|
21
|
+
'lib/rubyquest/output.rb',
|
22
|
+
'lib/rubyquest/quest.rb',
|
23
|
+
'rubyquest.gemspec'
|
24
|
+
]
|
25
|
+
s.require_paths = ['lib']
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubyquest
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Luiz Branco
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-28 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: The game development is still in its early days, the main goal is to
|
15
|
+
provide a simple framework to create rpg quests in Ruby.
|
16
|
+
email: me@luizbranco.com
|
17
|
+
executables:
|
18
|
+
- rubyquest
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- Gemfile
|
23
|
+
- Gemfile.lock
|
24
|
+
- README.md
|
25
|
+
- bin/rubyquest
|
26
|
+
- lib/rubyquest.rb
|
27
|
+
- lib/rubyquest/cli.rb
|
28
|
+
- lib/rubyquest/command.rb
|
29
|
+
- lib/rubyquest/hero.rb
|
30
|
+
- lib/rubyquest/map.rb
|
31
|
+
- lib/rubyquest/output.rb
|
32
|
+
- lib/rubyquest/quest.rb
|
33
|
+
- rubyquest.gemspec
|
34
|
+
homepage: http://github.com/luizbranco/rubyquest
|
35
|
+
licenses: []
|
36
|
+
post_install_message:
|
37
|
+
rdoc_options: []
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
requirements: []
|
53
|
+
rubyforge_project:
|
54
|
+
rubygems_version: 1.8.15
|
55
|
+
signing_key:
|
56
|
+
specification_version: 3
|
57
|
+
summary: Rubyquest is a text-based game made, well, in Ruby!
|
58
|
+
test_files: []
|