Skip to content

Commit

Permalink
Framework done
Browse files Browse the repository at this point in the history
  • Loading branch information
MrCoffey committed Oct 16, 2014
1 parent 3e30da7 commit 5c5716a
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions dungeon.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
class Dungeon
attr_accessor :player

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

=begin
/*Those classes aren't necessary due the Struct is suppling
Expand All @@ -20,6 +12,14 @@ def initialize(player_name)
Room = Struct.new(:reference, :name, :description, :connections)
=end

class Dungeon
attr_accessor :player

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

#This add a new Room to @rooms array
def add_room(reference, name, description, connections)
@rooms << Room.new(reference, name, description, connections)
Expand All @@ -29,14 +29,14 @@ def add_room(reference, name, description, connections)
def start(location)
@player.location = location
show_current_description
end
end

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

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

def find_room_in_direction(direction)
Expand All @@ -52,8 +52,8 @@ def go(direction)
class Player
attr_accessor :name, :location

def initialize(player_name)
@name = player_name
def initialize(name)
@name = name
end
end

Expand All @@ -70,18 +70,19 @@ def initialize(reference, name, description, connections)
def full_description
@name + "\n\nYou are in " + @description
end

end
end


# Create the main dungeon object
my_dungeon = Dungeon.new("Fred Bloggs")

#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})
# Add rooms to the dungeon
my_dungeon.add_room(:largecave, "Large Cave", "a large cavernous cave", { :west => :smallcave })
my_dungeon.add_room(:smallcave, "Small Cave", "a small, claustrophobic cave", { :east => :largecave })

# Start the dungeon by placing the player in the large cave
my_dungeon.start(:largecave)

end



0 comments on commit 5c5716a

Please sign in to comment.