Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Lab 4: Implementing Exits and Command Interpreters in a Room Environment, Lab Reports of Computer Science

The steps to implement exits between rooms and functional command interpreters in a room environment. The process involves modifying the xml file to include exits, parsing the file in a two-pass manner, creating a constructor for room that takes a list of exits, and adding a method to generate pointers to destination rooms. Once all rooms are built, generateexits should be called for each room. After exits are working, modify the command interpreter to accept exit commands and create a hierarchy for command interpretation.

Typology: Lab Reports

Pre 2010

Uploaded on 07/22/2009

koofers-user-x6k
koofers-user-x6k 🇺🇸

4

(2)

10 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Lab #4
Summary
Our goal this week is to get Exits working throughout our application,
and have our Command Interpreters functioning throughout the
application as discussed in class. The first step would be to modify our
XML file to include exits between rooms. As discussed in class, these
exits can either be relative or absolute paths to other rooms in the
environment. The parsing of this file will be done in a “two-pass”
manner. This does not necessarily mean that you will parse the XML
file twice, but rather that you need to temporarily do something with
the exits while you are parsing the XML file. Then once all the rooms
are built, you can go back through and add exits to them. A good
solution to this might be to change the constructor for Room to take a
list of exits in their relative or absolute path form. Then add a method
to Room called generateExits which actually creates the pointers to the
destination Rooms. Once you have finished building all the Rooms in
the Environment, go back and call generateExits for each Room. At
this point in time, all the possible destination Rooms should be created
and creating a pointer to them should be possible.
Once this is working, modify your command interpreter to accept exit
commands. Maybe north,south,east,west or something similar to this.
Once you can successfully exit a Room and arrive at a new Room, then
modify your command interpreter structure as we discussed in class.
Every Environment, Area, and Room can have a command interpreter
associated with it. When one issues a command, it should try to get
interpreted by the Room they are in first. If it can’t be interpreted
there, it should work its way up the hierarchy until it is either
interpreted or gets to the top and can then be deemed an invalid
command.

Partial preview of the text

Download Lab 4: Implementing Exits and Command Interpreters in a Room Environment and more Lab Reports Computer Science in PDF only on Docsity!

Lab # Summary Our goal this week is to get Exits working throughout our application, and have our Command Interpreters functioning throughout the application as discussed in class. The first step would be to modify our XML file to include exits between rooms. As discussed in class, these exits can either be relative or absolute paths to other rooms in the environment. The parsing of this file will be done in a “two-pass” manner. This does not necessarily mean that you will parse the XML file twice, but rather that you need to temporarily do something with the exits while you are parsing the XML file. Then once all the rooms are built, you can go back through and add exits to them. A good solution to this might be to change the constructor for Room to take a list of exits in their relative or absolute path form. Then add a method to Room called generateExits which actually creates the pointers to the destination Rooms. Once you have finished building all the Rooms in the Environment, go back and call generateExits for each Room. At this point in time, all the possible destination Rooms should be created and creating a pointer to them should be possible. Once this is working, modify your command interpreter to accept exit commands. Maybe north,south,east,west or something similar to this. Once you can successfully exit a Room and arrive at a new Room, then modify your command interpreter structure as we discussed in class. Every Environment, Area, and Room can have a command interpreter associated with it. When one issues a command, it should try to get interpreted by the Room they are in first. If it can’t be interpreted there, it should work its way up the hierarchy until it is either interpreted or gets to the top and can then be deemed an invalid command.