0% found this document useful (0 votes)
8 views40 pages

Brick Breaker Game Project Report

The Brick Breaker Game project report details the development of a Java Swing desktop arcade game where players control a paddle to bounce a ball and break bricks across multiple levels. The game incorporates object-oriented programming principles, real-time physics, and modular design to enhance gameplay, featuring collision detection, scoring, and level progression. This project serves as an educational tool for Java programming, showcasing key concepts in game development and offering potential for future enhancements.

Uploaded by

n85242171
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)
8 views40 pages

Brick Breaker Game Project Report

The Brick Breaker Game project report details the development of a Java Swing desktop arcade game where players control a paddle to bounce a ball and break bricks across multiple levels. The game incorporates object-oriented programming principles, real-time physics, and modular design to enhance gameplay, featuring collision detection, scoring, and level progression. This project serves as an educational tool for Java programming, showcasing key concepts in game development and offering potential for future enhancements.

Uploaded by

n85242171
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

BRICK BREAKER GAME

A PROJECT REPORT

Submitted by

[Link] ( 8115U24EC067 )

in partial fulfillment of requirements for the award of the course

EGB1201 - JAVA PROGRAMMING

in

DEPARTMENT OF

ELECTRONICS AND COMMUNICATION ENGINEERING

Under the Guidance of

[Link] M.E.,(Ph.D.,)

Department of Computer Science and Engineering

K. RAMAKRISHNAN COLLEGE OF ENGINEERING


(AUTONOMOUS)
SAMAYAPURAM, TRICHY– 621112.

ANNA UNIVERSITY
CHENNAI 600025.

DECEMBER - 2025
K. RAMAKRISHNAN COLLEGE OF ENGINEERING
(AUTONOMOUS)
SAMAYAPURAM – 621 112

BONAFIDE CERTIFICATE

Certified that this project report on “BRICK BREAKER GAME” is the


bonafide work of [Link] ( 8115U24EC067 ) who carried out the project
work during the academic year 2025 - 2026 under my supervision.

SIGNATURE SIGNATURE

Dr. R. SASIKUMAR ,M.E.,Ph.D., [Link] ,M.E.,(Ph.D),

HEAD OF THE DEPARTMENT SUPERVISOR

ASSISTANT PROFESSOR ASSISTANT PROFESSOR

Department of CSE Department of CSE

K. Ramakrishnan College of Engineering K. Ramakrishnan College of Engineering


(Autonomous) (Autonomous)

Samayapuram – 621 112. Samayapuram – 621 112.

Submitted for the viva-voce examination held on …………….

INTERNAL EXAMINER EXTERNAL EXAMINER

ii
DECLARATION

I declare that the project report on “BRICK BREAKER GAME” is the result
of original work done by me and best of my knowledge, similar work has not been
submitted to “ANNA UNIVERSITY CHENNAI” for the requirement of Degree of
BACHELOR OF ENGINEERING. This project report is submitted on the partial
fulfilment of the requirement of the completion of the course EGB1201 – JAVA
PROGRAMMING.

Signature

NIRANJAN.S

Place: Samayapuram
Date:

iii
ACKNOWLEDGEMENT

It is with great pride that I express my gratitude and in-debt to my institution


“[Link] College of Engineering (Autonomous)”, for providing me with
the opportunity to do this project.

I glad to credit honourable chairman Dr. K. RAMAKRISHNAN, B.E., for


having provided for the facilities during the course of my study in college.

I would like to express my sincere thanks to our beloved Executive Director


Dr. S. KUPPUSAMY, MBA, Ph.D., for forwarding my project and offering adequate
duration in completing my project.

I would like to thank Dr. D. SRINIVASAN, B.E, M.E., Ph.D., Principal, who
gave opportunity to frame the project the full satisfaction.

I whole heartily thanks to [Link],M.E.,Ph.D., Head of the


department, COMPUTER SCIENCE AND ENGINEERING for providing his
encourage pursuing this project.

I express my deep expression and sincere gratitude to my project supervisor


[Link], M.E.,(Ph.D), Department of COMPUTER SCIENCE AND
ENGINEERING, for his incalculable suggestions, creativity, assistance and patience
which motivated me to carry out this project.

I render my sincere thanks to Course Coordinator and other staff members for
providing valuable information during the course.

I wish to express my special thanks to the officials and Lab Technicians of my


department who rendered their help during the period of the work progress.

iv
VISION

To be distinguished as a prominent program in Electronics and Communication

Engineering Studies by preparing students for Industrial Competitiveness and


Societal Challenges.

MISSION

M1. To equip the students with latest technical, analytical and practical
knowledge

M2. To provide vibrant academic environment and Innovative Research


culture M3. To provide opportunities for students to get Industrial Skills and
Internships to meet out the challenges of the society.

PROGRAM EDUCATIONAL OBJECTIVES (PEO’S)

PEO1: Graduates will become experts in providing solution for the Engineering
problems in Industries, Government and other organizations where they are
employed.
PEO2: Graduates will provide innovative ideas and management skills to
enhance the standards of the society by individual and with team works through
the acquired Engineering knowledge.
PEO3: Graduates will be successful professionals through lifelong learning and
contribute to the society technically and professionally.

PROGRAM SPECIFIC OUTCOMES (PSO’S)

PSO1: Analyze and design complex electronic circuits and communication


systems by applying the principles of engineering and mathematics.

PSO2: Analyze and provide innovative design solutions to research problems,

v
industrial problems and for the demanding needs of the society in the domains of
electronic integrated circuits, signal processing, high frequency and antenna
design.

PSO3: Continuously involve in life-long learning activities so as to evolve and


become an active team member in diverse and challenging design situations.

PROGRAM OUTCOMES

PO1: Engineering knowledge: Apply the knowledge of mathematics, science,


engineering fundamentals, and an engineering specialization to the solution of
complex engineering problems.
PO2: Problem analysis: Identify, formulate, review research literature, and
analyze complex engineering problems reaching substantiated conclusions using
first principles of mathematics, natural sciences, and engineering sciences.
PO3: Design/development of solutions: Design solutions for complex
engineering problems and design system components or processes that meet the
specified needs with appropriate consideration for the public health and safety,
and the cultural, societal, and environmental considerations.
PO4: Conduct investigations of complex problems: Use research-based
knowledge and research methods including design of experiments, analysis and
interpretation of data, and synthesis of the information to provide valid
conclusions.

PO5: Engineering tool usage: Create, select, and apply appropriate techniques,
resources, and modern engineering and IT tools including prediction and
modeling to complex engineering activities with an understanding of the
limitations.

PO6: The Engineer and The World: Apply reasoning informed by the

vi
contextual knowledge to assess societal, health, safety, legal and cultural issues
and the consequent responsibilities relevant to the professional engineering
practice.
PO7: Ethics: Apply ethical principles and commit to professional ethics and
responsibilities and norms of engineering practice.
PO8: Individual and Collaborative Teamwork: Function effectively as an
individual, and as a member or leader in diverse teams, and in multidisciplinary
settings.
PO9: Communication: Communicate effectively on complex engineering
activities with the engineering community and with society at large. Some of
them are, being able to comprehend and write effective reports and design
documentation, make effective presentations, and give and receive clear
instructions.
PO10: Project Management and Finance: Demonstrate knowledge and
understanding of the engineering and management principles and apply these to
one’s own work, as a member and leader in a team, to manage projects and in
multidisciplinary environments.
PO11: Life-long learning: Recognize the need for and have the preparation and
ability to engage in independent and lifelong learning in the broadest context of
technological change.

CO-PO MAPPING

PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PSO1 PSO2 PSO3

✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓

vii
ABSTRACT

The Brick Breaker Game is a comprehensive Java Swing desktop arcade


application where players control a paddle at screen bottom to bounce a ball and
destroy colored bricks arranged in progressive levels. The primary objective is
clearing all bricks across three difficulty tiers while managing three lives, with
each level featuring increased brick density, varied layouts, and accelerated ball
speeds for escalating challenge. Developed using object-oriented principles, the
project modularizes functionality across [Link] (window initialization),
[Link] (core logic, collision detection, rendering, state management),
and [Link] (dynamic brick grids with level-specific colors). Key
features include real-time Graphics2D animation via 8ms Timer loop, precise
rectangle-based collision handling for ball-paddle/wall/brick interactions, 5-point
scoring per brick, lives reset mechanism, front-page menu with instructions
toggle (I key), level-complete notifications, game-over/victory screens, and
intuitive keyboard controls (arrows for paddle, SPACE for launch, ENTER for
start/restart, ESC for exit). Technologies utilized encompass Java JDK 17, Swing
(JFrame/JPanel), AWT Graphics2D, KeyListener/ActionListener for event-
driven gameplay. This self-contained project exemplifies Java GUI/game
programming fundamentals—physics simulation, input handling, modular
design—serving as an educational prototype with expansion potential for sound
effects, power-ups, high-score persistence, and multiplayer networking.

viii
ABSTRACT WITH POs AND PSOs MAPPING

CO 5 : BUILD JAVA APPLICATIONS FOR SOLVING REAL-TIME PROBLEMS

ABSTRACT POs MAPPED PSOs MAPPED


The Brick Breaker Game is a Java Swing-based desktop
arcade game where players control a paddle to bounce a
ball and break bricks arranged in multiple levels. The
objective is to clear all bricks while managing three
lives, with increasing difficulty across three levels
featuring more bricks and faster ball speeds. The game PO1 -3

uses object-oriented programming with modular classes PO2 -3

and real-time rendering via Java's Graphics2D API. Key PO3 -3


PO4 -3
features include collision detection between the ball and
PO5 -3
bricks, paddle, and walls; scoring with points awarded PSO1 -3
PO6 -3
per brick broken; lives management resetting the ball PSO2 -3
PO7 -3
after misses; and user controls via keyboard for paddle
PO8 -3
movement, ball launch, and game navigation. The game
PO9 -3
structure includes [Link] for window setup, PO10 -3
[Link] for main logic and rendering, and PO11-3
[Link] for brick layouts. Implemented
technologies include Java JDK 17, Swing, AWT
Graphics, and Timer for animation. This project
provides an educational tool for Java game development,
blending interactive gameplay with core programming
concepts and offering scope for future improvements.

Note: 1- Low, 2-Medium, 3- High

ix
TABLE OF CONTENTS
CHAPTER NO. TITLE PAGE NO.

ABSTRACT ix

1 INTRODUCTION 1

1.1 Objective 1

1.2 Overview 2

1.3 Technologies Used 2

2 PROJECT METHODOLOGY 3

2.1 Problem Definition 3

2.2 Proposed Work 4

2.3 Architecture Diagram 6

3 MODULE DESCRIPTION 7

3. 3.1 Paddle Control Module 7

3.2 Ball Movement and Collision Module 7

3.3 Brick Management Module 7

3.4 Score and Lives Management Module 7

3.5 Level Progression Module 7

3.6 User Interface (UI) Module 8

3.7 Input Management Module 8

3.8 Game State and Control Module 8

x
4 CONCLUSION & FUTURE SCOPE 9

4.1 Conclusion 9

4.2 Future Scope 10

APPENDIX A (SOURCE CODE) 11

APPENDIX B (SCREENSHOTS) 25

REFERENCES 29

xi
CHAPTER 1

INTRODUCTION

1.1 Objective

The Brick Breaker Game is a classic arcade-style game developed as a desktop


application using Java Swing. The game centers on a player-controlled paddle at the
bottom of the screen that bounces a ball to break colored bricks arranged in rows at the
top. Designed to simulate real-time physics with smooth animations, the game pro-
gressively increases in difficulty across multiple levels. Each level features different
brick layouts and faster ball speeds. Using Java's GUI and event-driven programming
capabilities, the game offers interactive controls, such as keyboard input for paddle
movement and ball launch. This project highlights the practical use of object-oriented
concepts, collision detection, and real-time rendering, serving as a foundational project
for learning game development in [Link] objective is to demonstrate practical
implementation of object-oriented programming concepts in a real-world application.
The system is designed to handle data in memory, providing quick access and modifi-
cation of records. It also lays the foundation for future database integration to store
data persistently. The primary objective of this project is to develop a multi-level Brick
Breaker Game using Java Swing, emphasizing the application of object-oriented pro-
gramming concepts. It aims to create an engaging user interface where players control
a paddle to bounce a ball and break bricks efficiently. Key goals include implementing
real-time collision detection between the ball, paddle, and bricks, managing game
states including score, lives, and level transitions, and providing intuitive keyboard
controls. The project also focuses on modular code structure for easy maintenance and
future extension, making it a practical learning tool for students.

1
1.2 Overview
The Brick Breaker Game starts with a welcoming front page displaying the
title and instructions. Upon starting, players use the left and right arrow keys to
control the paddle and the spacebar to launch the ball. The ball moves automatically,
bouncing off walls, bricks, and the paddle. Each brick destroyed adds to the player's
score. Players have three lives that decrease if the ball falls below the paddle.
Clearing all bricks advances the player to the next level, where brick patterns and ball
speed increase. The game concludes with either a "Game Over" or "Congratulations"
screen based on player performance.

1.3 Technologies Used

Java (JDK 17)

Java is a versatile, object-oriented programming language that powers the core


application logic of the Alumni Management System. It provides robust support for
modular programming, event handling, and memory management. Its extensive stand-
ard library and third-party APIs simplify tasks such as GUI creation, data storage, and
input validation, making it ideal for building desktop applications.

Java Swing

Java Swing is a GUI toolkit that enables the creation of native-feel desktop applications
with a wide variety of components and layouts.

Key Features:

• Rich Component Set – buttons, tables, dialogs, labels.


• Event-Driven Programming – handles user actions efficiently.

2
CHAPTER 2

PROJECT METHODOLOGY

2.1 Problem Description


The Brick Breaker Game primarily exists as a web or mobile application,
limiting accessibility for Java programming students who require a desktop-based
learning example for academic projects. Beginners often face difficulties
implementing essential game mechanics such as real-time physics simulation, precise
collision detection between the moving ball and other objects, smooth timer-based
animations, and keyboard event processing within the Java Swing framework. Many
existing tutorials provide fragmented code snippets lacking a complete modular
structure, comprehensive state management across multiple game screens (front page,
gameplay, level complete, game over), persistent score and lives tracking, and
progressive difficulty scaling through various brick layouts and velocity adjustments.
Therefore, students need a fully functional, self-contained Java Swing project that
integrates object-oriented design patterns, Graphics2D rendering, KeyListener input
handling. Timer game loop implementation. This project serves as both a playable
demonstration and an extensible educational template for understanding the complete
game development lifecycle, from initialization through user interaction to final state
resolution.

The proposed solution is a standalone Java Swing desktop application featuring


a clean, three-class modular architecture, systematically separating window lifecycle
management ([Link]), comprehensive game logic and rendering ([Link]),
and dynamic brick layout generation ([Link]). The system uses an 8ms
[Link]-driven main game loop to deliver smooth animation at roughly
125 FPS.

3
The game architecture follows a strict three-tier MVC-inspired design ensuring
clean separation of concerns. The Presentation Layer ([Link]) initializes the
JFrame container and embeds the GamePlay JPanel as the rendering surface. The
Controller Layer ([Link]) manages the entire game lifecycle, implementing
keyboard listeners for game control and a timer-based loop for state updates and
rendering. It maintains all game states including score, lives, level, ball position and
direction, paddle position, and play status flags across different screens such as the
front page, instruction screen, gameplay, and end screens. The Model Layer
([Link]) encapsulates the two-dimensional brick layout, calculating
brick dimensions and setting level-specific colors. It provides essential methods to
draw bricks and update their status when hit. Collision detection is efficiently
implemented using Rectangle intersection checks with controlled flow to ensure
single hit registration per frame, supporting high-frame-rate rendering typical of
optimized Swing game development.

2.2 Proposed Work


The proposed Brick Breaker Game is a standalone Java Swing desktop
application featuring clean three-class modular architecture separating window
management ([Link]), core game logic ([Link]), and brick generation
([Link]). The system implements production-quality 8ms
[Link]-driven main game loop delivering smooth animation,
sophisticated [Link]() collision detection for ball-paddle bounce physics
with velocity reflection, ball-wall boundary reversal, and brick destruction with 5-
point scoring. Progressive three-level difficulty automatically scales brick density
(3×7 → 4×8 → 5×9) and ball speed while preserving directional consistency across
levels.

4
Keyboard controls provide intuitive paddle movement (arrow keys ±25px), ball
launch (SPACEBAR), level advancement (SPACE after completion), game
start/restart (ENTER), instructions toggle (I key), and ESC exit confirmation with
JOptionPane dialog. Front-page menu displays title, controls summary, and exit
prompt while gameplay HUD shows real-time score/lives/level at top border.
Persistent tracking maintains score/lives across entire playthrough with automatic
level-complete transitions displaying "LEVEL X COMPLETE!" message prompting
next stage advancement.

The implementation delivers immediately playable experience with five


distinct game states (front page, instructions overlay, active play, level complete,
game over/victory) ensuring comprehensive user onboarding, intuitive controls,
visual feedback, and graceful state resolution. Modular design establishes extensible
foundation supporting future sound integration, power-ups (multi-ball, paddle resize),
high-score persistence via file I/O, additional levels/themes, and advanced features
while maintaining clean separation of concerns characteristic of professional Java
game development practices suitable for academic demonstration and portfolio
presentation.

5
2.3 Architecture Diagram

Fig. 2.1: Brick Breaker Game

6
CHAPTER 3

MODULE DESCRIPTION

3.1 Paddle Control Module


This module manages the paddle's horizontal movement controlled by the player
using keyboard arrow keys. It ensures smooth left and right motion within window
boundaries. It also handles the paddle's position initialization and resets during level
transitions or after losing lives to maintain proper gameplay balance.

3.2 Ball Movement and Collision Module

This module is responsible for the real-time movement of the ball and all
collision detections. It detects collisions between the ball and paddle, bricks, and
window borders, updates ball direction accordingly, and triggers brick destruction. It
computes ball position updates based on velocity vectors and enforces game physics
realistically.

3.3 Brick Management Module

This module generates and manages the grid layout of bricks for each level. It
maintains the 2D array representing bricks, their positions, and visibility state after
collisions. It supports drawing bricks with level-specific colors and handles updates
when a brick is destroyed to remove it from the display.

3.4 Score and Lives Management Module

This module tracks and updates the player’s score and remaining lives. It adds
points when bricks are broken, reduces lives when the ball falls below the paddle, and
provides game-over detection. This information is displayed on the game screen,
keeping players informed of their progress.

3.5 Level Progression Module

This module manages the progression between multiple levels. It adjusts brick

7
layout complexity and ball speed based on the current level. Upon clearing all bricks,
it advances the game state, resets positions, and prepares the next level. It also handles
win condition detection and displays victory messages.

3.6 User Interface (UI) Module


This module handles the graphical user interface elements such as the front
page, in-game HUD (score, lives, level), instruction screen, and end-game messages.
It draws all visual components using Graphics2D and manages screen refreshes
according to the game state.

3.7 Input Management Module


This module processes user keyboard inputs for controlling the paddle,
launching the ball, starting or restarting the game, toggling instructions, and exiting. It
ensures responsive control by implementing KeyListener interface handling relevant
key events.

3.8 Game State and Control Module


This module manages the overall game state machine including menus, active
gameplay, pauses, level completions, and game-over conditions. It controls transitions
between states and ensures consistent updates to all other modules. It handles timer
events to run the main game loop, coordinating rendering and logic updates.

8
CHAPTER 4

CONCLUSION & FUTURE SCOPE

4.1 CONCLUSION
The Brick Breaker Game project successfully delivers a complete, fully
functional Java Swing desktop arcade application demonstrating professional game
development practices through clean modular architecture and robust
implementation.

The three-class structure ([Link], [Link], [Link])


effectively separates window management, core game logic, and data modeling
responsibilities while implementing production-quality features including 8ms
Timer-driven smooth animation, precise Rectangle-based collision detection,
progressive three-level difficulty scaling, persistent score/lives tracking, intuitive
keyboard controls, and comprehensive state management across five distinct screens
(front page, gameplay, level complete, game over, victory).

The project exemplifies object-oriented design principles, event-driven


programming via KeyListener/ActionListener interfaces, real-time Graphics2D
rendering, and game physics simulation including velocity reflection and boundary
collision handling.

This self-contained application provides immediate playability while serving


as an exemplary educational template for Java GUI/game programming suitable for
academic coursework, technical portfolios, and foundational skill development in
interactive application design.

9
4.2 FUTURE SCOPE
The future scope of the Brick Breaker Game includes numerous enhancements
to enrich gameplay and broaden its usability. Adding sound effects and background
music using the Java Sound API can significantly improve player immersion by
providing audio feedback for collisions, brick breaks, and level transitions.
Introducing power-ups such as multi-ball, paddle enlargement, or temporary ball
speed increases can add strategic depth and keep the gameplay engaging for longer
periods. Additionally, implementing persistent high-score tracking through file I/O or
database integration like SQLite will allow players to monitor their progress over time
and compete on leaderboards.

Further development could focus on designing additional levels with


procedurally generated brick patterns and increased difficulty to extend the game's
challenge and playtime. A settings menu enabling customization of controls,
difficulty levels, and visual themes would enhance user experience. Support for
mouse and touch inputs would enable broader platform compatibility. Networked
multiplayer features could allow competitive or cooperative play. Advanced graphics,
such as particle effects using JavaFX, mobile deployment via GraalVM, and AI
opponents for solo gameplay are promising directions for making the game more
versatile and appealing in both educational and commercial contexts.

10
APPENDIX A
(SOURCE CODE)

import [Link].*;
import [Link].*;

public class MapGenerator {

public int map[][];


public int brickWidth;
public int brickHeight;
public int row;
public int col;

public MapGenerator(int row, int col) {


[Link] = row;
[Link] = col;

map = new int[row][col];


for (int i = 0; i < row; i++)
for (int j = 0; j < col; j++)
map[i][j] = 1;

brickWidth = 540 / col;


brickHeight = 150 / row;
}

public void draw(Graphics2D g, int level) {


Color brickColor;

11
switch (level) {
case 1 -> brickColor = new Color(0, 200, 255);
case 2 -> brickColor = new Color(255, 165, 0);
case 3 -> brickColor = new Color(144, 238, 144);
default -> brickColor = [Link];
}

for (int i = 0; i < row; i++) {


for (int j = 0; j < col; j++) {
if (map[i][j] > 0) {
int x = j * brickWidth + 80;
int y = i * brickHeight + 50;
[Link](brickColor);
[Link](x, y, brickWidth, brickHeight);

[Link](new BasicStroke(3));
[Link]([Link]);
[Link](x, y, brickWidth, brickHeight);
}
}
}
}

public void setBrickValue(int value, int r, int c) {


map[r][c] = value;
}
}

12
import [Link].*;
import [Link].*;
import [Link].*;

public class GamePlay extends JPanel implements KeyListener, ActionListener {

private boolean gameStarted = false;


private boolean play = false;
private boolean ballLaunched = false;
private boolean showInstructions = false;
private boolean showExitPrompt = false;

private int score = 0;


private int lives = 3;
private int level = 1;
private final int maxLevel = 3;

private MapGenerator map;


private int totalBricks;
private Timer timer;
private int delay = 8;

private int playerX = 310;


private int ballposX = 350;
private int ballposY = 530;
private int ballXdir = -2;
private int ballYdir = -3;

public GamePlay() {

13
map = new MapGenerator(3, 7);
totalBricks = [Link] * [Link];

addKeyListener(this);
setFocusable(true);
setFocusTraversalKeysEnabled(false);

timer = new Timer(delay, this);


[Link]();
}

public void paint(Graphics g) {

if (!gameStarted) {
drawFrontPage(g);
return;
}

[Link]([Link]);
[Link](0, 0, 700, 600);

[Link]((Graphics2D) g, level);

[Link]([Link]);
[Link](0, 0, 3, 600);
[Link](0, 0, 700, 3);
[Link](697, 0, 3, 600);

[Link]([Link]);

14
[Link](new Font("serif", [Link], 20));
[Link]("Score: " + score, 540, 30);
[Link]("Lives: " + lives, 450, 30);
[Link]("Level: " + level, 20, 30);

[Link]([Link]);
[Link](playerX, 550, 100, 8);

if (!ballLaunched) {
ballposX = playerX + 40;
ballposY = 530;
}
[Link]([Link]);
[Link](ballposX, ballposY, 20, 20);
[Link](ballposX, ballposY, 20, 20);

if (totalBricks == 0 && level <= maxLevel && lives > 0) {


play = false;
[Link]([Link]);
[Link](new Font("serif", [Link], 30));
[Link]("LEVEL " + level + " COMPLETE!", 160, 300);
[Link](new Font("serif", [Link], 18));
[Link]("Press SPACE to start next level", 170, 350);
}

if (level > maxLevel) {


[Link]([Link]);
[Link](new Font("serif", [Link], 30));
[Link]("CONGRATULATIONS! YOU WON!", 100, 300);

15
[Link](new Font("serif", [Link], 20));
[Link]("Final Score: " + score, 260, 340);
[Link]("Press ENTER to Restart", 230, 380);
}

if (lives == 0) {
[Link]([Link]);
[Link](new Font("serif", [Link], 30));
[Link]("GAME OVER", 250, 300);
[Link](new Font("serif", [Link], 20));
[Link]("Final Score: " + score, 260, 340);
[Link]("Press ENTER to Restart", 230, 380);
}

[Link]();
}

private void drawFrontPage(Graphics g) {


[Link]([Link]);
[Link](0, 0, 700, 600);

[Link]([Link]);
[Link](new Font("serif", [Link], 40));
[Link]("🎮 BRICK BREAKER 🎮", 130, 180);

[Link]([Link]);
[Link](new Font("serif", [Link], 22));
[Link]("Press ENTER to Start", 240, 270);
[Link]("Press I for Instructions", 230, 310);

16
[Link]("Press ESC to Exit", 250, 350);

if (showInstructions) {
[Link]([Link]);
[Link](new Font("serif", [Link], 18));
[Link]("➡ Move Left : Left Arrow Key", 210, 390);
[Link]("➡ Move Right: Right Arrow Key", 210, 420);
[Link]("➡ Launch Ball: Spacebar", 210, 450);
[Link]("➡ You have 3 lives total. Lose all and game ends.", 120,
480);
}

if (showExitPrompt) {
[Link]([Link]);
[Link](new Font("serif", [Link], 24));
[Link]("Exit Game? (Y to exit / N to cancel)", 130, 520);
}
}

public void actionPerformed(ActionEvent e) {


[Link]();

if (play) {

if (new Rectangle(ballposX, ballposY, 20, 20)


.intersects(new Rectangle(playerX, 550, 100, 8))) {
ballYdir = -ballYdir;
}

17
A:
for (int i = 0; i < [Link]; i++) {
for (int j = 0; j < [Link][0].length; j++) {
if ([Link][i][j] > 0) {
int brickX = j * [Link] + 80;
int brickY = i * [Link] + 50;
Rectangle brickRect = new Rectangle(brickX, brickY,
[Link], [Link]);
Rectangle ballRect = new Rectangle(ballposX, ballposY, 20, 20);

if ([Link](brickRect)) {
[Link](0, i, j);
totalBricks--;
score += 5;

if (ballposX + 19 <= brickRect.x || ballposX + 1 >= brickRect.x +


[Link])
ballXdir = -ballXdir;
else
ballYdir = -ballYdir;

break A;
}
}
}
}

ballposX += ballXdir;
ballposY += ballYdir;

18
if (ballposX < 0) ballXdir = -ballXdir;
if (ballposY < 0) ballYdir = -ballYdir;
if (ballposX > 670) ballXdir = -ballXdir;

if (ballposY > 570) {


lives--;
play = false;
ballLaunched = false;
ballposX = playerX + 40;
ballposY = 530;

if (lives == 0) {
play = false;
}
}
}

repaint();
}

public void keyPressed(KeyEvent e) {

if (showExitPrompt) {
if ([Link]() == KeyEvent.VK_Y) {
[Link](0);
} else if ([Link]() == KeyEvent.VK_N) {
showExitPrompt = false;
repaint();

19
}
return;
}

int key = [Link]();

if (key == KeyEvent.VK_RIGHT) {
playerX = [Link](playerX + 25, 600);
} else if (key == KeyEvent.VK_LEFT) {
playerX = [Link](playerX - 25, 10);
} else if (key == KeyEvent.VK_I) {
showInstructions = !showInstructions;
repaint();
} else if (key == KeyEvent.VK_ESCAPE) {
if (!gameStarted) {
showExitPrompt = true;
repaint();
} else {
int option = [Link](this,
"Exit to Main Menu? Current progress will be lost.",
"Exit Game", JOptionPane.YES_NO_OPTION);
if (option == JOptionPane.YES_OPTION) {
[Link](this, "Score: " + score);
backToFrontPage();
}
}
} else if (key == KeyEvent.VK_ENTER) {
if (!gameStarted) {
gameStarted = true;

20
resetGameState();
repaint();
return;
}

if (lives == 0 || level > maxLevel) {


resetGameState();
repaint();
}
} else if (key == KeyEvent.VK_SPACE) {
if (!gameStarted) return;
if (!ballLaunched && lives > 0 && level <= maxLevel && totalBricks > 0) {
play = true;
ballLaunched = true;
} else if (!play && totalBricks == 0 && level <= maxLevel) {
nextLevel();
}
}
}

private void nextLevel() {


level++;

if (level == 2) {
map = new MapGenerator(4, 8);
} else if (level == 3) {
map = new MapGenerator(5, 9);
} else {
level = maxLevel + 1;

21
repaint();
return;
}

totalBricks = [Link] * [Link];

applyLevelSpeed();

ballLaunched = false;
play = false;
playerX = 310;
ballposX = playerX + 40;
ballposY = 530;

repaint();
}

private void applyLevelSpeed() {


int signX = (ballXdir < 0) ? -1 : 1;
int signY = (ballYdir < 0) ? -1 : 1;

if (level == 1) {
ballXdir = signX * 2;
ballYdir = signY * 3;
} else if (level == 2) {
ballXdir = signX * 3;
ballYdir = signY * 4;
} else if (level == 3) {
ballXdir = signX * 4;

22
ballYdir = signY * 5;
}
}

private void resetGameState() {


score = 0;
lives = 3;
level = 1;
map = new MapGenerator(3, 7);
totalBricks = [Link] * [Link];
play = false;
ballLaunched = false;
playerX = 310;
ballposX = playerX + 40;
ballposY = 530;
ballXdir = -2;
ballYdir = -3;
gameStarted = true;
showExitPrompt = false;
showInstructions = false;
applyLevelSpeed();
}

private void backToFrontPage() {


gameStarted = false;
play = false;
ballLaunched = false;
showExitPrompt = false;
showInstructions = false;

23
score = 0;
lives = 3;
level = 1;
map = new MapGenerator(3, 7);
totalBricks = [Link] * [Link];
}

public void keyReleased(KeyEvent e) {}


public void keyTyped(KeyEvent e) {}
}

import [Link].*;

public class Main {


public static void main(String[] args) {
JFrame window = new JFrame();
GamePlay gamePanel = new GamePlay();

[Link](10, 10, 700, 600);


[Link]("Brick Breaker - Multi Level");
[Link](false);
[Link](JFrame.EXIT_ON_CLOSE);
[Link](gamePanel);
[Link](true);
}
}

24
APPENDIX B
(SCREENSHOTS)
BrickBreaker Game – Home Page

Game-Instruction page

25
Game Exit page

Game level one – Level 1

26
Game-Level 1 completion

Game-Level 2 start page

27
Game-Level 2 completed

Game-game over

28
REFERENCES

1. Oracle – Java SE Documentation

Oracle. (2024). Java Platform, Standard Edition Documentation. Oracle Corporation.


[Link]

2. Oracle – Swing Tutorial

Oracle. (2024). Creating a GUI With Swing. Oracle Corporation.


[Link]

3. Oracle – 2D Graphics API

Oracle. (2024). 2D Graphics Trail. Oracle Corporation.


[Link]

4. Oracle – Event Handling

Oracle. (2024). Writing Event Listeners. Oracle Corporation.


[Link]

5. Oracle – Timer Class Documentation

Oracle. (2024). Class Timer ([Link]). Oracle Corporation.


[Link]

6. Oracle – KeyListener Documentation

Oracle. (2024). Interface KeyListener. Oracle Corporation.


[Link]

7. Oracle – Graphics Class Documentation

Oracle. (2024). Class Graphics. Oracle Corporation.


[Link]

8. StackOverflow – Brick Breaker Game Discussions

StackOverflow Community. (2020–2024). Brick breaker Java game implementation discussions.


[Link]

9. GitHub – Open Source Brick Breaker Projects

GitHub. (2024). Brick Breaker Java open-source repositories.


[Link]

29

You might also like