Report
Report
On
Brick Breaker Game By java
Submitted during fourth semester in partial fulfillment of the requirements
for the award of degree of
Bachelor of Technology
In
Tanishq Saini
(21001050021)
&
Love
(22001050501)
Under supervision of
Dr. Umesh
FARIDABAD-121006
JUL-DEC 2023
CANDIDATE’S DECLARATION
I hereby certify that the work which is being presented in this Minor thesis titled
“Brick Breaker Game” in fulfilment of the requirement for the degree of Bachelor
of Technology in Computer Engineering and submitted to “J. C. Bose University of
Science and Technology, YMCA, Faridabad”, is an authentic record of my own
work carried out under the supervision of Dr. Umesh.
The work contained in this thesis has not been submitted to any other
University or Institute for the award of any other degree or diploma by me.
Tanishq Saini
(21001050021)
Love
(22001050501)
CERTIFICATE
This is to certify that the project titled “Brick Breaker Game” submitted by
Tanishq Saini and Love to “J. C. Bose University of Science and Technology,
YMCA, Faridabad” for the award of the degree of Bachelor of Technology in
Computer Engineering is a record of bonafide work carried out by both under
my supervision. In my opinion, the thesis has reached the standards of fulfilling
the requirements of the regulations to the degree
Dr. Umesh
( Mentor)
Assistant Professor
Department of
Computer
Engg,
J. C. Bose University of Science and Technology, YMCA, Faridabad
ACKNOWLEDGEMENT
It is with deep sense of gratitude and reverence that I express my sincere thanks to
my supervisor Dr. Umesh for her guidance, encouragement, help and useful
suggestions throughout. Her untiring and painstaking efforts, methodical approach
and individual help made it possible for me to complete this work in time. I consider
myself very fortunate to have been associated with a scholar like her. Her affection,
guidance and scientific approach served a veritable incentive for completion of this
work.
Tanishq Saini
Love
TABLE OF CONTENTS
1. CANDIDATES ‘S DECLARATION
2.CERTIFICATE
3.ACKNOWLEDGEMENT
ABOUT PROJECT:
1. Introduction
2.Objectives
3.Methodology
4.Implementation of code:
4.1 Main.java
4.2 MapGenerator.java
4.3 GamePlay.java
5.Output snapshots
6.Conclusion
1. INTRODUCTION:
The Brick Breaker game is a classic arcade game that has entertained players for
decades. It challenges players to break a formation of bricks using a paddle and a
bouncing ball. The game requires precise control, quick reflexes, and strategic
planning. In this project, we aim to develop a Brick Breaker game using the Java
programming language, utilizing its graphics libraries and features.
2.OBJECTIVES:
The objective of the Brick Breaker game is to control a paddle at the bottom of
the screen and use it to bounce a ball upward, aiming to break a formation of
bricks positioned at the top. The player's goal is to destroy as many bricks as
possible by accurately rebounding the ball off the paddle, without letting the ball
fall off the bottom of the screen. Each time a brick is destroyed, the player earns
points, and the game becomes more challenging as the level progresses.
Players will control a paddle at the bottom of the screen to bounce a ball
upwards, breaking bricks positioned at the top. The game will keep track of the
score and provide an engaging and challenging experience for the players.
3.METHODOLOGY:
import java.awt.Color;
import javax.swing.JFrame;
The code imports necessary classes from the java.awt and javax.swing packages.
These packages provide the required classes for creating graphical user interfaces
(GUI) and managing the game window.
JFrame obj = new JFrame();
Gameplay gamePlay = new Gameplay();
Here, an instance of JFrame is created and named obj. JFrame represents the
game window. Additionally, an instance of the Gameplay class is created, which is
responsible for rendering the game and handling user interactions.
obj.add(gamePlay);
obj.setVisible(true);
Here, the gamePlay object, which represents the gameplay area, is added to the
game window using the add method. This ensures that the game is rendered
within the window. Finally, setVisible(true) is called again to ensure the window
is visible to the user.
4.2 MapGenerator.java
1. Variables:
map: This is a 2-dimensional integer array that represents the game
map. Each element in the array corresponds to a brick on the screen.
brickWidth and brickHeight: These variables store the width and
height of each brick.
2. Constructor:
The constructor takes in row and col as parameters, representing the
number of rows and columns of bricks in the game.
It initializes the map array with the given dimensions and sets each
element to 1, indicating the presence of a brick.
The brickWidth and brickHeight variables are calculated based on
the size of the game screen and the number of rows and columns.
3. draw method:
This method is responsible for rendering the bricks on the game
screen.
It uses a nested loop to iterate over each element in the map array.
If the value of an element is greater than 0, indicating the presence
of a brick, it proceeds to draw the brick.
The brick is drawn as a filled rectangle using the fillRect method,
with its position and size calculated based on the brickWidth and
brickHeight variables.
Additionally, a black rectangle is drawn around each brick using the
drawRect method to provide a visual separation between the bricks.
4. setBrickValue method:
This method allows you to set the value of a specific brick in the map
array.
It takes in the value to be set, as well as the row and col coordinates
of the brick in the array.
By modifying the value at the specified coordinates, you can add or
remove bricks from the game dynamically.
4.3 Gameplay.java
1. Variables:
play: A boolean variable that indicates whether the game is currently
in progress or not.
score: An integer variable that stores the player's score.
totalBricks: An integer variable that keeps track of the total number
of bricks in the game.
timer: A Timer object that triggers an action event at a specified
delay.
delay: An integer variable that determines the delay between each
action event.
playerX: An integer variable that represents the X-coordinate of the
paddle.
ballposX and ballposY: Integer variables that represent the X and Y
coordinates of the ball.
ballXdir and ballYdir: Integer variables that store the direction of the
ball's movement.
map: An instance of the MapGenerator class, responsible for
generating and managing the bricks.
2. Constructor:
The constructor initializes the map object by creating a new instance
of MapGenerator with 4 rows and 12 columns of bricks.
It adds the KeyListener and sets the focusable and focus traversal
keys enabled properties of the JPanel.
Lastly, it starts the Timer object to begin the game loop.
3. paint method:
This method is responsible for rendering the game elements on the
screen.
It first fills the background with a black color.
It then calls the draw method of the MapGenerator object to draw
the bricks on the screen.
Next, it draws the borders, the player's score, the paddle, and the
ball using various colors and shapes.
If the player wins the game (no remaining bricks), it displays a victory
message.
If the player loses the game (ball goes below the paddle), it displays a
game over message.
Finally, the method disposes of the graphics object.
4. keyPressed method:
This method is called when a key is pressed.
If the right arrow key is pressed and the paddle is not at the
rightmost boundary, it moves the paddle to the right.
If the left arrow key is pressed and the paddle is not at the leftmost
boundary, it moves the paddle to the left.
If the Enter key is pressed and the game is not in progress, it resets
the game by reinitializing various variables and creating a new
instance of MapGenerator.
5. moveRight and moveLeft methods:
These methods are called to move the paddle to the right and left,
respectively.
They update the playerX variable accordingly.
6. actionPerformed method:
This method is triggered by the Timer object at a specified delay.
If the game is in progress, it checks for collisions between the ball
and the paddle or the bricks.
If a collision occurs, it updates the ball's direction and removes the
collided brick.
It also updates the ball's position, checks for collisions with the game
boundaries, and updates the player's score.
If all bricks are destroyed, it displays a victory message and stops the
game.
If the ball goes below the paddle, it displays a game over message
and stops the game.
Finally, it triggers a repaint to update the game screen
5.OUTPUT SNAPSHOTS: 1. When we run our main file on cmd .
OUTPUT:
2.We can start playing game by entering the enter key from the keyboard.
3.After completing the game .
Output: