Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4004534
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:17:06+00:00 2026-05-20T08:17:06+00:00

I am stuck on the part in chapter 6. It is a dungeon text-adventure

  • 0

I am stuck on the part in chapter 6. It is a dungeon text-adventure game with rooms and a player that moves around. I keep getting a noMethod error for the .detect method used in the find_room_in_dungeon method. I assume that I am probably missing something but I just can’t figure out what. I would really appreciate if someone could help me out. thanks.

class Dungeon
  attr_accessor :player

  def initialize(player_name)
    @player=Player.new(player_name)
    @room  = []
  end

  def add_room(reference, name, description, connections)
    @room << Room.new(reference, name, description, connections)
  end

  def start(location)
    @player.location=location
    show_current_description
  end

  def show_current_description
    puts find_room_in_dungeon(@player.location).full_description
  end

  ###
  def find_room_in_dungeon(reference)
    @rooms.detect { |room| room.reference == reference }
  end
  ###

  def find_room_in_direction(direction)
    find_room_in_dungeon(@player.location).connections[direction]
  end

  def go(direction)
    puts "you go " + direction.to_s
    @player.location= find_room_in_direction(direction)
    show_current_description
  end

  class Player
    attr_accessor :name, :location

    def initialize(name)
      @name = name
    end

  end

  class Room
    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/n you are in" + @description
    end

  end
end
my_dungeon= Dungeon.new("adventurer")
my_dungeon.add_room(:largecave, "large cave", "a very large cave", {:west => :smallcave})
my_dungeon.add_room(:smallcave, "smallcave", "a small cave", {:east => :largecave})
my_dungeon.start(:largecave)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T08:17:07+00:00Added an answer on May 20, 2026 at 8:17 am

    You called the variable @room when you assigned it and when you access it in add_room, but @rooms when you try to access it in find_room_in_dungeon. If you rename it to be the same in all three cases, it will work.

    I would suggest naming the variable @rooms everywhere rather than @room as it is an array of (possibly) multiple rooms, not a single room.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working through the Grails in Action book, and I'm stuck at that part
I'm writing a function that automatically inserts some text under certain conditions. I stuck
I'm working on an assignment and I'm getting stuck on one part of it,
I am currently stuck at the part whenever I drag a HTML5 slider, it
I am currently stuck on the part where user use his username and password
I'm doing a homework in MARS simulator (Assembly) and I'm stuck on one part.
I just started out with RequireJS, but i'm stuck at the part where i
I am trying to code this algorithm. I am stuck in the part of
So im stuck on a few things in each part below, they are pretty
I'm stuck on one thing i can't get solved. I have part of code,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.