Skip to content

Commit

Permalink
Addind new rooms
Browse files Browse the repository at this point in the history
  • Loading branch information
MrCoffey committed Oct 16, 2014
1 parent 5c56e5e commit e07991d
Showing 1 changed file with 54 additions and 4 deletions.
58 changes: 54 additions & 4 deletions dungeon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,50 @@ def initialize(player_name)
@player = Player.new(player_name)
@rooms = []
end

=begin
Those classes aren'n necessary due the Struct
/*Those classes aren't necessary due the Struct is suppling
/*their functions.
/*
/*If you ever need to add methods to Player or Room, you can uncomment them
/*and add the attributes back with attr_accessor.
/*
/*Struct were changed for entire class due they change their objects
Player = Struct.new(:name, :location)
Room = Struct.new(:reference, :name, :description, :connections)
=end

#This add a new Room to @rooms array
def add_room(reference, name, description, connections)
@rooms << Room.new(reference, name, description, connections)
end

#This make the dungeon work
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

Expand All @@ -25,8 +66,17 @@ def initialize(reference, name, description, connections)
@description = description
@connections = connections
end
end
=end
Player = Stru

def full_description
@name + "\n\nYou are in" + @description
end

end


#Adding new rooms
my_dungeon.add_room(:largecave, "Large Cave", "a large cavernous cave", {:west => :smallcave})
my_dungeon.add_room(:smallcave, "Small Cave", "a small, claustrophobic cav", {:east => :largecave})

end

0 comments on commit e07991d

Please sign in to comment.