Description
Animation and MVC Architecture
Question 1 (40 points):
Purpose: Practising GUI design and Implementation.
Degree of Diculty: Tricky
The objective of this assignment is to get experience working with the model-view-controller architecture
and simple animations using Timers. You are to add another view to the space invaders game given to
you. In particular for Part (a), you are to add another window to the game that should be beside the rst
window. This new window should show an invader image and have text that states how many invaders are
left to be destroyed. In Part (b), you are also expected to modify the game to allow multiple laser res with
a recharge delay.
(a) New Window Specications
You will add another window to appear beside the main game window. This window should appear
once the game playing is started, and disappear once the game playing stops. Thus, the extra window
should not be present when the welcome, high scores, or save scores views are present.
The new window is to display an image for an invader. There are two images for an invader – one with
arms up and one with arms down. You should switch between them every time an invader is killed.
Note that the images are white on a black background so they only look good when shown on a black
background, therefore your panel should have a black background.
The images for the game objects are stored in les. The names of these les could be hard coded
into the program. However, it is a common task to change to dierent images, and it should be easy
to do. To facilitate this, the le names are stored in a separate le. Thus, to change to dierent images,
it is not even necessary to recompile the project. To make the le easy to change, it is a text le
(SpaceInvaders.properties). As it is common to store the properties of a project in a text le, Java has
a special class (Properties) to handle such les. In the game space invaders, the Properties class is
used by the class PropertiesDiskStorage (of package util) to load the images of an entity of the game.
Thus, you can get a list of the names of the les for the images of an invader by the following (line 109
of class GameObject):
List
Given the name of the le for an image, the image needs to be read into memory. This is a fairly
timeconsuming task so it should not be done unless necessary. One approach is to read all the images
at the start. This will delay the start of the system (to read all the images). Also, it is common for not
all the possible images to be needed, so reading all possible images can be wasteful. The approach
taken is to read images as needed. Those already read are stored in a HashMap, with the le names
used as keys, so that no image is read twice. The approach of using local storage to save a copy
of something that is time-consuming to obtain is called using a cache. Caches are often used when
accessing resources over the web, or accessing items from disk. In the space invaders game, the class
to handle image access is called ImageCache that is implemented using the Singleton pattern. Thus,
when an image is needed, the image can be obtained by (line 35 of the class GraphicsPanel):
BufferedImage image = ImageCache.getInstance().getImage(imageName);
The new window is also to have a text message stating the number of invaders that remain. In order
to know when this information might have changed, the window should be a GameObserver, and be
added to the list of observers of the game. In order to access the count of the number of invaders
remaining, a method for that purpose should be added to the GameInfoProvider interface.
You should follow the model-view-controller architecture. Thus, the controller will create and set up
the new window. The classes in the game package and the view package should know nothing about
the new window, except the game now needs to implement the method to obtain the number of
invaders. The new class/classes should be placed in a new package.
Note that the new window should be created before the panel with the game, as Java leaves the focus
in the component last created.
Page 3
Department of Computer Science
176 Thorvaldson Building
110 Science Place, Saskatoon, SK, S7N 5C9, Canada
Telephine: (306) 966-4886, Facimile: (306) 966-4884
CMPT 270
Developing Object Oriented Systems
(b) Repeated Laser Fire Specications
The space invaders game only allows one laser to be red at a time. This is too boring. You should
modify the game so that a multiple laser beams can be red by the player. Laser guns take some time
to be recharged, so the player should only be allowed to shoot a laser once every 0.5 seconds.
(c) External Documentation
Once you have completed the questions above, create a le called A6_documentation.pdf that includes all the external documentation for your updated game. External documentation should include:
• A description of how to run your system. What class should be invoked, what method?
• The status of your assignment. What is working and what is not working? What is tested and what
is not tested? If it is only partially working, the previous point should have described how to run that
part or parts that work. For the part or parts not working, describe how close they are to working.
For example, some of the alternatives for how close to working are (i) nothing done; (ii) designed
but no code; (iii) designed and part of the code; (iv) designed and all the code but anticipate many
faults; or (v) designed and all the code but with a few faults; (vi) working perfectly and thoroughly
tested.
• A UML diagram for your new class/classes. For each new class, include all its features in the UML
diagram. For previously-existing classes, no features are needed, just include the class name in a
box. Additionally, only show the previously-existing classes that are directly related to your new
classes (inheritance, aggregation, ball-and-socket, and uses association). Don’t be alarmed that,
many of the previous classes will not be shown at all.
What to Hand In
• A le titled A6.jar of your complete system.
• A zip folder titled A6.zip that contains all the classes you created and or modied.
• A le titled A6_documentation.pdf containing your external documentation
Be sure to include your name, NSID, student number and course number at the top of all documents.
Evaluation
5 pts For the jar le (should successfully run and be stand alone)
5 pts For correctly using the Model-View-Controller Architecture
15 pts For the new window and correct animation of the Space Invader image.
5 pts For correctly implementing the timer
5 pts For appropriate internal documentation in your new classes
5 pts For the external documentation
Page 4