Informatics 1 WS 2014/15

Website of Prof. Dr. Barne Kleinen, Professor for Media Informatics (Bachelor/Master) at HTW Berlin

Exercise 11: Keeping Track of Stuff

     <prev next>

Pre-lab

This week’s lab work will continue a larger project that will occupy us until the end of the semester.

What to Bring to Lab

Please bring these exercises printed out or written out with you to lab.

P1. What items could be kept in the locations in your game? Come up with a list of at least 10 items. How heavy is each item?

P2. What will the starting position of the items be? List which items are going to be in which place.

Post-Lab, AKA What To Turn In

Your completed assignment, submitted in Moodle as a pdf, should include:

  • A description of what you did during the lab, including a record of what worked, what problems you encountered, and answers to the questions asked in the pre-lab. The focus is on the process!
  • Include the current version of your source code.
  • The names and roles of any collaborators in any parts of the exercise.
  • A record of how long you needed for this lab and what you learned.

I have been asked to skip the report for those last two exercises to spare you the time; I’ve decided against it:

  • reflecting about what you did and learned is an important part of the learning process. It’s not just about getting the code to run!

  • But: The lab report can be rather short. Is is mainly for yourself, to reflect and track your learning process. You don’t have to note down every single step. Just take a couple of minutes to reflect on your learnings, and things you struggled with. And your co-workers :)


Assignment

Adding Items

  1. Extend your project so that a room can contain a single item. Items have descriptions and weights. When creating rooms and setting their exits, items for this game should also be created. When a player enters a room, information about an item present in this room should be displayed.
  2. How should the information about an item present in a room be produced? Which class should produce the string describing the item? Which class should print it? Why? If answering this exercise makes you feel you should change your implementation, go ahead and do so – and explain in your report why.
  3. Modify the project so that a room can hold any number of items. Use a collection to do this! Make sure the room has an addItem method that places an item into the room. Make sure all items get shown when a player enters a room. Set up a fixture to thoroughly test this!
  4. Implement a “back” command that does not have a second word and takes the player back into the previous location. Test this! What happens if a second word is given?
  5. (For the bored) What happens if you type “back” twice? Is this behavior sensible? Implement it so that using it repeatedly takes you back several rooms, all to the beginning of the game if used often enough. Use a Stack data structure, even if we don’t know about them yet. You can read about them in the API.
  6. (for the bored): Add at least two specialized Items to the game, using inheritance. For instance, add Food, Weapons and Clothing in a classical Role-Playing-Game. Each of these specializations (Subclasses) should have at least one special field.

Writeup

Submit your writeup as your post-lab to the Moodle area by 23.00 the day before the next lab.