The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
MUD in 15 Lines of Ruby

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Red Handed

Posts: 1158
Nickname: redhanded
Registered: Dec, 2004

Red Handed is a Ruby-focused group blog.
MUD in 15 Lines of Ruby Posted: Aug 30, 2005 9:49 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Red Handed.
Original Post: MUD in 15 Lines of Ruby
Feed Title: RedHanded
Feed URL: http://redhanded.hobix.com/index.xml
Feed Description: sneaking Ruby through the system
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Red Handed
Latest Posts From RedHanded

Advertisement

This is great. In response to a post about how writing a MUD in Ruby would be “a horrifically complex and lengthy project,” Jon Lambert dropped a 15-line MUD in the response! Now that’s a comeback.

 require 'socket';require 'yaml';def q x;$m.find{|o|o.t==:p&&x==o.n};end
 def a r,t;$m.find_all{|o|t==o.t&&(!r||r==o.l)};end;def g z;a(nil,:p).each{|p|
 p.p z};end;class O;attr_accessor :i,:n,:l,:e,:s,:t;def initialize n,l=nil,t=:r
 @n,@l,@i,@t=n,l,$d+=1,t;@e={};end;def p s;@s.puts(s)if @s;end;def y m
 v=$m.find{|o|@l==o.i};t=v.e.keys;case m;when/^q/;@s.close;@s=nil;
 File.open('d','w'){|f|YAML::dump $m,f};when/^h/;p "i,l,d,g,c,h,q,,O,R" 
 when/^i/;a(@i,:o).each{|o|p o.n};when/^c.* (.*)/;g "#{@n}:#{$1}" 
 when/^g/;a(@l,:o).each{|q|q.l=@i};when/^d/;a(@i,:o).each{|q|q.l=@l}
 when/^O (.*)/;$m<<<

A bit of sleuthing on the matter and I’ve discovered that this is a derivative of Jon’s TeensyMud. He has nice, readable versions in his repository, if you like.

If you want to play with this one:

  1. Save the above to teensymud.rb.
  2. Create a YAML file named “d” (for dungeon) with a blank array in it. (Likeso: echo "[]" > d.)
  3. Run teensymud.rb.
  4. Telnet to localhost port 4000.
  5. At Name prompt, enter your name then .
Play commands
i displays player inventory
l displays the contents of a room
dr drops all objects in your inventory into the room
g gets all objects in the room into your inventory
k attempts to kill player (e.g. k bubba)
s[ay] sends to all players in the room
c[hat] sends to all players in the game
q[uit] quits the game (saves player)
moves player through exit named (ex. south)
OLC
O creates a new object (ex. O rose)
R creates a new room and autolinks the exits using the exit names provided.

Please, tell us more, Jon. If you’re feeling nostalgic and want to egg things on, come join ruby-talk this week. The Ruby Quiz will be a MUD client. (extracted from ruby-talk:154208.)

Read: MUD in 15 Lines of Ruby

Topic: IMG_0660.JPG [Flickr] Previous Topic   Next Topic Topic: A Swedish Rails community

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use