CMSC 335 Summer 2016 Projects

Sorcerer's Cave - Thoughts

By Nicholas Duchon
Cave Project


Generally, the project should be what we call "in the Java spirit" - by which I mean defining and using classes, variables and methods appropriately. Some examples:
  1. You should ask yourself if it makes sense to instantiate a class more than once. This has implications for which variables should be local to a method, which methods should be instance vs class (static) and  which variables should be instance vs class.
  2. For example, if you are going to use a class like a Game class to contain everything, it makes sense to have more than one game, and each game could have its own data file.
  3. In a Game, some students have pointed out the there might be artifacts, treasures and creatures that are not part of any party. How should we handle these? I suggest a single data structure to handle the lot - an ArrayList is most appropriate, but that structure is generic, so what kind of generic declaration should we use, perhaps ArrayList <Object>, but that seems like a too general structure since we don't really want stuff like JLabel or JButton this structure. Thus, we are lead to proposing another class, say GameElement, and the other classes we have seen so far, Creature, Treasure and Artifact should extend this class, and then we can use the following declaration: ArrayList <GameElement> to hold stuff that is just lying around.
  4. On the other hand, when stuff comes out of a <GameElement> structure, it will probably need to be cast to allow insertion into a party. So perhaps a better solution is to have different ArrayList's for each type of item (artifact, treasure and creature) not currently in a party.
  5. Links? I use this word as shorthand for references to instances of other objects. To give you some idea of what I have in mind, you might consider the following example, particularly the graphics with it:

Stay tuned to this posting, I may have other thoughts as I respond to your questions.

Here is a figure showing how I envision the internal data structures corresponding to the same data file. The yellow are ArrayList's, and the various boxes are instances of the various classes, with the names of those instances as shown. I hope this makes it clearer about how the instances are related to each other, and how the entries in the data structures are supposed to work.

Here's the image: