Professional Documents
Culture Documents
Programming Applications
Lab Assignment
Assessment
The lab work is formally assessed the marks count towards your final mark for this module.
You need to submit all work via KEATS by 23:00 on Saturday the 28 th of February, and you
must attend your timetabled PRA lab in the week commencing the 2 nd of March, to have the
work marked. Failure to do either of these, without an approved ERF/NEA, will result in you
receiving zero marks for your work.
Please submit your work on time and attend the lab for marking. For notes regarding what happens if
things go wrong, please see the latter pages of the instructions for the first lab; and if in doubt, talk to
your personal tutor.
The task is to develop a word game where a word is to be guessed, and four pictures are displayed
as a clue. As with the classic game hangman, the word is initially shown as blanks; where the number
of blanks is the length of the word. The difference is that the player is given a selection of possible
letters (of which just a few are in the word) and they must choose from these.
Note that your GUI design must not be fixed to one level of the game. The example above is just one
level: on other levels, there will always be four pictures (or the name of the game would be a lie), but
the word to be guessed, the pictures themselves, and the number of letters to choose from (and what
they are) varies.
A selection of letters from which the user can choose (e.g. a String abcdef if the letters to
choose from are a,b,c,d,e and f);
Create a class, FourPictures, that has a constructor that takes each of these, and stores them in
member variables.
In addition, make a member variable to store the revealed word: the letters in the answer, that have
been correctly guessed so far. Initialise this in your constructor. It should initially be all 'blanks' (the
underscore character), separated by spaces. If the answer is n letters long, there should be n blanks,
with a space between each of them. For instance, for paris, the revealed word would be '_ _ _ _ _'
(five blanks, with a space between each).
It should then, for instance, be possible to run the following code as a main method:
String filenames[] = {"Paris1.jpg", "Paris2.jpg",
"Paris3.jpg", "Paris4.jpg"};
FourPictures game1 = new FourPictures("paris","pysitrla", filenames);
FourPictures game2 = new FourPictures("paris","eipfrasncywv", filenames);
Note, here, the revealed word is not passed to the constructor: this will be given a value by code
inside the constructor.
As you progress through the exercises, you will need to use and update the FourPictures class, e.g.
with accessor methods for its member variables.
A label showing 'Guess: ' followed by the revealed word (initially, as in the screen-shot, blanks
separated by spaces);
Write code that will make this GUI, for a given FourPictures object. A suggested implementation is to
break the job into a number of stages:
A JLabel for the current revealed portion of the word, at NORTH (hint: HTML formatting is an
easy way of getting a large font).
A JPanel in the CENTER, which we can use for the four images;
Note, to get full marks for this exercise, you must make a class that extends JFrame, e.g:
public class GameWindow extends JFrame {
public GameWindow(FourPictures game) {
...code here adding GUI components to 'this'...
}
}
For various important reasons, you should do the above instead of the following:
public class GameWindow {
public GameWindow(FourPictures game) {
JFrame f = new JFrame();
...code here adding GUI components to f... // not so great
}
}
And certainly, whatever you do, don't do a combination of the two:
public class GameWindow extends JFrame { // Okay so far
public GameWindow(FourPictures game) {
JFrame f = new JFrame();
// No!
The revealed word inside the FourPictures class, should be updated. Add a method to the
FourPictures class to do this, and call it from your event handler. To be clear what it needs to
do:
Suppose the word to be guessed is 'paris' and the revealed word was previously _ _ _ _ _
(five blanks, separated by spaces)
If the user clicks on 'a' this should be changed to _ a _ _ _ : the second blank is replaced
with the letter 'a', because the second character in the word was 'a'
The label at the top of the JFrame should be updated, to show this new revealed word.
Finally, once the user has guessed the word, make all the buttons disappear, replacing the content of
the panel at the bottom with a label containing the word 'Correct!'.
At this point, you should now have a functioning game. Your application should load two windows,
which you can move to be side-by-side. They should both work as separate, self-contained instances
of the game; just with a different selection of letters to choose from.
A letter that is in the answer, but has not yet been revealed, is clicked on. The corresponding
button thus disappears from the panel at the bottom, and that letter is revealed (as in Pair
Exercise 3).
The hint button disappears, too, limiting the user to one hint per game.
Importantly, do not just save one of these links to disk, then read from the file you will get no
marks for this. Your application must read directly from one of these two URLs, when it is run; so, if
the list of levels on the web server changes, the levels displayed in your application will change. If
you have not read from a URL before have a look at the following Oracle tutorial:
http://docs.oracle.com/javase/tutorial/networking/urls/readingURL.html
If you open one of the links above in a web browser, you can see the format of the list of levels is as
follows:
The answer
The letters to choose from
The URL of picture 1
The URL of picture 2
The URL of picture 3
The URL of picture 4
This then repeats, as many times as necessary, to define all the levels.
You will need to do two things for this exercise:
(a) Write code to open the list of levels from a URL; then read through the lines and create a
FourPictures object for each level.
(b) Amend your GUI class, so instead of taking a single FourPictures object, it takes a List
containing all the FourPictures objects; and additionally, has a 'next level' button, that updates the
GUI to show the next level on the list. This button should be greyed out until the user has correctly
guessed the answer to the current level.
Individual Exercise
On the PRA KEATS page, there is a link where you can submit a level for the game. Each student
can contribute one level, and the details are stored to create the 'levels.php' link given earlier.
For this exercise, you should submit a level. The form will ask for the answer (e.g. paris), the letters
to choose from (e.g. pysitrla), and links to four images. You should choose these yourself; but
don't use paris or london as your answer, as that would be too obvious.
One good source of images of the right sort of size is Wikimedia Commons if you search for images
on there, the thumbnails are a reasonable size to use for the game. You can find the URL for a
thumbnail by right-clicking it, and choosing 'Copy image location' (or the equivalent in your web
browser). Paste the URLs for four images into the form, and then submit your level. Once submitted,
it will display the details of the level so you can confirm they are correct; if not, repeat the process until
you are happy with your level submission.
You are reminded at this point of the college Information Technology Services regulations. Treat this
exercise as if you were posting on a discussion forum visible to your class, so e.g. do not submit
obscene images, or use obscene language; and do not post content that harasses, bullies or
discriminates against other members of the college. Breach of these regulations is covered by the B3
Misconduct regulations.
The helpdesk, open Monday to Friday from 1:30pm to 4:30pm (13:30 to 16:30).
Liana's PRA drop-in clinic, once a week, on Wednesdays, from 12:00 to 14:00, in K4U.13/14
Andrew and Steffen's office hours. Details of staff office hours are always available from:
https://internal.kcl.ac.uk/nms/depts/informatics/stu/geninfo/officehours.aspx
Any other comments or queries that cannot be dealt with via these routes, email both
andrew.coles@kcl.ac.uk and steffen.zschaler@kcl.ac.uk . For best results, please use your @kcl
email address (so we know who you are); include a meaningful subject line (so we know it isn't spam);
and only send one email to us both rather than copy-and-pasting the same text into two separate
emails.
Marking
Your work will be marked by a TA in your fourth PRA lab session (week commencing 2 nd March). As
well as ensuring your work is marked in a timely manner, this is a good opportunity to get immediate
feedback on your work, which you can learn from and apply later in the course.
This piece of work counts for 2.5% of your overall module mark for PRA. You will be awarded a mark
between 0 and 5 (inclusive) so each mark is worth half a percent. Your mark is determined by
adding together two marks:
A quality mark between 0 and 2. Code that has no noticeable bugs gets 2 marks; code with
minor bugs gets 1 mark; code with major bugs gets 0 marks.
Please note that because this work is marked in your PRA lab, and involves you going through your
code with a TA, you must attend your timetabled PRA lab to have your work marked. Otherwise,
you may receive a mark of zero. In case of illness or other mitigating circumstances that mean you
are unable to attend your lab to have your work marked, you will need to submit an Notification of
Examination Absence (NEA) form to the departmental office, as soon as you are able to do so,
enclosing evidence. If the NEA is approved, arrangements will be made to mark your work on another
occasion.
Provisional marks
Under the college regulations, the mark you receive in the lab is provisional. The TA marking your
work will recommend to Andrew and Steffen that you receive that mark. Andrew and Steffen will then
review and record the marks awarded, to then be reviewed and approved by the board of examiners.
Until this point, all marks are subject to change.
If you disagree with your provisional mark, please do not argue with the TAs: contact Andrew and
Steffen via email, explaining the issue. This does not prejudice your right to later appeal under
section A6 of the regulations. For further advice on appeals, contact your personal tutor or the
KCLSU appeals advice service.