adventure.rb
# Shortcut for single-player games
Shortcut for single-player games
Shortcut for single - player games
def player(id=nil, params=nil)
		if params.nil?
			params = id
			id = @@player
		end
		return id unless params
		if params[:start]
			return 'That player has already started.' if id.is_a?Adventure::Player
			if id
				id = Adventure::Player.new(id, params[:start])
			else
				id = Adventure::Player.new('Player 1', params[:start])
				@@player = id
			end
			params.delete :start
		end
		unless id
			raise "You must start a player with player :start before you can send commands."
		end
		rtrn = []
		params.each do |k, v|
			next unless k
			k = k.to_sym
			v = [v].flatten(1)
			begin
				direct_object = Adventure::resolve(v.first)
				if (item = id.has_item?(direct_object)) && item.respond_to?(k)
					v.shift
					rtrn << item.send(k, *v)
				elsif (item = id.current_room.has_item?(direct_object)) && item.respond_to?(k)
					v.shift
					rtrn << item.send(k, *v)
				else
					rtrn << id.send(k.to_sym, *v)
				end
			rescue Exception
				rtrn << "I don't understand what you said, sorry."
			end
		end
		return rtrn.first if rtrn.length < 2
		rtrn
	end
def player ( id = nil , params = nil ) if params . nil? params = id id = @@player end return id unless params if params [ :start ] return 'That player has already started.' if id . is_a? Adventure :: Player if id id = Adventure :: Player . new ( id , params [ :start ] ) else id = Adventure :: Player . new ( 'Player 1' , params [ :start ] ) @@player = id end params . delete :start end unless id raise "You must start a player with player :start before you can send commands." end rtrn = [ ] params . each do | k , v | next unless k k = k . to_sym v = [ v ] . flatten ( 1 ) begin direct_object = Adventure :: resolve ( v . first ) if ( item = id . has_item? ( direct_object ) ) && item . respond_to? ( k ) v . shift rtrn << item . send ( k , * v ) elsif ( item = id . current_room . has_item? ( direct_object ) ) && item . respond_to? ( k ) v . shift rtrn << item . send ( k , * v ) else rtrn << id . send ( k . to_sym , * v ) end rescue Exception rtrn << "I don't understand what you said, sorry." end end return rtrn . first if rtrn . length < 2 rtrn end
Shortcut for single-player games
Shortcut for single - player games
id
<not_specific>
params
<not_specific>