代写Eric Robert、代做java/python编程语言、代做AdvRoom代做Processing|代写Web开发

Adventure Credit: Eric RobertsINTRODUCTIONYour mission in this assignment is to write a simple text-based adventure game in the tradition of WillCrowther’s pioneering “Adventure” program of the early 1970s. In games of this sort, the player wandersaround from one location to another, picking up objects, and solving simple puzzles. The program you willcreate for this assignment is considerably less elaborate than Crowther’s original game and it thereforelimited in terms of the type of puzzles one can construct for it. Even so, you can still write a program thatcaptures much of the spirit and flavor of the original game.Because this assignment is large and detailed, it takes quite a bit of writing to describe it all. This handoutcontains everything you need to complete the assignment, along with a considerable number of hints andstrategic suggestions. To make it easier to read, the document is divided into the following sections:Overview of the adventure game1. Overview of Adventure2. The Adventure class3. The AdvRoom and AdvMotionTableEntry classes4. The AdvObject class5. Implementing the adventure game6. Strategy and tactics7. MilestonesTry not to be daunted by the size of this handout. The code is not as big as you might think. If you startearly and follow the suggestions in the “Strategy and tactics” section, things should work out well.Section 1: Overview of Adventure The adventure game you will implement for this assignment takes place in a virtual world in which you,as the player, move about from one location to another. The locations, which are traditionally called“rooms” even though they may be outside, are described to you through a written textual descriptionthat gives you a sense of the geography. You move about in the game by giving commands, most of whichare simply an indication of the direction of motion. For example, in the classic adventure game developedby Willie Crowther, you might move about as follows:In this example, you started outside the building, followed the road up the hill by typing WEST, and arrivedat a new room on the top of the hill. Having no obvious places to go once you got there, you went backtoward the east and ended up outside the building again. As is typical in such games, the completedescription of a location appears only the first time you enter it; the second time you come to the building,the program displays a much shorter identifying tag, although you can get the complete description bytyping LOOK, as follows:From here, you might choose to go inside the building by typing IN, which brings you to another room, asfollows:In addition to the new room description, the inside of the building reveals that the adventure game alsocontains objects: there is a set of keys here. You can pick up the keys by using the TAKE command, whichrequires that you specify what object you’re taking, like this:OVERVIEW OF THE DATA FILESThe adventure program you will create for this assignment is entirely data driven. The program itselfdoesn’t know the details of the game geography, the objects that are distributed among the variousrooms, or even the words used to move from place to place. All such information is supplied in the formof data files, which the program uses to control its own operation. If you run the program with differentdata files, the same program will guide its players through different adventure games.To indicate which data files you would like to use, the adventure program begins by asking you for thename of an adventure. To get the adventure game illustrated above, you would begin by typing Crowther,which selects the collection of files associated with a relatively sizable subset of Will Crowther’s originaladventure game. For each adventure, there are three associated data files that contain the name of theadventure as a prefix. For the Crowther adventure, for example, these files are CrowtherRooms.txt, which defines the rooms and the connections between them. In theseexamples, you have visited three rooms: outside of the building, the top of the hill, and the insideof the well house. CrowtherObjects.txt, which specifies the descriptions and initial locations of the objects in thegame, such as the set of keys. CrowtherSynonyms.txt, which defines several words as synonyms of other words so you can usethe game more easily. For example, the compass points N, E, S, and W are defined to be equivalentto NORTH, EAST, SOUTH, and WEST. Similarly, if it makes sense to refer to an object by more thanone word, this file can define the two as synonyms. As you explore the Crowther cave, forexample, you will encounter a gold nugget, and it makes sense to allow players to refer to thatobject using either of the words GOLD or NUGGET.These data files are not programs, but are instead text files that describe the structure of a particularadventure game in a form that is easy for game designers to write. The adventure program reads thesefiles into an internal data structure, which it then uses to guide the player through the game.Your program must be able to work with any set of data files that adhere to the rules outlined in thishandout. In addition to the three files with the Crowther prefix, the starter folder also contains filenamed TinyRooms.txt that contains only three rooms with no objects and no synonyms and a set ofthree files with the prefix Small that define a much smaller part of the Crowther cave. Your programshould work correctly with any of these files, as well as other adventure games that you design yourself.The detailed structure of each data file is described later in this handout in conjunction with thedescription of the module that processes that particular type of data. For example, the rooms data file isdescribed in conjunction with the AdvRoom class.OVERVIEW OF THE CLASS STRUCTUREThe adventure game is divided into the following principal classes: Adventure - This class and is by far the largest module in the assignment. This class is yours towrite, but the public methods are specified in the starter files. AdvRoom - This class represents a single room in the cave. This class is also yours to write. Theprivate methods that decompose parts of the operation are yours to design, but the specificationof the public methods used to communicate with other modules is specified. This class is closelylinked with the AdvMotionTableEntry class, which is described in the same section. Thatclass is provided as part of the starter project. AdvObject - This class represents one of the objects in the cave. As with the AdvRoom class,you have to implement this class although the public methods are specified. AdvMotionTableEntry - This class defines a record type that combines a direction of travel,the room one reaches by moving in that direction, and an optional object that enables the motion.The definition of this class is extremely simple and is provided in the starter project.The structure of each of these classes is described in detail in one of the sections that follow.Even though the code for these components is substantial, your job is made easier since most of themethods used to communicate among the classes have already been designed for you. The publicmethods in the AdvRoom and AdvObject classes are completely specified; all you need to do isimplement them.Section 2: The Adventure Class The main program class is called Adventure and will contain most of the code you have to write for thisassignment. This class is in charge of the following: opening the data files assembling the data structures, maintaining the list of words known by the game interacting with the user implementing the various commandsFor the most part, you will have the opportunity to figure out how to decompose the entire operationinto reasonably-sized pieces and for choosing what data structures and methods to use in the underlyingimplementation. The below is the header file for the Adventure class.class Adventure{public:// No other public functions are needed.Adventure();Adventure(string objfile, string rmfile, string cmdfile);void Play();private:// Loading functionsvoid LoadObjects(string filename);void LoadRooms(string filename);void LoadSynonyms(string filename);// You should will need additional commands// other than the quit, help, and move commands.// Some of the commands should take arguments.// For some it may be helpful to return values.// You should only make functions for built-in commands.// For example, you should NOT make one for WAVE.void GetUserCmd(string &verb, string &obj);void QuitCmd();void HelpCmd();int MotionCmd(string motionName);// You will need some attributes to keep// track what room the player is currently in// and what objects are currently being held.// You should have some methods to help you// print the room and objects.// You will also need attributes to store// objects and rooms.struct Synonym {string word;string synonym;};vector synonyms;string GetSynonym(string str);};This class contains only one public method, which is the play method. It has the following responsibilities:1. Read in the data files for the game into an internal data structure2. Play the game by reading and executing commands entered by the userUnderstanding how to implement these aspects of the game, however, requires you to learn more aboutthe AdvRoom and AdvObject classes, which are described in the next two sections. Section 5 thenreturns to the question of how to implement the Adventure class, which represents the lion’s share of theassignment.Section 3: AdvRoom and AdvMotionTableEntry The AdvRoom class represents an individual room in the cave. Each room in the cave is characterized bythe following properties: A room number, which must be greater than zero Its name, which is a one-line string identifying the room Its description, which is a multiline array describing the room A list of objects contained in the room A flag indicating whether the room has been visited A motion table specifying the exits and where they leadThe AdvRoom stores this information in its private data structure and then makes that informationavailable to clients through the public methods of the class. These methods are listed in the starter files.The following is the header file:class AdvRoom{public:AdvRoom();bool readRoom(ifstream &roomFile); // Reads room data from an open file. Returns true if successful.vector getDescription(); // Return the room description.string getName(); // Returns the room name.void addObject(AdvObject obj); // Adds an object to the room.AdvObject removeObject(string objName); // Removes an object with name objName and returns the object.AdvObject getObject(int index); // Returns object index from the room.int objectCount(); // Returns how many objects are in the room.bool containsObject(string objName); // Return true if the room contains an object with objName.bool hasBeenVisited(); // Returns true if the room has been visited. False otherwise.void setVisited(bool flag); // Sets if the room has been visited.vector getMotionTable(); // Returns a motion table for the room.int getRoomNumber(); // Returns the room number.private:// Put the room properties here.};THE ROOMS DATA FILEThe information for the individual rooms is not part of the program but is instead stored in a data file. Oneof your responsibilities in completing the implementation of the AdvRoom class is to write the methodreadRoom(roomFile), which creates a new AdvRoom object by reading that description from therooms file for that adventure. For example, TinyRooms.txt looks like this:1Outside buildingYou are standing at the end of a road before a small brickbuilding. A small stream flows out of the building anddown a gully to the south. A road runs up a small hillto the west.-----WEST 2UP 2NORTH 3IN 32End of roadYou are at the end of a road at the top of a small hill.You can see a small building in the valley to the east.-----EAST 1DOWN 13Inside buildingYou are inside a building, a well house for a large spring.-----SOUTH 1OUT 1In thinking about an adventure game - particularly as the player, but also as the implementer - it isimportant to recognize that the directions are not as well behaved as you might like. There is no guaranteethat if you move from one room to another by moving north, you will be able to get back by going south.The best way to visualize the geographic structure of an adventure game is as a collection of rooms withlabeled arrows that move from one room to another, as illustrated by the following diagram of theconnections defined in TinyRooms.txt:The connections in this graph are modeled using the AdvMotionTableEntry class, which is describedin a subsequent section.EXTENSIONS TO THE CONNECTION STRUCTUREIf the adventure program allowed nothing more than rooms and descriptions, the games would beextremely boring because it would be impossible to specify any interesting puzzles. For this assignment,you are required to make the following extensions to the data structure that provide a basis for designingsimple puzzles that nonetheless add significant interest to the game: Locked passages. The connection data structure must allow the game designer to indicate that aparticular connection is ava代写Eric Robert作业、代做java/python编程语言作业、代做AdvRoom留学生作业 代做留学生Procilable only if the player is carrying a particular object. That object thenbecomes the key to an otherwise locked passage. In the file format, such locked passages are specified byadding a slash and the name of an object after a room number. Forced motion. If the player ever enters a room in which one of the connections is associated with themotion verb FORCED, the program should display the long description of that room and then immediatelymove the player to the specified destination without waiting for the user to enter a command. This featuremakes it possible to display a message to the player and is in fact identical to the design that WillieCrowther adopted in his original adventure game.Both of these features are illustrated by the segment of the SmallRooms.txt data file shown in at thebottom of this page. If the player is in room 6, and tries to go down, the following two lines in theconnection list come into play:DOWN 8 KEYSDOWN 7The first line is active only if the player is carrying the keys. In this case, the player moves into room 8which is the beginning of the underground portion of the cave. If not, the DOWN command takes the userto room 7. Because the motion entries include the verb FORCED, the program prints out the longdescription for room 7 and then moves the player back to room 6, as shown in the following sample run:6Outside grateYou are in a 25-foot depression floored with bare dirt.Set into the dirt is a strong steel grate mounted inconcrete. A dry streambed leads into the depression fromthe north.-----NORTH 5UP 5DOWN 8 KEYSDOWN 77Above locked grateThe grate is locked and you dont have any keys.-----FORCED 68Beneath grateYou are in a small chamber beneath a 3x3 steel grate tothe surface. A low crawl over cobbles leads inward tothe west.-----UP 6OUT 6IN 9WEST 9It is possible for a single room to use both the locked passage and forced motion options. TheCrowtherRooms.txt file, for example, contains the following entry for the room just north of thecurtain in the building:The effect of this set of motion rules is to force the user to room 71 if that user is carrying the nugget andto room 76 otherwise. When you are testing your code for locked and forced passages, you might wantto pay particular attention to the rooms in the CrowtherRooms.txt that implement the shimmeringcurtain that marks the end of the game.THE ADVMOTIONTABLEENTRY CLASSThere are several possible strategies one might have chosen to represent the table of connections in eachroom to its neighbors. In this assignment, you should store the room connections as a vector of objectseach of which is an instance of the class AdvMotionTableEntry. The complete definition of this classis included with the starter file. You could easily have designed this class yourself, but its implementationis so simple that doing so would not have helped you learn anything important. Because the class appearsas the result type of a public method, it seemed easier simply to provide it to you directly.70Curtain1-----FORCED 71 NUGGETFORCED 76Section 4: The AdvObject Class The AdvObject class keeps track of the information about an object in the game. The amount ofinformation you need to maintain for a given object is considerably less than you need for rooms, whichmakes both the internal structure and its external representation as a data file much simpler. The entriesin the object file consist of three lines indicating the word used to refer to the object, the description ofthe object that appears when you encounter it, and the room number in which the object is initiallylocated. For example, the data file SmallObjects.txt looks like this:This file indicates that the keys start out in room 3 (inside the building), the lamp initially resides in room8 (beneath the grating), and the rod can be found in room 12 (the debrisroom). The entries in the file maybe separated with blank lines for readability, as these are here; your implementation should work equallywell if these blank lines are omitted.The objects, of course, will move around in the game as the player picks them up or drops them. Yourimplementation must therefore provide a facility for storing objects in a room or in the user’s inventoryof objects. The easiest approach is to use a vector, which makes it easy to add and remove objects usingthe push_back and pop_back functions. To remove an element from somewhere in the middle of alist, you can swap the element with the back element and then pop the back element.The header file for the AdvObject class appears below. The implementation of these methods shouldbe quite straightforward, particularly in comparison to those in the AdvRoom class, which is significantlymore complicated.KEYSa set of keys3LAMPa brightly shining brass lamp8RODa black rod with a rusty star12#include #include #include #include #include using namespace std;class AdvObject{public:AdvObject();AdvObject(string objName, string objDes, int loc);bool readObject(ifstream &objFile);string getName();string getDescription();int getInitialLocation();private:// Add your private variables here...};Section 5: Implementing the Adventure Game As noted in the introduction to this assignment, implementing the Adventure class represents the lion’sshare of the work. Before you start in on the code, it will simplify your life considerably if you spend sometime thinking about the data structures you need and what the overall decomposition looks like.The play method for the Adventure class must execute each of the following steps:1. Read data files for the game into an internal data structure2. Play the game by reading and executing commands entered by the userREADING IN THE DATA FILESOnce you have the name of the adventure, the next phase in the program is to read in the data files thatcontain all the information necessary to play the game. As noted in the section entitled “Overview of thedata files” on page 3, every adventure game is associated with three text files whose names begin withthe adventure name. For example, if the adventure name is Crowther, these files are namedCrowtherRooms.txt, CrowtherObjects.txt, and CrowtherSynonyms.txt. The formats of the first two fileshave already been described in the discussion of the AdvRoom and AdvObject classes.Each of those classes, moreover, includes a method that reads the data for one room or one object froman ifstream. All the Adventure class has to do, therefore, is1. Open the appropriate file to obtain the ifstream object.2. Create an empty data structure for the rooms or objects, as appropriate.3. Call AdvRoom.readRoom or AdvObject.readObject to read in a new value.4. Add the new room or object to their respective vectors.5. Repeat steps 3 and 4 until readRoom or readObject returns false.6. Close the file.The rooms file must be present in every adventure, and your program should print an appropriate errormessage if that file is missing. If the objects file is missing—as it is for the Tiny adventure—your programshould simply assume that there are no objects.The only file whose format you haven’t seen is the synonyms file, which is used to define abbreviationsfor commands and synonyms for the existing objects. The synonym file consists of a list of lines in whichone word is defined to be equal to another. The CrowtherSynonyms.txt file shows that you can abbreviatethe INVENTORY command to I or the NORTH command to N. Similarly, the user can type GOLD to referto the object defined in the object file as NUGGET. As with the objects file, the synonyms file is optional.If it doesn’t exist, your program should simply assume that there are no synonyms.Each line of the synonyms file consists of two strings separated by a space. You can separate the stringinto its component pieces in any of a number of ways. A data structure is provided for you to store a wordand its associated synonym.EXECUTING COMMANDSOnce you have read in the data, you then need to play the game. The user by default will always start inroom 1 and then move around from room to room by entering commands on the console. The process orreading a command consists of the following steps:1. Get a line from the user.2. Break the line up into a verb representing the action and an object (if specified) indicating thetarget of that action. In the game you have to write, the object is relevant only for the TAKE andDROP commands, but your extensions might add other verbs that take objects as well. In thisphase, you should make sure to convert the words to uppercase and check the synonyms table toensure that you’re working with the canonical form of each word. For example, if the user entersthe line> release goldyour program should decide that the verb is DROP and the object is NUGGET. Having a dedicatedmethod for this job is recommended.3. Decide what kind of operation the verb represents. If the word appears in the motion table forsome room, then it is a motion verb. In that case, you need to look it up in the motion table forthe current room and see if it leads anywhere from the current room. If it isn’t a motion verb, theonly legal possibilities (outside of any extensions you write) is that it is one of the six built-in actionverbs: QUIT, HELP, LOOK, INVENTORY, TAKE, and DROP. In you have an action verb, you have tocall a method that implements the appropriate action, as outlined in the following section. In anyother case, you need to tell the user that you don’t understand that word.An easy way to implement this is a cascading if statement that first checks if the verb is QUIT, thenchecks to see if it’s HELP, and so on.QUIT This command signals the end of the game. Your program should stop reading commandsand exit from the run method.HELP This command should print instructions for the game on the console. You need notduplicate the instructions from the stub implementation exactly, but you should certainlygive users an idea of how your game is played. If you make any extensions, you shoulddescribe them in the output of your HELP command so that we can easily see whatexciting things we should look for.INVENTORY This command should list what objects the user is holding. If the user is holding no objects,your program should say so with a message along the lines of “You are empty-handed.”LOOK This command should type the complete description of the room and its contents, evenif the user has already visited the room.TAKE obj This command requires a direct object and has the effect of taking the object out of theroom and adding it to the set of objects the user is carrying. You need to check to makesure that the object is actually in the room before you let the user take it.DROP obj This command requires a direct object and has the effect of removing the object from theset of objects the user is carrying and adding it back to the list of objects in the room. Youneed to check to make sure that the user is carrying the object.Section 6: Strategy and Tactics Even though the adventure program is big, the good news is that you do not have to start from scratch.You instead get to start with a complete program that solves the entire assignment because each of theclasses you need to write is implemented as a subclass of a library stub that performs all of the necessaryfunctions. Your job is simply to replace all of the stubs with code of your own.The following suggestions should enable you to complete the program with relatively little trouble: Start as soon as possible!!!! The deadlines are bare minimum targets in order to finish on time. You have the entireassignment and there is nothing preventing you from moving onto the next parts once you aredone with a milestone. Ideally, you finish early and maybe complete a few extra creditextensions. Get each class working before you start writing the next one. Work on the classes one at a time,and debug each one thoroughly before moving on to the next. My suggestion is to start withAdvObject and AdvRoom, and then to move on to the more difficult implementation ofAdventure itself. Use the smaller data files for most of your testing. Don’t try to test your code on the Crowtherdata files. These files take time to read in and are complicated only because of their scale. TheTiny data files are appropriate for the basic functionality, and the Small data files haveexamples of every required feature. When you finish your implementation, it makes sense to trythe larger data files just to make sure everything continues to work in the larger context.Section 7: MilestonesPART A Complete AdvObject Complete AdvRoom Complete the load functions in the Adventure class. (HINT: look at the debug functions) Complete the Constructors for the Adventure class.There are some debugging methods provided for you to test these classes.PART B� Complete the GetUserCmd method Initialize the player to stand in the first room and have user input possible. You should have at aminimum the HELP, QUIT, and LOOK commands usable:PART CThe full program should be functional for part C. I suggest completing the following order for tasks: Movement/Verbs in the room (i.e. EAST, SOUTH, WHISTLE, etc). INVENTORY command Picking up objects/Dropping objects Checking for Synonyms转自:http://ass.3daixie.com/2018112882668316.html

你可能感兴趣的:(代写Eric Robert、代做java/python编程语言、代做AdvRoom代做Processing|代写Web开发)