Skip to content

Instantly share code, notes, and snippets.

@mfifth
Created October 9, 2015 23:14
Show Gist options
  • Save mfifth/d0f7c96d68c232e4d562 to your computer and use it in GitHub Desktop.
Save mfifth/d0f7c96d68c232e4d562 to your computer and use it in GitHub Desktop.
class Dungeon
attr_accessor :player #Is this an instance variable? or a class variable?
def initialize(player_name) #Why is this here?
@player = Player.new(player_name) #What is this code doing?
@rooms = [] #Why is there an "@" before rooms? This isn't an instance variable is it?
end
def add_room (reference, name, description, connections)
@rooms << Room.new(reference, name, description, connections)
end
def start(location) #Where is "location" defined? What does it do?
@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) #What is this method doing?
@rooms.detect{|room| room.reference == reference}
end
def find_room_in_dungeon(direction)
find_room_in_dungeon(@player.location).connections[direction]
end
def go(direction)
puts "You go " + direction.to_s #Why are we converting this to a string?
@player.location = find_room_in_direction(direction) #How does this line of code work?
show_current_description
end
class Player
attr_accessor :name, :location
def initialize(name)
@name = name
end
return self
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\nYou are in " + @description
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment