Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
89 lines (73 sloc) 2 KB
# Basic example using "Adventure" DSL
# Define rooms (locations), commands, and items
# Start the player somewhere
# There are some default commands: go, get, drop
require 'adventure'
# This tells the DSL to print the different ways a player can go.
# Make us a river! There's a pebble there, you can call it a pebble or just pebble.
room(:a_river, 'A peaceful river.') {
item :a_pebble, 'A small, smooth stone.', [:pebble] {
# You can hit the pebble, but only if you have it.
command(:hit) {
if player.has_item?(self)
# Drop and then "get" to nowhere makes it go away
room(player.current_room) {
'The pebble vanishes.'
'You do not have a pebble.'
direction :north => :a_hill
direction :west => :the_lake
# Make us a hill! The only thing you can do is go south to the river.
room(:a_hill, 'On top of a hill.') {
direction :south => :a_river
# Make us a lake! There's food and a knife here... not too exciting.
room(:the_lake, 'Isn\'t this lake awesome!') {
direction :east => :a_river
direction :north => :a_hill
item :food, 'Some food.'
item :a_knife, 'A sharp knife.', [:knife]
# This is just the catch-all for if you do not specify
# something to hit (or what you specify is not there)
# The synonym set up here will be applied globally
command(:hit, [:strike]) { |*args|
'Hit what?'
# We can make silly commands too.
command(:sing) {
'You sing a little song.'
# The not-so-useful help
command(:help) {
if has_item?:a_pebble
'What? Lost? Try hitting the pebble.'
'Is the pebble gone? Because there\'s really nothing else.'
# Start the player at the river.
player :start => :a_river
# Game interface. Just do the traditional text-based interface.
puts player.current_room
catch :quit do
loop do
verb, objects = parse gets
throw :quit if verb == :quit
throw :quit if verb == :exit
puts player(verb => objects)
puts 'Thanks for playing!'