|
|
HTW Berlin
Fachbereich 4
Internationaler Studiengang
Internationale Medieninformatik (Bachelor)
Info 1: Informatik I
Winter Term 2022/23
|
Laboratory
12 : Pick up and Carry
|
This week's lab work will finish up
your project.
What to Bring to Lab
Please bring these exercises printed out or written out with you to
lab. Please have your name on your page. You do the prelab for the game
you received from your neighbor last week.
P1. Here are some informal specifications: A player
must be able to pick up items from the current room. They can carry any
number of items, but only up to a maximum weight limit. Some items are
too heavy to be picked up. The player can drop one or all items in the
current location. What changes are you going to have to make to your
game? Don't program them yet, just specify the changes that need to be
made to each class in writing.
P2. There are (at least) two ways to make an item too
heavy to pick up. We can just make them very heavy, and define what the
maximum weight a player can pick up is. Or we can have a Boolean field canBePickedUp.
Which solution do you think is better? Why?
P3. What sort of a data structure are you going to use
to keep track of all the items a player has? Why?
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!
- A description of the changes your partner made to your code.
- Include the final 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.
This lab assignment is due by January 31,
2023, 22.00 at the latest.
Assignment
Picking up Items
- Switch your project back with the group you
swapped with last week. If you were working on the zuul-refactored game,
find someone else who was doing that and swap with them, either pairwise
or in a three-way swap. Read through the changes made and note down in
your report what was changed. If you got your own project back, are you
happy with the changes? If you got a zuul-refactored project, what was
changed here from the refactored one? Are you missing anything?
- If not already there, make sure there is an Item
class in the project you get back. Items have names, descriptions, and
weights. Make sure you can print out an item's description.
- Implement a command "take" that has the name of
the item as the second parameter. What happens if the item to be taken
is not in the room?
- Implement the command "drop" to get rid of an
item. "drop all" should do just that.
Carrying Items
- Implement the field to store the items
currently carried by the player. How is the maximum weight determined?
Does "take" know how to deal with this? You will probably need a method
to ask if the current item can be taken by the player.
- Implement an "items" command that prints out
all items currently carried with their weights, and the total weight.
Add a Non-Playing Character
- Create a class that represents a non-playing
character. This could be a ghost, or a monster, or just someone standing
around. Add one to one of your rooms. If a room has a NPC, this should
be noted when printing out the description of the room.
- Add a command "ask" to speak with the NPC. If
there is none in the room, then say so, otherwise the character needs to
say something interesting.
For the Bored - something to do over the
break
- Add a magic cookie item to a room. Add an "eat
cookie" command. If a player finds and eats the magic cookie, it
increases the weight that the player can carry. You may adapt this to
your game scenario
- Add some form of time limit to your game. If a
certain task is not completed in a specified time (or number of steps
through the rooms), the player loses.
- Implement a trapdoor - one that only goes one
way. Don't forget to sort out what happens with "back" on this exit.
- Have your NPC move to a random room.
- (For the really bored) Add a beamer to the
game. It can be charged, that is, it remembers the location it was
charged in. And it can be fired, returning the player automatically to
the remembered location. Remember to sort out back :)
- (To keep the bored busy over the break) Add
locked doors. Players have to find the key and unlock them before they
can continue. Add a transporter room that transports the player to a
random room. Add non-playing characters to the game - they are similar
to items, but they speak to you when you meet them in a room. They may
give you help if you are nice to them. Add moving characters. Add
monsters. Now refactor the processCommand
method, which is probably an unholy mess by now. Refactor and improve
the design to make it easy to add new commands.
Writeup
Submit your writeup as your post-lab to the
Moodle area by the final date given on the schedule.
Have a great vacation! You've learned a lot about
programming in these past few weeks. Keep playing with your game over the
break so you don't forget everything!
Copyright
Prof. Dr. Debora Weber-Wulff
Questions or comments:
<weberwu@htw-berlin.de>
Some rights reserved. CC-BY-NC-SA - Copyright and Warranty
The exercises are adapted from Objects First with Java, A Practical Introduction Using BlueJ. David Barnes & Michael Kölling, 2016