Go directlyCode:
# Encoding: utf-8class dungeon # create Get Set Method # Save the player and room list attr_accessor: Player def initialize (player_name) @ player = player. new (player_name) @ room = [] end # sets the player location attribute def start (location) @ player. location = Location show_current_description end # locate def show_current_description puts find_room_in_dungeon (@ player. location ). full_description end # def find_room_in_dungeon (reference) @ room. detect {| room. reference = reference} end # def find_room_in_direction (Direction) find_room_in_dungeon (@ player. location ). connections [direction] end # def go (Direction) puts "to # {direction. to_s} "@ player. location = find_room_in_direction (Direction) show_current_description end # Add the room def add_room (reference, name, description, connections) @ Room <room. new (reference, name, description, connections) end # player = struct. new (: name,: location) # room = struct. new (: reference,: name,: Description,: connections) endclass player # create a Get Set Method # Save the name and current location attr_accessor: name,: Location def initialize (player_name) @ name = player_name endendclass room # create Get Set Method # Save name, description, connection method with other rooms, for reference of other room connections attr_accessor: reference,: name,: description,: connections def initialize (reference, name, description, connections) @ reference = reference @ name = Name @ description = Description @ connections = connections end def full_description "# {@ name} \ n at # {@ description}" endend # mainmy_dungeon = dungeon. new ("Larry") # Add roomsmy_dungeon.add_room (: largecave, "big cave", "big, empty cave", {: West = >: smallcave}) my_dungeon.add_room (: smallcave, "", ", ", {: East = >:largecave}) # startmy_dungeon.start (: largecave) my_dungeon.go (: West) my_dungeon.go (: east)
Running result:
Great cave
In a big, empty cave
Go to West
Little cave
In a small, closed cave
Go to East
Great cave
In a big, empty cave