Я застрял на части в главе 6. Это текстовая приключенческая игра с подземельями и игроком, который перемещается.Я продолжаю получать ошибку noMethod для метода .detect, используемого в методе find_room_in_dungeon.Я предполагаю, что я, вероятно, что-то упускаю, но я просто не могу понять, что.Буду очень признателен, если кто-нибудь сможет мне помочь.спасибо.
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)