Hi There!

I'm Dan Schlegel, an Associate Professor in the Computer Science Department at SUNY Oswego

Assignment 6

In this final assignment, you will extend your game just a little bit and then add a feature of your choice, polish everything nicely, and package your project as a jar file for distribution to your friends and family. There are four parts; be sure to read and complete all four parts because we plan to play games on the last day of classes.

Part 1: Use a New Data Structure in Your Game

If your project uses an XML parser that you have written: your task here is to modify that XML parser to now allow for Items to have Items, and those subitems to have Items in turn – to any level! In particular, you should use the StackLL data structure that we wrote in class in your XML parser program to process the Items in an extended kind of xml data file, like what you might find in the attched excerpt. You can find a complete sample XML file of this new kind of castle here. Think about how you might use the stack data structure to keep track of which Item the sub-Items are inside.

The most interesting consequence of this change is the way the code must change to find sub-sub-. . . -sub-Items at varying levels when the human playing the game enters the instruction to inspect a thing by name. If you are not careful here, you might get lost in a recursive approach or have more cases (Item in Room, Item in Item, Item in Item in Item, . . . ) than possible to handle. One approach to simple logic for handling this is to have a second ArrayList of Items for each Room object that includes all Items in the room at any level. The creation of this second ArrayList would happen in the parser, and then the inspect instruction would look within this second ArrayList for the Item specified by the user.

If your project uses the parser that we wrote: your task here is to implement some cheat codes in your game using the HashMap data structure. The cheat codes that we have in mind will allow the player to see the contents of rooms they are not currently in. Specifically, you should modify your game so that Rooms are stored in a HashMap with name as the key. This will allow you to look up a room by its name without iterating through the whole list of Rooms. Then modify your Player class to accept the following commands:

  • cheatmode – enables the below two options.
  • look:[roomname] – prints out the contents of [roomname] by looking up the Room in the HashMap.
  • look:all – prints out the contents of all rooms, printed in alphabetical order by room name.
  • nocheatmode – disallows the use of the above two options.

Be sure you write unit tests to test your new functionality.

Part 2: New Feature

Add a new feature to your game. The feature should be fairly substantial and require changes to more than one of your classes. If you want to know if the feature you are considering is appropriate, feel free to ask. Ideally, you will choose one that you specified in the design portion of Assignment 5, but it doesn’t have to be one of those. Be sure to leave a document describing your new feature somewhere, along with the changes you made to implement it, so that I can try it out. Be sure to let me know where this document is!

Part 3: Polishing Everything Up

You should now get your game ready for ‘prime-time.’ In other words, be sure the messages the user receives are understandable and look good. Remove any debug output (like the contents of the XML file, or anything else like that you may have added that doesn’t have to do with the game). Be sure to test your game – play it for a bit and make sure you are happy enough with it that you wouldn’t mind putting it in front of some other people to play, other people whom you don’t even know!

Part 4: Create a jar file

Enable your project to build jar files by following the directions at this page, specifically the section to “create an executable jar”.

Once you have a jar file, open a terminal and run: java -jar yourjarfile.jar. Your game should run! When you submit, submit your jar along with your source file. If you need a special xml file to go with it, be sure to submit that too and give some instructions on how to start the game.