0% found this document useful (0 votes)
10 views78 pages

Ball and Brick Game Project Report

This document appears to be a project report for a "Ball and Brick" game. It includes sections on the gameplay, graphical user interface, scoring, game details like frame rate and movement of the ball and bar. It also includes class diagrams and a sequence diagram to describe the structure and behavior of the game. The student has submitted this project report under the supervision of their professor for their Computer Science degree program.

Uploaded by

Abdullah Suleman
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views78 pages

Ball and Brick Game Project Report

This document appears to be a project report for a "Ball and Brick" game. It includes sections on the gameplay, graphical user interface, scoring, game details like frame rate and movement of the ball and bar. It also includes class diagrams and a sequence diagram to describe the structure and behavior of the game. The student has submitted this project report under the supervision of their professor for their Computer Science degree program.

Uploaded by

Abdullah Suleman
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Ball and Brick

SUBMITTED BY

Sameer Younas 2015-GCUF-76508

BACHELOR OF SCIENCE
IN
COMPUTER SCIENCE
(BSCS)

Department of Computer Science


GCUF, Sahiwal Campus
i
IN THE NAME OF ALLAH ALMIGHTY

“In the name of Allah, the Beneficial, the Compassionate


and the Merciful.

Praise be to Allah, Lord of Creation,


The Compassionate, the Merciful,
King of Judgment-day!

You alone we worship, and to You alone we pray for


help,
Guide us to the straight path

The path of those who You have favored,

Not of those who have incurred Your wrath,


All the praises and thanks are to Allah, the Lord of the
‘Alamin (Mankind, jinns and all that exists).

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.

Signature of the Student

Name: Sameer Younas


Registration No.:2015-CUF-76508

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.

Signature of Supervisor ………………….


Name: ……………………………………..
Designation with Stamp……………………….

Co-Supervisor (if any)


Signature ………………………………….
Name: ……………………………………..
Designation with Stamp……………………….

Member of Supervisory Committee


Signature ………………………………….
Name: ……………………………………..
Designation with Stamp……………………….

Member of Supervisory Committee


Signature ………………………………….
Name: ……………………………………..
Designation with Stamp……………………….

Chairperson
Signature with Stamp……………………………

Dean / Academic Coordinator

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.

“We dedicated this project to my teachers.


To my respected”

“Computer science faculty”

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.

4. Graphical User Interface


Figure 1 shows the layout of the main screen where the player interacts with to play the game.

5
Figure 1 - Main Screen Layout

There are two main zones in this screen which are Brick Zone and Score Zone.

4.1. Brick Zone


The size of the Brick Zone is 455x480 pixels, with margins from the left, up, and down edges of the
monitor to the edges of the game GUI to be 60, 60, and 60 pixels respectively as shown in Figure 1.
The brick zone is located at the left part of the screen.

4.1.1. The bricks

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.

Figure 2 - The size and distances of one brick to neighboring bricks

4.1.2. The bar


The bar is located 10 pixels away from the bottom of the Brick Zone as depicted in Figure 1. The player
can only move it horizontally by pressing the buttons on the Zed board.

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:

 The current score (start at 0).


 The elapsed time in second (start counting when the ball first leaves the bar in the beginning of the
game).
 The current ball speed in pixel per second.
 The current bricks left.

6. Gameplay – Details
This section provides the detailed rules of the game.

6.1. Frame rate


The desired slowest frame rate is 25 frame per second (FPS), i.e. the screen must be updated every
40 milliseconds.

6.2. The Bricks


Each column of brick is managed by one thread which results in 10 separate threads (call brick-threads)
are used just to handle the bricks. When all the bricks managed by one thread are broken, the
corresponding thread must be stopped. The thread that is utilized to handle the movement of the ball
(called ball-thread) sends the instantaneous location of the ball to these threads. Each of these brick-

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.

6.3. The movement of the bar


There are 5 usable buttons (BTNL, BTNU, BTNR, BTND and BTNC) on the Zed board that you can use
to control the bar. You can use any button that is suitable.

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.

6.4.1. The reflection of the ball


In case of hitting the (left, right, upper) sides of the Brick Zone, the ball reflects in a way as shown in
Figure 4. The angle of incidence equals the angle of reflection. After bouncing back from a surface,
the speed of the ball may decrease, but in the current project, the speed is unchanged. If the ball hits
the N (normal) region on the bar, the ball will reflect similarly to the case of hitting the sides of the
Brick Zone.

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.

Figure 5 – The ball hits the corner of the brick

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.

6.4.2. The speed of the ball


The speed of the ball is calculated in pixels per second and is determined along the movement line. It
is your job to calculate the respective vertical and horizontal speeds of the ball based on the angle of
the movement line and the direction of the movement.

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:

 The game can be paused/resumed/reset.


 The player has the option to replay the game when it is over.
 The bar will be extended for some duration (maybe 10 seconds) when the ball hits the gem brick.
 The bar regions are color coded.
 Multiplayer.
 Higher FPS.
 Etc.

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.

[Link] and Brick Game project: Project Model


The Ball Game project is concerned with developing a video game, where the player attempts to break
through a wall by knocking out bricks with a ball, which he or she bounces on his paddle.

Status of project model: draft

Project manager: Sameer Younas

Personnel:

Person name Email address Contact information

13
Sameer hooligan_me@[Link] Dubai Garden
Younas
High Street

City 5

B8 6QB

Project model picture: Ball Game project

Documentation includes following graphs and subprojects:

Graph name Documentation

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:

Model name Ball Game structure - analysis

Status draft

Authors A.B.C

Documentation Preliminary classes of the game are identified.

Diagram picture: Ball Game structure - analysis

Graph dictionary

Object Type of Object Documentation

Ball Class [UML]

BallGame Class [UML]

Brick Class [UML]

Paddle Class [UML]

15
Wall Class [UML]

This model describes the class structure of the game identified in the Note text
analys...

Ball: Class [UML]


Properties:

Class name Ball

Attributes +position

Operations

Package

Abstract? F

Persistent? F

Stereotype

Overridability

Role

Parameters

Constraints

Invariant

Derivation rules

Responsibility

Documentation

Simple symbol? F

Ball relationships:

In role In relationship With objects(s) In role

: Part : Aggregation BallGame : Whole

16
Ball links:

Link type Graph's name

Decomposition None

Explosions None

BallGame: Class [UML]


Properties:

Class name BallGame

Attributes

Operations

Package

Abstract? T

Persistent? F

Stereotype

Overridability

Role

Parameters

Constraints

Invariant

Derivation rules

Responsibility

Documentation

Simple symbol? T

BallGame relationships:

In role In relationship With objects(s) In role

: Whole : Aggregation Wall : Part

: Whole : Aggregation Ball : Part

17
: Whole : Aggregation Paddle : Part

BallGame links:

Link type Graph's name

Decomposition none

Explosions none

Brick: Class [UML]


Properties:

Class name Brick

Attributes

Operations

Package

Abstract? F

Persistent? F

Stereotype

Overridability

Role

Parameters

Constraints

Invariant

Derivation rules

Responsibility

Documentation

Simple symbol? T

18
Brick relationships:

In role In relationship With objects(s) In role

: Part : Aggregation Wall : Whole

Brick links:

Link type Graph's name

Decomposition none

Explosions none

Paddle: Class [UML]


Properties:

Class name Paddle

Attributes

Operations

Package

Abstract? F

Persistent? F

Stereotype

Overridability

Role

Parameters

Constraints

Invariant

Derivation rules

Responsibility

Documentation

Simple symbol? T

19
Paddle relationships:

In role In relationship With objects(s) In role

: Part : Aggregation BallGame : Whole

Paddle links:

Link type Graph's name

Decomposition none

Explosions none

Wall: Class [UML]


Properties:

Class name Wall

Attributes

Operations

Package

Abstract? F

Persistent? F

Stereotype

Overridability

Role

Parameters

Constraints

Invariant

Derivation rules

Responsibility

Documentation

Simple symbol? T

20
Wall relationships:

In role In relationship With objects(s) In role

: Part : Aggregation BallGame : Whole

: Whole : Aggregation Brick : Part

Wall links:

Link type Graph's name

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:

Link type Graph's name

Decomposition none

Explosions none

21
Sub-objects:
A.B.C: Person
Properties:

Name A.B.C

