PROG2007 Assignment 2
Weight: 30% of your final mark
Due: XXXXXXXXXX20th September XXXXXXXXXX:00 pm
Specifications
Your task is to complete various exercises in BlueJ, using the Java language, and to submit these via
the MySCU link created for this purpose.
Marking criteria includes:
• Use of co
ect coding style, including the use of comments;
• Accuracy of coding;
• Use of suitable coding structures;
• Co
ect submission and naming conventions of assessment items as required.
Getting Help
This assignment is to be completed individually. It is the opportunity to gain an understanding of the
concepts of object-oriented programming and coding syntax. It is important that you master these
concepts yourself. You are permitted to work from the examples in the study guide or textbook, but
you must acknowledge assistance from other textbooks or classmates. In particular, you must not use
online material or help from others, as this would prevent you from mastering these concepts.
Who can you get help from? Use this diagram to determine from whom you may seek help with your
program.
Lecturer
Tutors
Online
Forums
Relatives
Students
outside unit
Hired
coders
Classmates
Private
Tutors
Othe
Encouraged
Attribution Required
Ask tutor
Not acceptable
Setting up your assignment
To set up your assignment, you will need to do the following:
• Create a folder called FirstNameLastName-A2.
• Copy the zuul-bad project in chapter 8 of the book projects to your
FirstNameLastName-A2 folder.
• Create a Word document called FirstNameLastName-A2-documentation. Add your
full name and student ID to the footer. Save this word document to your
FirstNameLastName-A2 folder.
After you have set up your assignment, open the zuul-bad project In BlueJ, create a new
instance of the Game class, run the play method and familiarise yourself with the game.
You should also:
• Review the code style guide in topic 7, as this is the style you will be required to use
in your assignment.
• Download chapter 6 of the textbook from topic 7 on MySCU, as you will need this for
the assignment.
Please Note:
• In the following parts of the assignment, the written exercises are to be done in the
FirstNameLastName-A2-documentation word document, and the programming
exercises are to be done in BlueJ.
• When you submit your assignment, you will need to zip up your FirstNameLastName-
A2 folder and upload it onto MySCU.
Designing your game
Using the given zuul-bad game as a starting point, you must design your own game. Some
possible game scenarios are described in Exercise 6.3 of the reference textbook. If you find it
difficult to visualise this sort of game scenario, try modelling your game on some familiar real-
world location. If you need additional inspiration, you can try playing the original Colossal
Cave Adventure game.
You must have the following in your game:
• Your game scenario must have at least nine (9) different rooms.
• Your game scenario must have at least six (6) types of exits - north, south, east, west,
up and down, and any other you require. This requirement does NOT mean that each
oom must have 6 exits.
• Your game scenario must include at least four (4) items that the player could find, pick
up and potentially use.
• The player can only ca
y a maximum of four (4) items in the player's inventory.
• Your game must have some way for the player to win. Most likely, this will be by
achieving some goal such as finding a particular item, surviving for some specified
number of moves, or exiting a particular room ... whatever makes sense for your game.
Written Exercise 1
Write a
ief description of your game in your word document. You must:
• Describe your game, including the back story and the setting of the game
• List the items in the game and how to use it
• Explain how the player wins
Written Exercise 2
Draw a map for your game scenario. You must:
• Label the rooms
• Label the exits (connections between rooms)
• Specify the locations of the items
The map can be hand-drawn. You do not need to use a drawing program, but your map must
e clearly readable. This map must also be placed in the Word document.
Written Exercise 3
Your game has 6 exits; however, the zuul-bad game only has 4 exits. Yours will also have more
ooms than zuul-bad, and they will have different names. Copy the following template into
your word document and replace the text for each of the methods. You must identify and
describe the changes you would need to make to the zuul-bad project to convert it into your
game. You need to consider the additional exits and rooms you have in your game.
DO NOT WRITE THE CODE…YOU WILL NOT GET ANY MARKS. You must identify and describe
the changes.
I have completed the Room class, so you can see what is required.
XXXXXXXXXXTEMPLATE START-------------------
Class Room
Instance variables
• Add an instance variables of type Room for the up exit
• Add an instance variables of type Room for the down exit
setExits method
• Add a parameter of type Room to the setExits method for the up exit
• Add a parameter of type Room to the setExits method for the down exit
• Add an if-statement to the setExits method to assign the up parameter to the up
instance variable
• Add an if-statement to the setExits method to assign the down parameter to the down
instance variable
getDescription method
• no changes needed
Class Game
Instance variables
• Replace this text. Identify and describe the changes you need to make to the instance
variables to add your additional exits and rooms in point form. If no changes are
needed, write no changes needed
createRooms method
• Replace this text. Identify and describe the changes needed in the createRooms
method to add your additional exits and rooms in point form. If no changes are
needed, write no changes needed
play method
• Replace this text. Identify and describe the changes needed in the play method to add
your additional exits and rooms in point form. If no changes are needed, write no
changes needed
printWelcome method
• Replace this text. Identify and describe the changes needed in the printWelcome
method to add your additional exits and rooms in point form. If no changes are
needed, write no changes needed
processCommand method
• Replace this text. Identify and describe the changes needed in the processCommand
method to add your additional exits and rooms in point form. If no changes are
needed, write no changes needed
printHelp method
• Replace this text. Identify and describe the changes needed in the printHelp method
to add your additional exits and rooms in point form. If no changes are needed, write
no changes needed
goRoom method
• Replace this text. Identify and describe the changes needed in the goRoom method to
add your additional exits and rooms in point form. If no changes are needed, write no
changes needed
quit method
• Replace this text. Identify and describe the changes needed in the quit method to add
your additional exits and rooms in point form. If no changes are needed, write no
changes needed
XXXXXXXXXXTEMPLATE FINISH-------------------
Written Exercise 4
The printWelcome method and the goRoom methods contain code duplication and both print
a description of the cu
ent room and a list of the exits. This is not a good design. Explain
why.
Programming exercise 1
Co
ect the problem of repeated functionality in the printWelcome and goRoom methods by
efactoring the repeated functionality out of these methods into a method of its own called
getRoomExitsAndDescription. Then call this new method in each place the description and
exits need to be displayed.
Written Exercise 5
In the previous exercise, you created the getRoomExitsAndDescription method that prints a
description of the cu
ent room and a list of the exits. This code is contained in the Game
class. This is not a good design. Explain why.
Programming exercise 2
• Refactor the code that generates the list of the exits into a method named
getExitString in the Room class. This method should return a String listing the exits
from the room. For example, if the room has exits to the north and west, this method
should return a String containing: "north west".
• Add a method called getLongDescription to the Room class that returns a String
containing the description of the cu
ent room and a list of the exits of a room (hint:
call the getExitString method you just created.
• Now that each room has a method that can print information about a Room refactor
the code in the Game class to take advantage of this functionality. i.e. anywhere the
Game class uses the getRoomExitsAndDescription method, change it to use your
getLongDescription method.
Written Exercise 6
Now that you have made some changes to your code, create a template similar to the
template I provided for written exercise 3 for the Game and Room class (note that it will be
different as you now have new methods and have refactored code into different classes).