From: Robert Klemme Date: 2012-09-24T20:07:52+09:00 Subject: Re: still learning by doing - connecting rooms in a game On Fri, Sep 21, 2012 at 12:02 AM, Henry Maddocks wrote: > > To start with I would have… > > One Room class that takes a name and description Ack. > and a visited attribute. Well, it depends what kind of attribute you are thinking of: if there are more players then the attribute would at least have to be a collection type. Conceptually visit is a relationship between room and user - with potentially more properties (e.g. time of visit, order). > Not a class for each room as you have done. Ack. > Create a Map structure that defines the room layout. Something like > > [ > {:room => :kitchen, :next_rooms => {:north => :living_room, :south => :basement}}, > {:room => : living_room, :next_rooms => {:north => :bathroom, :south => :kitchen}}, > ... > ] I'd rather make the rooms reference their neighbors, maybe like this: class Room attr_accessor :name, :description def neighbors @neighbors || = {} end def connect(direction, other_room) neighbors[direction] = other_room other_room.neighbors[reverse_direction(direction)] = self end private def reverse_direction(d) case d when :north then :south when :south then :north #... else raise ArgumentError, "Illegal direction: %p" % [d] end end Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/