Beruflich Dokumente
Kultur Dokumente
c
This section describes each piece of functionality you must implement, and the order
in which they must be implemented. Note that the functionality constitutes only half
of your overall mark while design and coding style makes up the rest. Please read
Section ³Marking Scheme´ for more details.
It is recommended that you submit your project to PLATE after completing each task
in order to receive feedback about which parts of your program are correct/incorrect.
c
Define the Game class so that a game has 1 player, 3 items and 1 exit. These
should be defined as 5 private fields within Game, with appropriate types and
appropriate names.
Also define appropriate fields in each of the other 3 classes: Player, Item and Exit.
To decide on appropriate fields, think of what data needs to be stored for each kind
of object.
Finally, define the constructor of the Game class to ask the user for the initial
positions and information about all of the player, item and exit objects, and to then
create these new objects and store them in the 5 fields of the game.
è
R
G
Note that the text in × is text that the user of the program will type in. In a later
task, there will be two modes: easy mode and hard mode. Choosing the mode will
have no effect at this stage, and you can assume that the user will always choose
easy mode.
Submit this now to PLATE to receive mar ks for this task, or to receive feedback on
mistakes in your output.
!
"
#$
The first 3 components display the names and positions of the 3 item objects. The
last part, ³player(1) ± 0 points´ displays information about the position of the player
(in this case, 1) and the number of points (in this case, 0). The exit is not shown in
this string.
This method print the string; only return it as the method's result.
Hint: You can construct the string using string concatenations of the form:
You can also use the + class described in the text book. You must ,
however, use the
method.
Note that the at the end in bold text represents text that the user types in. Your
program must print the prompt and then use a scanner to read the user's input.
The command will always be a single character. Unfortunately, Java's Scanner class
does not have a -
method and so you need to use the following code:
This will obtain the first character of whatever the user types.
After reading the user's input, your program should execute the appropriate
command. In this task, you can ignore the 'p' command and only support the 'l' and 'r'
commands.
If the user types 'l' or 'r', your program should send a message to the player object to
move one position to the left or right respectively.
You do not need to try this entire task at once. Complete a little bit at a time, and
submit to PLATE to see your progress and receive PLATE's feedback.
Each item object has a certain number of points. For each item, you also need to
record whether the item has been picked up yet or not. Make sure you have
appropriate fields in your Item class to support this before continuing.
There are two methods that you need to modify to make this feature work.
First, you must update the
method as follows. Let's suppose that the
player has just picked up the apple and orange items. In the string, these items now
become replaced by a star: ³*´ as in the following string:
22!
"
#3
This string indicates that the first two items are now taken, and only the cherry item
remains.
Submit to PLATE to receive your marks and feedback for this task.
Submit to PLATE to receive your marks and feedback for this task.
Update your ^
method so that if all items have been collected /
picked up, then the exit will now appear in the string, as follows:
222
"
#"4
56$75
The 56$75 at the end of this string indicates that the exit has appeared at position 0.
Also update your
method so that if the player moves to where the exit is, you
record somewhere the fact that the player has exited the game. You will need a
new ) field to store this information.
Submit to PLATE to receive your marks and feed back for this task.
!
You will now implement several loops in your program. After completing each loop,
submit it to PLATE to receive marks and feedback for that loop.
This string indicates that the apple is worth 4 points, the orange is worth 2
points, and the cherry is worth 7 points.
ÔWhen the user is asked whether to play in (e)asy mode or (h)ard mode, it is
possible for
the user to type in an invalid option such as 'Z'. Write a loop which repeatedly
asks the
user to select the mode until the user enters a valid option. Your output
should follow
the following format exactly:
è
;
Ôè
)
Ôè
;
Ôè
After you have done this, define a class called J, which has a correctly
defined
method. This method should create a new ^ object, and then
invoke its
method.
"
This task is intended for students who are aiming for an HD in this subject.
Modify your program so that if the user selects hard mode, the game asks the user
to input the names, initial positions and initial directions for two enemy objects. We
shall use the number -1 to indicate the left direction, and 1 to indicate the right
direction. These enemy objects will automatically move left or right whenever the
player has a turn. If an enemy is heading left and reaches position zero, it will turn
around and begin heading right. If an enemy is heading right and reaches position
10, it will turn around and begin heading left. If the player and an enemy occupy the
same position at the same time, the player dies, the message ³Ouch! You were
eaten.´ is displayed, and the game stops.
Your program, when played in easy mode, should still have t he same behaviour as
before. When played in hard mode, the output should match exactly the behaviour
shown below:
è
=222>
=222>
=222>
If the player manages to avoid all enemies, the output may instead look like this:
è
A
=222>
=222>
=222>
2
2
2
22=!22>"!
($
B
<3
22=!22>"4
((
3
<3
22=!22>"B
(
!
<3
222"
(?
!
<"$
56$75
222"?
(
3
<"$
56$75
222"
(B
4
<"$
56$75
222"(
(4
B
<"$
56$75
222"$
(!
?
<"$
56$75
222"(
(!
<"$
56$75
222"
(3
(
<"$
56$75
222"
(B
$
<"$
56$75
ë
#
c
It is good design to separate all user interface code from the rest of your p rogram -
this allows you to easily replace your user interface with a different one without
affecting the rest of your program.
Create a class called X; containing exactly all of the user interface code for your
program. That is, any code that mentions , or should
be moved into this class. To be eligible to receive the bonus marks, any given
change to the user interface should be possible by making changes only to
your X; class. The
methods themselves do not need to be moved into
the X; class, but the methods that print these strings do.
J
Your solution will be marked according to the following scheme: