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

Report

The project report details the development of a Brick Breaker game using Java, fulfilling the requirements for a Bachelor of Technology in Computer Engineering. It outlines the game's objectives, methodology, implementation, and key components, including the MapGenerator and Gameplay classes. The game offers an engaging experience where players control a paddle to bounce a ball and destroy bricks, with features such as score tracking and game over conditions.

Uploaded by

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

Report

The project report details the development of a Brick Breaker game using Java, fulfilling the requirements for a Bachelor of Technology in Computer Engineering. It outlines the game's objectives, methodology, implementation, and key components, including the MapGenerator and Gameplay classes. The game offers an engaging experience where players control a paddle to bounce a ball and destroy bricks, with features such as score tracking and game over conditions.

Uploaded by

Tanishq Saini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Project 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

Computer Engineering (Hindi)


By

Tanishq Saini
(21001050021)
&
Love
(22001050501)
Under supervision of

Dr. Umesh

Department of Computer Engineering


J. C. BOSE UNIVERSITY OF SCIENCE & TECHNOLOGY, YMCA

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.

I shall ever remain indebted to the faculty members of J. C. Bose University of


Science and Technology, YMCA, Faridabad and all my classmates for their
cooperation, kindness and general help extended to me during the completion of
this work.

Although it is not possible to name them individually, I cannot forget my well-


wishers at J. C. Bose University of Science and Technology, YMCA, Faridabad and
outsiders for their persistent support and cooperation.

This acknowledgement will remain incomplete if I fail to express my deep sense of


obligation to myself for the consistent self-motivation and self-encouragement.

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:

To develop the Brick Breaker game in Java, we followed a systematic approach


that involved several key steps:
a. Game Environment Setup: We utilized Java's graphics libraries, such as Java
AWT or JavaFX, to create a graphical user interface (GUI) for the game. This
included setting up the game window, defining the dimensions, and creating the
necessary components such as the paddle, ball, and bricks.
b. Game Logic Implementation: We implemented the underlying game logic to
handle various aspects of the gameplay. This included coding collision detection
algorithms to detect when the ball hits the paddle or bricks, updating the position
of the ball and paddle based on user input, and managing the state of the bricks
(such as tracking which bricks have been destroyed).
c. User Input Handling: We incorporated event handling mechanisms to respond
to user input effectively. This involved capturing keyboard or mouse events to
move the paddle left or right, allowing the player to control its position and
influence the direction of the ball.
d. Scoring and Level Progression: We implemented a scoring system to keep track
of the player's performance, incrementing the score each time a brick is
destroyed. Additionally, we designed the game to have multiple levels, with each
level presenting a new arrangement of bricks and potentially introducing
additional challenges.
e. Visual Design and Feedback: We focused on creating an appealing visual design
for the game, including designing visually engaging sprites for the paddle, ball,
and bricks. We also incorporated appropriate visual feedback, such as animations
or effects when a brick is destroyed or when the game is over.

4.IMPLEMENTATION OF THE CODE:


4.1. Main.java->
The Main.java file provided represents the main entry point for the Brick Breaker
game.

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.setBounds(10, 10, 700, 600);


obj.setTitle("Breakout Ball");
obj.setResizable(false);
obj.setVisible(true);
obj.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

These lines of code configure the game window (obj).


 setTitle sets the title of the window to "Breakout Ball".
 setResizable is set to false, which means the window cannot be resized by
the user.
 setVisible makes the window visible to the user.
 setDefaultCloseOperation specifies that the application should exit when
the window is closed.

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:

4.You get a score of 5 for every brick.


5.Total score for one game is 105.
6.You can restart the game by pressing the enter key from the keyboard.
6.CONCLUSION:

The Brick Breaker game implemented in Java provides an interactive gaming


experience where players control a paddle to bounce a ball and destroy bricks.
The game consists of several key components:
1. MapGenerator: This class generates and manages the bricks' layout on the
game screen.
2. Gameplay: This class handles the main gameplay logic, including rendering
the game elements, detecting collisions, updating the score, and managing
game over/win conditions.
The game features include:
 The player controls the paddle using the left and right arrow keys to
prevent the ball from falling off the screen.
 The ball bounces off the paddle and destroys bricks when it collides with
them.
 The player earns points for each brick destroyed.
 The game ends when the ball falls below the paddle, and a game over
message is displayed.
 If the player successfully destroys all the bricks, a victory message is
displayed.
 The player can restart the game by pressing the Enter key.
Overall, the Brick Breaker game provides an enjoyable gaming experience that
tests the player's reflexes and aiming skills. It demonstrates the use of basic game
mechanics such as collision detection, score tracking, and game state
management.

You might also like