-----Original Message-----
From: "Jason"<jasowong / my-deja.com>
To: "ruby-talk ML"<ruby-talk / netlab.co.jp>
Date: Sat Feb 03 17:40:02 PST 2001
Subject: [ruby-talk:10328] Multi-dimensional Array

>Hi All,
>
>Beginning programmer (and beginning Ruby programmer) here... First off,

Welcome!

>I'm going to start with a mapreader class. I thought I could start by
>reading in a text file, with x's to denote walls.  So, I'm thinking I
>would need to store the x, y, and type of object (wall, monster,
>treasure, etc.) in the array, and thought that a multi-dimensional
>array would keep all of the data in good order.
>
snip
>So the question is,
>
>a. Is a multi-dimensional array the best way to track this information?
>b. Does Ruby have support for it?
>c. Is there a better way to keep the information?
>

Personally, I think I'd start off with a Map class (maybe module), where you can set and get x,y positions (being careful to account for multiple locations (for rooms)), everything would subclass that (or maybe you could mix it in).  Then, I'd create a Monster class, a Hero class, and a Room class.  Each would carry it's own position, plus whatever other info you'd want (strength, etc).  You could override +,-,etc to move the creature or whatever.  You'd actually have to think more about the structure of it, now that I've got you thinking in OOP terms.  I'd bet that you'll find that an implementation like this would be very easy to program and even easier to add features (new monsters, etc) to.

Arrays are great, but this is the kind of stuff that OOP really shines with.  It'll take you awhile before you start thinking that way, but once you do you'll realize the real potential.
Mike Wilson
Unix Administrator
http://ruby.weblogs.com
___________________________________________________
GO.com Mail                                    
Get Your Free, Private E-mail at http://mail.go.com