Ball and Brick Game Project Report
Ball and Brick Game Project Report
SUBMITTED BY
BACHELOR OF SCIENCE
IN
COMPUTER SCIENCE
(BSCS)
ii
DECLARATION
The work reported in this project report was carried out by us under the supervision of
Sir Nabeel Maqsood, Department of Computer Science GC University, Faisalabad, Sahiwal
Campus, Pakistan.
We hereby declare that the title of project Ball and Brick and the contents of our project report
are the product of our own research and no part has been copied from any published source
(except the references). We further declare that this work has not been submitted for award of
any other degree /diploma. The University may take action if the information provided is found
inaccurate at any stage.
iii
CERTIFICATE BY SUPERVISORY COMMITTEE
We certify that the contents and form of Project and Project report submitted by
Mr. Sameer Younas Registration No: 2015-GCUF-76508 has been found satisfactory and
in accordance with the prescribed format. We recommend it to be processed for the evaluation
by the External Examiner for the award of degree.
Chairperson
Signature with Stamp……………………………
iv
DEDICATION
We dedicated this book to the Almighty God, thank you for the guidance, strength, power of mind,
protection and skills and for giving us a healthy life. All of these, we offer to you.
v
ACKNOWLEDGEMENT
I would also like to acknowledge with much appreciation the crucial role of the staff, who gave
the permission to use all required equipment and the necessary materials to complete the task “Ball
and Brick”.
I have taken efforts in this project. However, it would not have been possible without the kind
support and help of many individuals and organizations. I would like to extend my sincere thanks
to all of them.
I am highly indebted to my teachers for their guidance and constant supervision as well as for
providing necessary information regarding the project & also for their support in completing the
project.
I would like to express my gratitude towards my parents for their kind co-operation and
encouragement which help me in completion of this project.
I would like to express my special gratitude and thanks to industry persons for giving me such
attention and time.
My thanks and appreciations also go to my colleague in developing the project and people who
have willingly helped me out with their abilities.
Sameer Younas
vi
PREFACE
This project is being prepared keeping in view the requirement of computer science technology
field.
We all wants to build software that makes the things better, avoiding the bad things that lurk the
shadow of failed efforts. To succeed, we need discipline when software is designed and built. We
need an engineering approach.
This project will provide a great help to those who wants to make their society better with the help
of computer technology.
Through the development of the project we had great experiences of various strategies that can be
applied in the development of the project. This project is the stepping stone for our future.
vii
Abstract
In this there will be a ball confined to move inside a rectangular or square area. The ball will
bounce off on striking any surface at an angle of reflection that is equal to the angle of the
incidence. Then there will platform confined to move in horizontal direction in the lower part of
the screen. The player’s aim will be to make ball strike rectangular bricks that will be present in
the upper part of the screen. These bricks will vanish when the ball strikes them. The player will
score points based on the number of bricks hit. There will be many difficult levels. With increment
in difficulty level the speed of the ball will increase, making it difficult for the player to play the
game. The player wins when he has crossed all difficult levels.
viii
Table of Contents
1. Introduction ................................................................................................................................ 10
2. Background.................................................................................... Error! Bookmark not defined.
3. Gameplay-General Description .................................................................................................. 12
4. Graphical User Interface................................................................ Error! Bookmark not defined.
4.1. Brick Zone ..................................................................................... Error! Bookmark not defined.
4.1.1. The Bricks ................................................................................ Error! Bookmark not defined.
4.1.2. The Bar .................................................................................... Error! Bookmark not defined.
4.1.3. The Ball.................................................................................... Error! Bookmark not defined.
5. Score Zone ..................................................................................... Error! Bookmark not defined.
6. Gameplay-Details .......................................................................... Error! Bookmark not defined.
6.1. Frame Rate ................................................................................... Error! Bookmark not defined.
6.2. The Bricks...................................................................................... Error! Bookmark not defined.
6.3. The Movement of Bar................................................................... Error! Bookmark not defined.
6.4. The Movement of Ball .................................................................. Error! Bookmark not defined.
6.4.1. The Reflection of Ball ................................................................. Error! Bookmark not defined.
6.4.2. The Speed of the Ball ................................................................. Error! Bookmark not defined.
7. Game Over..................................................................................... Error! Bookmark not defined.
8. Extra Features................................................................................ Error! Bookmark not defined.
9. Mid-Project Requirement.............................................................. Error! Bookmark not defined.
10. Ball and Brick Game: Project Model ........................................................................................... 20
11. Ball and Brick Game Structure-analysis:Class Diagram[UML] .................................................... 21
12. Ball and Brick Game Structure-design:Class Diagram[UML] ...................................................... 29
13. Ball and Brick Game Behaviour-Design:Sequence Diagram ....................................................... 55
3.1. Introduction .................................................................................. Error! Bookmark not defined.
3.2 Existing Approaches and techniques ............................................. Error! Bookmark not defined.
3.2.1 Water fall Approach .................................................................... Error! Bookmark not defined.
3.2.2 Incremental Approach ................................................................ Error! Bookmark not defined.
ix
Chapter #01
Introduction
1
1. Introduction
The goal of this ENSC 452 course is to implement a program on Zed Board with both Xilinx's
system software and hardware. We decide our project to be a video game similar to the brick
breaker. In our game, the user can move the bar at the bottom of the screen left and right in order
to bounce the movable ball up and try to hit the bricks. Once the ball hit any brick, the brick will
be downgraded and eventually wiped out. We will split our job into 6 milestones and use Agile
methodology to accept greater flexibility and to get higher efficiency. Each part will be tested by
a specific test plan to ensure the completeness.
2
Chapter # 02
Background
3
1. Background
Breakout is a traditional arcade game developed and published by Atari, Inc. And Brick
Breaker is a clone of Breakout. The game consists of 50 bricks on the top of the screen,
a flying ball and a movable paddle on the bottom of the screen. The paddle is controlled
by the user to move either left or right. Player need to use this paddle to prevent the ball
from falling out of the screen. Three unbreakable walls on the side of the screen are used
to deflect the ball. The collision between the ball and bricks can make brick downgraded
or disappear. The speed of ball gradually goes up with time. The level of bricks is also
upgraded as time goes on, which means it requires more than one collision to smash the
upgraded bricks. The game will continuously proceed as long as the ball is not falling out
of the screen. During playing, the user is able to pause the game and continuous again.
4
3. Gameplay – General description
The player moves the bottom bar displayed on the VGA screen by using the buttons on the Zed board
to deflect a bouncing ball to smash the bricks on the upper part of screen. There are several rules in
the movements of the ball, how the score is calculated and game specifications that will be justified in
the following sections.
You can refer to the YouTube video here to have a basic idea of the game. Even though the project
requirement is simpler, you are encouraged to make the game more interesting. Please note that you
are required to follow all the requirements specified in this document to implement the basic features
of the game. For the extra features, you are free to do what you want.
5
Figure 1 - Main Screen Layout
There are two main zones in this screen which are Brick Zone and Score Zone.
6
There are total of 8 rows of brick and each row has 10 bricks as shown in Figure 1.
Figure 2 illustrates the size of the brick and the distances between bricks. You are free to design the
pattern and the color of the bricks. During the game, some of the bricks may be able to change to a
special color to double the score when they are hit by the ball. The rule will be provided in Section III.
There are different types of region on the bar which cause different effects to the ball (angle and speed)
depending upon which region the ball hits. The rule will be provided in Section III. The size of the bar
and the locations of the regions are described in Figure 3.
Figure 3 - The size of the bar and the different regions (A, S and N)
7
4.1.3. The ball
The ball is simply a circle with the radius of 7 pixels as presented in Figure 1 and you are free to design
the pattern as well as the color of it.
The ball moves along a straight line going through its center. The angle of that line and the direction
of the movement are determined when the ball hits the (left, right, upper) sides of the Brick Zone, the
bricks and the bar. The details of ball movement will be discussed in Section III.
5. Score zone
Apart from the Brick Zone, the remaining space is used for the Score Zone. You are free to design the
Score zone but it must have the basic information as listed below:
6. Gameplay – Details
This section provides the detailed rules of the game.
8
threads will check whether the ball hits any of its brick to inform the ball-thread to re-calculate the
movement of the ball.
The brick-threads are also responsible to update the current score. Under normal condition, for every
brick that the ball hits, the player gets 1 point. You should beware of the situation in which the ball
can hit more than one brick.
At any point in time, there must be two columns of brick which can be golden bricks. The player will
get 2 points if the ball hits the golden brick. The brick-threads compete to be golden by requesting
the imaginary golden-brick shared resource that can only serve two threads at a time. Therefore, the
counting semaphore should be used here for the imaginary golden-brick shared resource. The brick-
threads release the golden resources every 10 points gained by the player. In other words, the brick-
threads release the golden resources at the moment when the current score is 10 or 20 or 30, etc.
The bricks that are hit (including the golden bricks) must be disappeared in the next frame. If you
have any animation to show that the ball is disappearing, the animation must start from the next frame.
The bar can only be moved left or right. The bar must be completely inside the Brick Zone, i.e., the left
most edge of the bar must be at least 1 pixel away from the left edge of the Brick Zone, similarly for
distance between the right most edge of the bar and the right edge of the Brick Zone.
When the button is pressed and then released immediately (being pressed in less than 250
milliseconds), the bar will move left (right) 25 pixels.
If the button is held for more than 250 milliseconds, the bar will move continuously at the speed
of 200 pixels per second until the button is released.
9
6.4. The movement of the ball
The ball moves along a straight line going through its center (let’s call it movement line). The angle of
the straight line and the direction of the movement of the ball are determined whenever the ball hits
the edges of the Brick Zone (left, right, upper), the bricks and the bar.
The initial angle of the movement line with respect to the horizontal surface of the bar is 90o. It means
the ball will move upward vertically from the bar when the game starts.
10
Figure 4 - The bouncing of the ball under normal condition. (Image source: [Link]
[Link]/)
In case of hitting the edges of the bricks, the reflection surface is the corresponding edge. If the ball
collides with the corner of the brick, the reflection surface is the imaginary line that makes a 45o angle
to the edges of the brick as illustrated in Figure 5. The angle of incidence equals the angle of reflection.
If the ball hits the A- or A+ (Angle) region on the bar, the angle of reflection will
o
be decreased or increased by 15 respectively as shown in Figure 6.
The minimum and maximum angles of the movement line with respect to the bar
o o
are 15 and 165 respectively.
11
Figure 6 - The changes of the angle of the movement line when the ball hits the A- or A+ region on
the bar.
The initial speed is 250 pixels per second. Considering the required frame rate of 25 FPS, the ball
moves 10 pixels per frame.
In case of hitting the S- (Speed) region on the bar, the speed of the ball will be decreased by 100 pixels
per second. If the ball hits the S+ region, the speed will be increased by 100 pixels per second.
Besides, the speed of the ball automatically increases by 25 pixels per second whenever the player
gains 10 more points.
The minimum and maximum speeds of the ball are 50 and 1000 pixels per second.
12
7. Game over
The game ends when any of the below two conditions occurs. The game needs to display a message
to the player to show the condition that ends the game.
The ball falls off the lower edge of the Brick Zone.
All bricks are destroyed.
8. Extra features
You are free and encouraged to implement extra features to the game. Some suggestions:
9. Mid-project requirements
You are supposed to demonstrate the first milestone 2 or 3 weeks after lab 3 (please check the
schedule) to show the progress of your project. For this milestone, the following features must be
finished:
The main screen of the game with all the required components in the Brick Zone and Score Zone.
The ball and the bar can move smoothly, i.e. you should be able to update the screen at 25 FPS.
The ball can move up and down continuously at 250 pixels per second.
The bar can be controlled by the player while the ball is moving. The requirements specified in
Section III.3 for the movement of the bar should be all done.
The brick columns should be able to change their color while the ball and the bar are moving.
Personnel:
13
Sameer hooligan_me@[Link] Dubai Garden
Younas
High Street
City 5
B8 6QB
Ball Game structure - analysis Preliminary classes of the game are identified.
Ball Game structure - design Ball game structure class diagram displays basic structure of the ball game.
Game's idea is to remove all the bricks from the wall by striking them with the
ball.
Ball Game behaviour - Design This model describes interactions among the Ball game objects during the
game.
States of the Ball This diagram describes the states of the ball and possible transitions between
the states. It reuses events and operations from the class diagram (e.g. Start
game, move, calculateNewDirection).
Ball Game requirements This model describes the use cases for the ball game application.
14
[Link] Game structure - analysis: Class Diagram [UML]
Graph properties:
Status draft
Authors A.B.C
Graph dictionary
15
Wall Class [UML]
This model describes the class structure of the game identified in the Note text
analys...
Attributes +position
Operations
Package
Abstract? F
Persistent? F
Stereotype
Overridability
Role
Parameters
Constraints
Invariant
Derivation rules
Responsibility
Documentation
Simple symbol? F
Ball relationships:
16
Ball links:
Decomposition None
Explosions None
Attributes
Operations
Package
Abstract? T
Persistent? F
Stereotype
Overridability
Role
Parameters
Constraints
Invariant
Derivation rules
Responsibility
Documentation
Simple symbol? T
BallGame relationships:
17
: Whole : Aggregation Paddle : Part
BallGame links:
Decomposition none
Explosions none
Attributes
Operations
Package
Abstract? F
Persistent? F
Stereotype
Overridability
Role
Parameters
Constraints
Invariant
Derivation rules
Responsibility
Documentation
Simple symbol? T
18
Brick relationships:
Brick links:
Decomposition none
Explosions none
Attributes
Operations
Package
Abstract? F
Persistent? F
Stereotype
Overridability
Role
Parameters
Constraints
Invariant
Derivation rules
Responsibility
Documentation
Simple symbol? T
19
Paddle relationships:
Paddle links:
Decomposition none
Explosions none
Attributes
Operations
Package
Abstract? F
Persistent? F
Stereotype
Overridability
Role
Parameters
Constraints
Invariant
Derivation rules
Responsibility
Documentation
Simple symbol? T
20
Wall relationships:
Wall links:
Decomposition none
Explosions none
This model describes the class structure of the game identified in the analys...: Note text
Properties:
Note text This model describes the class structure of the game identified in the analysis phase.
Stereotype
This model describes the class structure of the game identified in the analys... relationships:
none
This model describes the class structure of the game identified in the analys... links:
Decomposition none
Explosions none
21
Sub-objects:
A.B.C: Person
Properties:
Name A.B.C
E-mail hooligan_me@[Link]
Name position
Data type
Default value
Stereotype
Visibility public
Scope instance
Access
Derived? F
Persistent? F
Constraints
Status draft
Documentation Ball game structure class diagram displays basic structure of the ball game. Game's idea is
to remove all the bricks from the wall by striking them with the ball.
22
Diagram picture: Ball Game structure - design
Graph dictionary
Ball Class [UML] Ball is the basic element of the game. Player tries to remove bricks by
hitting them with the ball.
Brick Class [UML] Single element of the wall. These will disappear, when the ball hits them.
23
MovingObject Class [UML] MovingObject is an abstract class for all moving components of the ball
game.
Paddle Class [UML] Player tries to keep the ball in play by hitting it with the paddle.
TopScore Class [UML] Stores one of the top scores and the player who achieved it.
Wall Class [UML] Walls are generally immobile; the ball bounces back off them giving no
points.
Attributes
Package Game
Abstract? F
Persistent? F
Stereotype
Overridability
Role
Parameters
Constraints
Invariant
Derivation rules
Responsibility
Documentation Ball is the basic element of the game. Player tries to remove bricks by hitting them with the
ball.
Simple symbol? F
24
Ball relationships:
Brick : Part
Wall : Part
BallGame : Whole
Paddle : Specialization
Brick : Specialization
MovingObject : Superclass
Ball links:
Decomposition none
25
BallGame: Class [UML]
Properties:
Package Game
Abstract? F
Persistent? F
Stereotype
Overridability
Role
Parameters
Constraints
Invariant
Derivation rules
Responsibility
Simple symbol? F
BallGame relationships:
Brick : Part
Ball : Part
Wall : Part
26
BallGame links:
Decomposition none
Explosions none
Attributes +value:int = 1
Package Game
Abstract? F
Persistent? F
Stereotype
Overridability
Role
Parameters
Constraints
Invariant
Derivation rules
Responsibility
Documentation Single element of the wall. These will disappear, when the ball hits them.
Simple symbol? F
Brick relationships:
Ball : Part
27
Wall : Part
BallGame : Whole
Paddle : Specialization
Ball : Specialization
MovingObject : Superclass
Brick links:
Decomposition none
Explosions none
28
MovingObject: Class [UML]
Properties:
Operations +void display() , +void move(Point position, int direction) , +void checkHits()
Package Game
Abstract? T
Persistent? F
Stereotype
Overridability
Role model
Parameters
Constraints
Invariant
Derivation rules
Responsibility
Documentation MovingObject is an abstract class for all moving components of the ball game.
Simple symbol? F
MovingObject relationships:
Paddle : Specialization
Brick : Specialization
Ball : Specialization
29
MovingObject links:
Decomposition none
Explosions none
Attributes +maxSpeed
Package Game
Abstract? F
Persistent? F
Stereotype
Overridability
Role
Parameters
Constraints
Invariant
Derivation rules
Responsibility
Simple symbol? F
Paddle relationships:
30
Ball : Part
Wall : Part
BallGame : Whole
Brick : Specialization
Ball : Specialization
MovingObject : Superclass
Paddle links:
Decomposition none
Explosions none
31
TopScore: Class [UML]
Properties:
Operations
Package Game
Abstract? F
Persistent? T
Stereotype
Overridability
Role
Parameters
Constraints
Invariant
Derivation rules
Responsibility
Documentation Stores one of the top scores and the player who achieved it.
Simple symbol? F
TopScore relationships:
TopScore links:
Decomposition none
Explosions none
32
Wall: Class [UML]
Properties:
Attributes
Operations
Package
Abstract? F
Persistent? F
Stereotype
Overridability
Role
Parameters
Constraints
Invariant
Derivation rules
Responsibility
Documentation Walls are generally immobile; the ball bounces back off them giving no points.
Simple symbol? T
Wall relationships:
Brick : Part
Ball : Part
BallGame : Whole
Brick : Specialization
Ball : Specialization
33
MovingObject : Superclass
Wall links:
Decomposition none
Explosions none
Sub-objects:
Sameer Younas: Person
Properties:
E-mail hooligan_me@[Link]
High Street
City 5
B8 6QB
34
+void display(): Operation [UML]
Properties:
Parameters
Return type
Overridability
Stereotype
Visibility public
Preconditions
Postconditions
Body
Documentation Overriden from superclass to display a round ball rather than a square
Return type
Overridability
Stereotype
Visibility public
Preconditions
Postconditions
Body
Documentation
35
in MovingObject hitObject: Parameter
Properties:
Parameter hitObject
Direction in
Default value
Parameters
Return type
Overridability
Stereotype
Visibility public
Preconditions
Postconditions
Body
Game: Package
Properties:
Stereotype modelLibrary
Documentation Ball game packace include all the components of the ball game application. Because the
application is small not other packages are used for categorization.
36
#currentScore:int = 0: Attribute [UML]
Properties:
Name currentScore
Default value 0
Stereotype
Visibility protected
Scope instance
Access
Derived? F
Persistent? F
Constraints
Name ballsLeft
Default value 3
Stereotype
Visibility private
Scope instance
Access
Derived? F
Persistent? F
Constraints
37
+playerName:String: Attribute [UML]
Properties:
Name playerName
Default value
Stereotype
Visibility public
Scope instance
Access
Derived? F
Persistent? F
Constraints
Parameters
Return type
Overridability
Stereotype
Visibility public
Preconditions
Postconditions
Body
Documentation This displays the Game Over text, when game ends. Game can end either when all bricks
have disappeared or when player has missed all of his/hers balls.
38
+void displayPlayersScore(): Operation [UML]
Properties:
Parameters
Return type
Overridability
Stereotype
Visibility public
Preconditions
Postconditions
Body
Documentation This displays player's current score after the Game over text.
Parameters
Return type
Overridability
Stereotype
Visibility public
Preconditions
Postconditions
Body
39
+void decrementBalls(): Operation [UML]
Properties:
Parameters
Return type
Overridability
Stereotype
Visibility public
Preconditions
Postconditions
Body
Parameters
Return type
Overridability
Stereotype
Visibility public
Preconditions
Postconditions
Body
40
+value:int = 1: Attribute [UML]
Properties:
Name value
Default value 1
Stereotype
Visibility public
Scope instance
Access
Derived? F
Persistent? F
Constraints
Documentation Value of the brick. When ball hits the brick, value will be added to player's currentScore.
Parameters
Return type
Overridability
Stereotype
Visibility public
Preconditions
Postconditions
Body
41
+void increaseScore(): Operation [UML]
Properties:
Parameters
Return type
Overridability
Stereotype
Visibility public
Preconditions
Postconditions
Body
Documentation When then ball hits a brick it will disappear and the value of the brick will be added to
player's currentScores.
Name position
Stereotype
Visibility public
Scope class
Access
Derived? F
Persistent? F
Constraints
Documentation Position stores the current location of the top left corner of the moving object in the game.
42
-velocity:Point = 0.0@2.0: Attribute [UML]
Properties:
Name velocity
Stereotype
Visibility private
Scope instance
Access
Derived? F
Persistent? F
Constraints
Documentation Stores the direction and speed of the movement. Positive x values are to the right, positive
y values up
Name extent
Default value
Stereotype
Visibility public
Scope instance
Access
Derived? F
Persistent? F
Constraints
43
-colour:ColorValue: Attribute [UML]
Properties:
Name colour
Default value
Stereotype
Visibility private
Scope instance
Access
Derived? F
Persistent? F
Constraints
Parameters
Return type
Overridability
Stereotype
Visibility public
Preconditions
Postconditions
Body
Documentation Displays the object at its current position. The default is to fill its extent with its colour;
subclasses can override for more interesting shapes and effects.
44
+void move(Point position, int direction): Operation [UML]
Properties:
Return type
Overridability
Stereotype action
Visibility public
Preconditions Is not outside the game field, ie. player has not missed the ball.
Postconditions
Body
Documentation Move changes the location and direction of the moving object in the game field according
to the given position and direction.
Parameter position
Direction in
Default value
Parameter direction
Direction in
Default value
45
+void checkHits(): Operation [UML]
Properties:
Parameters
Return type
Overridability
Stereotype
Visibility public
Preconditions
Postconditions
Body
Documentation Check whether moving object has hit some other object.
Name maxSpeed
Data type
Default value
Stereotype
Visibility public
Scope instance
Access
Derived? F
Persistent? F
Constraints
Documentation Maximum speed of the paddle can change during the game
46
+score:int = 0: Attribute [UML]
Properties:
Name score
Default value 0
Stereotype
Visibility public
Scope instance
Access
Derived? F
Persistent? F
Constraints
Documentation
47
[Link] Game behaviour - Design: Sequence Diagram
Graph properties:
Status draft
Documentation This model describes interactions among the Ball game objects during the game.
Graph dictionary
48
Object Type of Object Documentation
Object name
Class Ball
Stop? F
Documentation
:Ball relationships:
49
:Ball links:
Decomposition none
Explosions none
Object name
Class BallGame
Stop? T
Documentation
:BallGame relationships:
50
:BallGame links:
Decomposition none
Explosions none
Object name
Class Brick
Stop? F
Documentation
:Brick relationships:
:Brick links:
Decomposition none
Explosions none
51
:MovingObject: Lifeline object
Properties:
Object name
Class MovingObject
Stop? F
Documentation
:MovingObject relationships:
:MovingObject links:
Decomposition none
Explosions none
52
:Paddle: Lifeline object
Properties:
Object name
Class Paddle
Stop? F
Documentation
:Paddle relationships:
:Paddle links:
Decomposition none
Explosions none
none
53
Outside actor links:
Decomposition none
Explosions none
Sub-objects:
Sameer Younas: Person
Properties:
E-mail hooligan_me@[Link]
High Street
City 5
B8 6QB
54
Ball: Class [UML]
Properties:
Attributes
Package Game
Abstract? F
Persistent? F
Stereotype
Overridability
Role
Parameters
Constraints
Invariant
Derivation rules
Responsibility
Documentation Ball is the basic element of the game. Player tries to remove bricks by hitting them with the
ball.
Simple symbol? F
55
+void display(): Operation [UML]
Properties:
Parameters
Return type
Overridability
Stereotype
Visibility public
Preconditions
Postconditions
Body
Documentation Overriden from superclass to display a round ball rather than a square
Return type
Overridability
Stereotype
Visibility public
Preconditions
Postconditions
Body
Documentation
56
in MovingObject hitObject: Parameter
Properties:
Parameter hitObject
Direction in
Default value
Parameters
Return type
Overridability
Stereotype
Visibility public
Preconditions
Postconditions
Body
Game: Package
Properties:
Stereotype modelLibrary
Documentation Ball game packace include all the components of the ball game application. Because the
application is small not other packages are used for categorization.
57
BallGame: Class [UML]
Properties:
Attributes
Operations
Package
Abstract? T
Persistent? F
Stereotype
Overridability
Role
Parameters
Constraints
Invariant
Derivation rules
Responsibility
Documentation
Simple symbol? T
58
Brick: Class [UML]
Properties:
Attributes +value:int = 1
Package Game
Abstract? F
Persistent? F
Stereotype
Overridability
Role
Parameters
Constraints
Invariant
Derivation rules
Responsibility
Documentation Single element of the wall. These will disappear, when the ball hits them.
Simple symbol? F
59
+value:int = 1: Attribute [UML]
Properties:
Name value
Default value 1
Stereotype
Visibility public
Scope instance
Access
Derived? F
Persistent? F
Constraints
Documentation Value of the brick. When ball hits the brick, value will be added to player's currentScore.
Parameters
Return type
Overridability
Stereotype
Visibility public
Preconditions
Postconditions
Body
60
+void increaseScore(): Operation [UML]
Properties:
Parameters
Return type
Overridability
Stereotype
Visibility public
Preconditions
Postconditions
Body
Documentation When then ball hits a brick it will disappear and the value of the brick will be added to
player's currentScores.
61
MovingObject: Class [UML]
Properties:
Operations +void display() , +void move(Point position, int direction) , +void checkHits()
Package Game
Abstract? T
Persistent? F
Stereotype
Overridability
Role model
Parameters
Constraints
Invariant
Derivation rules
Responsibility
Documentation MovingObject is an abstract class for all moving components of the ball game.
Simple symbol? F
62
+position:Point = 100.0@100.0: Attribute [UML]
Properties:
Name position
Stereotype
Visibility public
Scope class
Access
Derived? F
Persistent? F
Constraints
Documentation Position stores the current location of the top left corner of the moving object in the game.
Name velocity
Stereotype
Visibility private
Scope instance
Access
Derived? F
Persistent? F
Constraints
Documentation Stores the direction and speed of the movement. Positive x values are to the right, positive
y values up
63
+extent:Point: Attribute [UML]
Properties:
Name extent
Default value
Stereotype
Visibility public
Scope instance
Access
Derived? F
Persistent? F
Constraints
Name colour
Default value
Stereotype
Visibility private
Scope instance
Access
Derived? F
Persistent? F
Constraints
64
+void display(): Operation [UML]
Properties:
Parameters
Return type
Overridability
Stereotype
Visibility public
Preconditions
Postconditions
Body
Documentation Displays the object at its current position. The default is to fill its extent with its colour;
subclasses can override for more interesting shapes and effects.
Return type
Overridability
Stereotype action
Visibility public
Preconditions Is not outside the game field, ie. player has not missed the ball.
Postconditions
Body
Documentation Move changes the location and direction of the moving object in the game field according
to the given position and direction.
65
in Point position: Parameter
Properties:
Parameter position
Direction in
Default value
Parameter direction
Direction in
Default value
Parameters
Return type
Overridability
Stereotype
Visibility public
Preconditions
Postconditions
Body
Documentation Check whether moving object has hit some other object.
66
Paddle: Class [UML]
Properties:
Attributes +maxSpeed
Package Game
Abstract? F
Persistent? F
Stereotype
Overridability
Role
Parameters
Constraints
Invariant
Derivation rules
Responsibility
Simple symbol? F
67
+maxSpeed: Attribute [UML]
Properties:
Name maxSpeed
Data type
Default value
Stereotype
Visibility public
Scope instance
Access
Derived? F
Persistent? F
Constraints
Documentation Maximum speed of the paddle can change during the game
68
69