Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Ruby Colossal Cave: https://en.wikipedia.org/wiki/Colossal_Cave_Adventure For th

ID: 3863560 • Letter: R

Question

Ruby

Colossal Cave: https://en.wikipedia.org/wiki/Colossal_Cave_Adventure

For this exercise complete the simple Dungeon game in the Inital Dungeon code. This is a fun way to learn about using classes and objects. You’ll be learning about a new type of Ruby data structure called the Struct class(p. 139) – it’s a simple was to create a data structure that is sometime preferable to using a class.

You’ll notice that the Dungeon game is one large class with several nested classes within it: Player and Room. All of the action takes place inside of the Dungeon class.

There may be several points in putting the dungeon code together that you will have to re-factor the code. Be sure to follow instructions carefully.

Assemble the Dungeon from the code given the Inital Dungeon code into a file named dungeon.rb.

Add at least two more rooms to your dungeon.

Run your code and capture the output into a file named dungeon.txt.

Inital Dungeon code:

class Dungeon attr_accessor :player def initialize(player_name) @player = Player.new(player_name) @rooms = [] end class Player attr_accessor :name, :location def initialize(player_name) @name = player_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 end end doug@theLinuxPC:lhome/doug/Dropbox/sass master n/Dropbox/sass master adventure Welcome to Adventure Would you like instructions? Somewhere nearby is Colossal Cave, where others have found fortunes in treasure and gold, though it is rumored that some who enter are never seen again. Magic is said to work in the cave I will be your eyes and hands Direct me with commands of 1 or 2 words I should warn you that I look at only the first five letters of each word, so you'll have to enter northeast" as "ne" to distinguish it from "north". (Should you get stuck, type "help" for some general hints For information on how to end your adventure etc., type "info".) This program was originally developed by Will Crowther Most of the features of the current program were added by Don Woods. Address complaints about the UNIX version to Jim Gillogly (jimorand.org). You are standing at the end of a road before a small brick building. Around you is a forest. A small stream flows out of the building and down a gully. Figure 1 Colossal Cave (1976) was a text adventure game that ran on mainframe computers. The Dungeon game we'll build is a very simple version of it

Explanation / Answer

#add a starting location

#tell adventurer to take a look around

#recreate adventurer using this new helper

#we can define new methods by assigning a lambda to an attribute

#give it the ability to move from location to location.

#This method will take a direction (like :east), and attempt to move to the new location using the exits association on its current location

#add destination room

#we create a prototypical room