E-mail hooligan_me@[Link]

Contact address [Link]

+position: Attribute [UML]


Properties:

Name position

Data type

Default value

Stereotype

Visibility public

Scope instance

Access

Derived? F

Persistent? F

Constraints

Documentation The ball must include location informtion.

[Link] Game structure - design: Class Diagram [UML]


Graph properties:

Model name Ball Game structure - design

Status draft

Authors Sameer Younas

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

Object Type of Object Documentation

Ball Class [UML] Ball is the basic element of the game. Player tries to remove bricks by
hitting them with the ball.

BallGame Class [UML] This is the main application class.

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.

Ball: Class [UML]


Properties:

Class name Ball

Attributes

Operations +void display() , +void calculateNewDirection(MovingObject hitObject) , +void check


position()

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:

In role In relationship With objects(s) In role

: Part : Aggregation Paddle : Part

Brick : Part

Wall : Part

BallGame : Whole

: Specialization : Generalization [UML] Wall : Specialization

Paddle : Specialization

Brick : Specialization

MovingObject : Superclass

Ball links:

Link type Graph's name

Decomposition none

Explosions States of the Ball

25
BallGame: Class [UML]
Properties:

Class name BallGame

Attributes #currentScore:int = 0 , -ballsLeft:integer = 3 , +playerName:String

Operations +void displayGameOverText() , +void displayPlayersScore() , +void playTune() , +void


decrementBalls() , +void initialize()

Package Game

Abstract? F

Persistent? F

Stereotype

Overridability

Role

Parameters

Constraints

Invariant

Derivation rules

Responsibility

Documentation This is the main application class.

Simple symbol? F

BallGame relationships:

In role In relationship With objects(s) In role

: Whole : Aggregation TopScore : Part

: Whole : Aggregation Paddle : Part

Brick : Part

Ball : Part

Wall : Part

26
BallGame links:

Link type Graph's name

Decomposition none

Explosions none

Brick: Class [UML]


Properties:

Class name Brick

Attributes +value:int = 1

Operations +void playHitSound() , +void increaseScore()

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:

In role In relationship With objects(s) In role

: Part : Aggregation Paddle : Part

Ball : Part

27
Wall : Part

BallGame : Whole

: Specialization : Generalization [UML] Wall : Specialization

Paddle : Specialization

Ball : Specialization

MovingObject : Superclass

Brick links:

Link type Graph's name

Decomposition none

Explosions none

28
MovingObject: Class [UML]
Properties:

Class name MovingObject

Attributes +position:Point = 100.0@100.0 , -velocity:Point = 0.0@2.0 , +extent:Point , -


colour:ColorValue

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:

In role In relationship With objects(s) In role

: Superclass : Generalization [UML] Wall : Specialization

Paddle : Specialization

Brick : Specialization

Ball : Specialization

29
MovingObject links:

Link type Graph's name

Decomposition none

Explosions none

Paddle: Class [UML]


Properties:

Class name Paddle

Attributes +maxSpeed

Operations +void playHitSound()

Package Game

Abstract? F

Persistent? F

Stereotype

Overridability

Role

Parameters

Constraints

Invariant

Derivation rules

Responsibility

Documentation Player tries to keep the ball in play by hitting

it with the paddle.

Simple symbol? F

Paddle relationships:

In role In relationship With objects(s) In role

: Part : Aggregation Brick : Part

30
Ball : Part

Wall : Part

BallGame : Whole

: Specialization : Generalization [UML] Wall : Specialization

Brick : Specialization

Ball : Specialization

MovingObject : Superclass

Paddle links:

Link type Graph's name

Decomposition none

Explosions none

31
TopScore: Class [UML]
Properties:

Class name TopScore

Attributes +playerName:String , +score:int = 0

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:

In role In relationship With objects(s) In role

: Part : Aggregation BallGame : Whole

TopScore links:

Link type Graph's name

Decomposition none

Explosions none

32
Wall: Class [UML]
Properties:

Class name Wall

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:

In role In relationship With objects(s) In role

: Part : Aggregation Paddle : Part

Brick : Part

Ball : Part

BallGame : Whole

: Specialization : Generalization [UML] Paddle : Specialization

Brick : Specialization

Ball : Specialization

33
MovingObject : Superclass

Wall links:

Link type Graph's name

Decomposition none

Explosions none

Sub-objects:
Sameer Younas: Person
Properties:

Name Sameer Younas

E-mail hooligan_me@[Link]

Contact address Dubai Garden

High Street

City 5

B8 6QB

34
+void display(): Operation [UML]
Properties:

Operation name display

Parameters

Return type

Overridability

Stereotype

Visibility public

Operation type instance

Preconditions

Postconditions

Body

Documentation Overriden from superclass to display a round ball rather than a square

+void calculateNewDirection(MovingObject hitObject): Operation [UML]


Properties:

Operation name calculateNewDirection

Parameters in MovingObject hitObject

Return type

Overridability

Stereotype

Visibility public

Operation type instance

Preconditions

Postconditions

Body

Documentation

35
in MovingObject hitObject: Parameter
Properties:

Parameter hitObject

Data type MovingObject

Direction in

Default value

+void check position(): Operation [UML]


Properties:

Operation name check position

Parameters

Return type

Overridability

Stereotype

Visibility public

Operation type instance

Preconditions

Postconditions

Body

Documentation Returns the location of the ball.

Game: Package
Properties:

Package name Game

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

Data type int

Default value 0

Stereotype

Visibility protected

Scope instance

Access

Derived? F

Persistent? F

Constraints

Documentation Stores the player's score in the current game.

-ballsLeft:integer = 3: Attribute [UML]


Properties:

Name ballsLeft

Data type integer

Default value 3

Stereotype

Visibility private

Scope instance

Access

Derived? F

Persistent? F

Constraints

Documentation How many balls player has left.

37
+playerName:String: Attribute [UML]
Properties:

Name playerName

Data type String

Default value

Stereotype

Visibility public

Scope instance

Access

Derived? F

Persistent? F

Constraints

Documentation Name of the player.

+void displayGameOverText(): Operation [UML]


Properties:

Operation name displayGameOverText

Parameters

Return type

Overridability

Stereotype

Visibility public

Operation type instance

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:

Operation name displayPlayersScore

Parameters

Return type

Overridability

Stereotype

Visibility public

Operation type instance

Preconditions

Postconditions

Body

Documentation This displays player's current score after the Game over text.

+void playTune(): Operation [UML]


Properties:

Operation name playTune

Parameters

Return type

Overridability

Stereotype

Visibility public

Operation type instance

Preconditions

Postconditions

Body

Documentation Plays a tune, when player misses the ball.

39
+void decrementBalls(): Operation [UML]
Properties:

Operation name decrementBalls

Parameters

Return type

Overridability

Stereotype

Visibility public

Operation type instance

Preconditions

Postconditions

Body

Documentation When player misses the ball, decrement balls left

+void initialize(): Operation [UML]


Properties:

Operation name initialize

Parameters

Return type

Overridability

Stereotype

Visibility public

Operation type instance

Preconditions

Postconditions

Body

Documentation When the game is started

40
+value:int = 1: Attribute [UML]
Properties:

Name value

Data type int

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.

+void playHitSound(): Operation [UML]


Properties:

Operation name playHitSound

Parameters

Return type

Overridability

Stereotype

Visibility public

Operation type instance

Preconditions

Postconditions

Body

Documentation When the ball hits a brick or a paddle, it makes a sound.

41
+void increaseScore(): Operation [UML]
Properties:

Operation name increaseScore

Parameters

Return type

Overridability

Stereotype

Visibility public

Operation type instance

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.

+position:Point = 100.0@100.0: Attribute [UML]


Properties:

Name position

Data type Point

Default value 100.0@100.0

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

Data type Point

Default value 0.0@2.0

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

+extent:Point: Attribute [UML]


Properties:

Name extent

Data type Point

Default value

Stereotype

Visibility public

Scope instance

Access

Derived? F

Persistent? F

Constraints

Documentation Moving objects have width and height

43
-colour:ColorValue: Attribute [UML]
Properties:

Name colour

Data type ColorValue

Default value

Stereotype

Visibility private

Scope instance

Access

Derived? F

Persistent? F

Constraints

Documentation Colour of the moving object.

+void display(): Operation [UML]


Properties:

Operation name display

Parameters

Return type

Overridability

Stereotype

Visibility public

Operation type instance

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:

Operation name move

Parameters in Point position , in int direction

Return type

Overridability

Stereotype action

Visibility public

Operation type instance

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.

in Point position: Parameter


Properties:

Parameter position

Data type Point

Direction in

Default value

in int direction: Parameter


Properties:

Parameter direction

Data type int

Direction in

Default value

45
+void checkHits(): Operation [UML]
Properties:

Operation name checkHits

Parameters

Return type

Overridability

Stereotype

Visibility public

Operation type instance

Preconditions

Postconditions

Body

Documentation Check whether moving object has hit some other object.

+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

46
+score:int = 0: Attribute [UML]
Properties:

Name score

Data type int

Default value 0

Stereotype

Visibility public

Scope instance

Access

Derived? F

Persistent? F

Constraints

Documentation

47
[Link] Game behaviour - Design: Sequence Diagram
Graph properties:

Model name Ball Game behaviour - Design

Status draft

Authors Sameer Younas

Documentation This model describes interactions among the Ball game objects during the game.

Diagram picture: Ball Game behaviour - Design

Graph dictionary

48
Object Type of Object Documentation

:Ball Lifeline object

:BallGame Lifeline object

:Brick Lifeline object

:MovingObject Lifeline object

:Paddle Lifeline object

Outside actor Outside actor

:Ball: Lifeline object


Properties:

Object name

Class Ball

Stop? F

Documentation

:Ball relationships:

In role In relationship With objects(s) In role

: Message to calculateNewDirection: Call :MovingObject : Message from

: Message to calculateNewDirection: Call :Paddle : Message from

: Message to check position: Call :MovingObject : Message from

: Return from : Return :MovingObject : Return to

: Return from position: Return :MovingObject : Return to

: Return from : Return :MovingObject : Return to

49
:Ball links:

Link type Graph's name

Decomposition none

Explosions none

:BallGame: Lifeline object


Properties:

Object name

Class BallGame

Stop? T

Documentation

:BallGame relationships:

In role In relationship With objects(s) In role

: Message from displayPlayersScore: Call :BallGame : Message to

: Message from displayGameOverText: Call :BallGame : Message to

: Message from move: Call :MovingObject : Message to

: Message from checkHits: Call :MovingObject : Message to

: Message to displayPlayersScore: Call :BallGame : Message from

: Message to displayGameOverText: Call :BallGame : Message from

: Message to decrementBalls: Call :MovingObject : Message from

: Message to : Call Outside actor : Message from

: Return from : Return Outside actor : Return to

: Return to : Return :MovingObject : Return from

50
:BallGame links:

Link type Graph's name

Decomposition none

Explosions none

:Brick: Lifeline object


Properties:

Object name

Class Brick

Stop? F

Documentation

:Brick relationships:

In role In relationship With objects(s) In role

: Message to increaseScore: Call :MovingObject : Message from

: Message to playHitSound: Call :MovingObject : Message from

: Return from : Return :MovingObject : Return to

: Return from : Return :MovingObject : Return to

:Brick links:

Link type Graph's name

Decomposition none

Explosions none

51
:MovingObject: Lifeline object
Properties:

Object name

Class MovingObject

Stop? F

Documentation

:MovingObject relationships:

In role In relationship With objects(s) In role

: Message from check position: Call :Ball : Message to

: Message from decrementBalls: Call :BallGame : Message to

: Message from playHitSound: Call :Brick : Message to

: Message from playHitSound: Call :Paddle : Message to

: Message from increaseScore: Call :Brick : Message to

: Message from calculateNewDirection: Call :Ball : Message to

: Message to move: Call :BallGame : Message from

: Message to checkHits: Call :BallGame : Message from

: Return from : Return :BallGame : Return to

: Return to : Return :Brick : Return from

: Return to : Return :Ball : Return from

: Return to position: Return :Ball : Return from

: Return to : Return :Ball : Return from

: Return to : Return :Brick : Return from

:MovingObject links:

Link type Graph's name

Decomposition none

Explosions none

52
:Paddle: Lifeline object
Properties:

Object name

Class Paddle

Stop? F

Documentation

:Paddle relationships:

In role In relationship With objects(s) In role

: Message from calculateNewDirection: Call :Ball : Message to

: Message to playHitSound: Call :MovingObject : Message from

:Paddle links:

Link type Graph's name

Decomposition none

Explosions none

Outside actor: Outside actor


Properties:

none

Outside actor relationships:

In role In relationship With objects(s) In role

: Message from : Call :BallGame : Message to

: Return to : Return :BallGame : Return from

53
Outside actor links:

Link type Graph's name

Decomposition none

Explosions none

Sub-objects:
Sameer Younas: Person
Properties:

Name Sameer Younas

E-mail hooligan_me@[Link]

Contact address Dubai Garden

High Street

City 5

B8 6QB

54
Ball: Class [UML]
Properties:

Class name Ball

Attributes

Operations +void display() , +void calculateNewDirection(MovingObject hitObject) , +void check


position()

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:

Operation name display

Parameters

Return type

Overridability

Stereotype

Visibility public

Operation type instance

Preconditions

Postconditions

Body

Documentation Overriden from superclass to display a round ball rather than a square

+void calculateNewDirection(MovingObject hitObject): Operation [UML]


Properties:

Operation name calculateNewDirection

Parameters in MovingObject hitObject

Return type

Overridability

Stereotype

Visibility public

Operation type instance

Preconditions

Postconditions

Body

Documentation

56
in MovingObject hitObject: Parameter
Properties:

Parameter hitObject

Data type MovingObject

Direction in

Default value

+void check position(): Operation [UML]


Properties:

Operation name check position

Parameters

Return type

Overridability

Stereotype

Visibility public

Operation type instance

Preconditions

Postconditions

Body

Documentation Returns the location of the ball.

Game: Package
Properties:

Package name Game

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:

Class name BallGame

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:

Class name Brick

Attributes +value:int = 1

Operations +void playHitSound() , +void increaseScore()

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

Data type int

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.

+void playHitSound(): Operation [UML]


Properties:

Operation name playHitSound

Parameters

Return type

Overridability

Stereotype

Visibility public

Operation type instance

Preconditions

Postconditions

Body

Documentation When the ball hits a brick or a paddle, it makes a sound.

60
+void increaseScore(): Operation [UML]
Properties:

Operation name increaseScore

Parameters

Return type

Overridability

Stereotype

Visibility public

Operation type instance

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:

Class name MovingObject

Attributes +position:Point = 100.0@100.0 , -velocity:Point = 0.0@2.0 , +extent:Point , -


colour:ColorValue

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

Data type Point

Default value 100.0@100.0

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.

-velocity:Point = 0.0@2.0: Attribute [UML]


Properties:

Name velocity

Data type Point

Default value 0.0@2.0

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

Data type Point

Default value

Stereotype

Visibility public

Scope instance

Access

Derived? F

Persistent? F

Constraints

Documentation Moving objects have width and height

-colour:ColorValue: Attribute [UML]


Properties:

Name colour

Data type ColorValue

Default value

Stereotype

Visibility private

Scope instance

Access

Derived? F

Persistent? F

Constraints

Documentation Colour of the moving object.

64
+void display(): Operation [UML]
Properties:

Operation name display

Parameters

Return type

Overridability

Stereotype

Visibility public

Operation type instance

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.

+void move(Point position, int direction): Operation [UML]


Properties:

Operation name move

Parameters in Point position , in int direction

Return type

Overridability

Stereotype action

Visibility public

Operation type instance

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

Data type Point

Direction in

Default value

in int direction: Parameter


Properties:

Parameter direction

Data type int

Direction in

Default value

+void checkHits(): Operation [UML]


Properties:

Operation name checkHits

Parameters

Return type

Overridability

Stereotype

Visibility public

Operation type instance

Preconditions

Postconditions

Body

Documentation Check whether moving object has hit some other object.

66
Paddle: Class [UML]
Properties:

Class name Paddle

Attributes +maxSpeed

Operations +void playHitSound()

Package Game

Abstract? F

Persistent? F

Stereotype

Overridability

Role

Parameters

Constraints

Invariant

Derivation rules

Responsibility

Documentation Player tries to keep the ball in play by hitting

it with the paddle.

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

You might also like