[go: up one dir, main page]

0% found this document useful (0 votes)
726 views18 pages

"Brick Breaker Game": A Project Report On

Ajp microproject

Uploaded by

dahiwalomkar07
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)
726 views18 pages

"Brick Breaker Game": A Project Report On

Ajp microproject

Uploaded by

dahiwalomkar07
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
You are on page 1/ 18

A

PROJECT REPORT ON
“Brick Breaker Game”
SUBMITTED BY
Miss. WAKCHAURE SADHANA BALASAHEB - 2200340651

Under the guidance of


Prof . S.B JADHAV

DEPARTMENT OF COMPUTER TECHNOLOGY


Sanjivani Rural Education Society’s

SANJIVANI K.B.P POLYTECHNIC

KOPARGAON : 423603,DIST: AHMEDNAGAR

 Brick Breaker Game. Page 1


CERTIFICATE
This is certify that the project report entitied
“Brick Breaker Game”
SUBMITTED BY

Miss. WAKCHAURE SADHANA BALASAHEB - 2200340651

Of Fifth semester of Diploma in ‘Computer Technology’ institute of Sanjivani


K.B.P Polytechnic Kopargaon has submitted the Micro-project satisfactorily in
subject “Advanced java” for academic year 2023 to 2024 as prescribed in the
curriculum.

Place: - Kopargaon

Date: ----------------

Subject Teacher HOD

 Brick Breaker Game. Page 2


INDEX

Sr.No Point Name

1. Requirements
2. About Java
3. Introduction
4. Program code
5. Output
6. Conclusion

7. References

 Brick Breaker Game. Page 3


REQUIREMENTS

 HARDWARE:
 Processor with minimum 258GB hard disk
 8 GB RAM

 SOFTWARE:
 Windows 10

 ANY OTHER RESOURCE USED :


Visual studio code
Java(jdk 1.8.0) or above

 Brick Breaker Game. Page 4


ABOUT JAVA
“Java is a versatile and widely-used programming language that has gained immense popularity
since its introduction in the mid-1990s. Known for its simplicity, portability, and security, Java
has become the go-to language for a wide range of applications, from web development to
mobile apps and enterprise software.

One of the key strengths of Java is its "write once, run anywhere" principle. This means that Java
programs can run on any platform that has a Java Virtual Machine (JVM) installed, regardless of
the underlying operating system. This portability makes Java an ideal choice for developing
cross-platform applications that can be deployed on various devices, from desktop computers to
smartphones and embedded systems.

Java's syntax is derived from C and C++, making it familiar to developers with a background in
these languages. However, Java eliminates certain complexities and pitfalls of these languages,
providing a simpler and more secure programming environment. It enforces strong type-
checking, automatic memory management through garbage collection, and strict error handling,
reducing the likelihood of runtime errors and vulnerabilities.

Java's extensive standard library provides a rich set of pre-built classes and APIs that simplify
common programming tasks. From input/output operations to networking, multithreading, and
database connectivity, Java offers a comprehensive suite of tools that accelerate development
and enhance productivity. Additionally, Java's vast ecosystem of third-party libraries and
frameworks, such as Spring, Hibernate, and Apache Struts, further extends its capabilities and
enables developers to build complex and feature-rich applications with ease.

Java's object-oriented nature allows for modular and reusable code through the use of classes and
objects. This promotes code organization, maintainability, and extensibility, making it easier to
manage large-scale projects. Furthermore, Java supports inheritance, polymorphism, and
encapsulation, which are fundamental concepts in object-oriented programming, enabling
developers to create flexible and modular software architectures.

In recent years, Java has evolved to meet the demands of modern software development. The
introduction of Java 8 brought significant enhancements, including lambda expressions,
functional interfaces, and the Stream API, which revolutionized the way developers write code
by enabling concise and expressive functional programming constructs. Subsequent releases,
such as Java 11 and Java 17, have focused on improving performance, security, and developer
productivity.

Java's versatility extends beyond traditional application development. With the rise of the
Internet of Things (IoT) and embedded systems, Java has found its way into various domains,

 Brick Breaker Game. Page 5


Introduction
Brick breaker is a classic arcade game where the player controls a paddle to bounce a ball and
break bricks. It's a fun and challenging game that requires both strategy and quick reflexes.

In this project, you'll start by designing the game board and drawing the bricks on the screen.
Then, you'll need to handle user input to control the paddle's movement. Make sure to update the
paddle's position based on the user's commands.

Next, you'll want to implement the ball's movement and collision detection. The ball should
bounce off the walls, paddle, and bricks. When the ball hits a brick, it should break and disappear
from the screen.

To add more excitement to the game, you can include power-ups and different types of bricks
with varying strengths. Power-ups can give the player extra abilities or bonuses, while different
brick types can require multiple hits to break.

In this project, you'll start by creating the game board using Java's graphics capabilities. You'll
design the layout of the bricks and set their initial positions on the screen. Each brick will have a
different color or pattern to make the game visually appealing.

Next, you'll need to handle the player's input to control the paddle. You can use keyboard events
to move the paddle left or right based on the player's commands. Make sure the paddle stays
within the boundaries of the game board.

Once the player starts the game, you'll need to implement the ball's movement. The ball should
bounce off the walls, paddle, and bricks. You can calculate the ball's trajectory using simple
physics concepts like velocity and angles.

To make the game more challenging, you can introduce power-ups and special bricks. Power-ups
can give the player temporary advantages like a larger paddle or multiple balls. Special bricks
can have different properties, such as being unbreakable or requiring multiple hits to destroy.

Keep track of the player's score by incrementing it whenever a brick is destroyed. You can
display the score on the screen to motivate the player to achieve higher scores.

Lastly, handle game over conditions. If the ball falls below the paddle, the player loses a life.
When all lives are lost, display the final score and allow the player to restart the game if they
wish.

 Brick Breaker Game. Page 6


Source Code
import java.util.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.Timer;

public class Gameplay extends JPanel implements KeyListener, ActionListener


{
private boolean play = false;
private int score = 0;
private int totalBricks = 48;
private Timer timer;
private int delay=8;
private int playerX = 310;
private int ballposX = 120;
private int ballposY = 350;
private int ballXdir = -1;
private int ballYdir = -2;
private MapGenerator map;

public Gameplay()
{
map = new MapGenerator(4, 12);
addKeyListener(this);
setFocusable(true);

 Brick Breaker Game. Page 7


setFocusTraversalKeysEnabled(false);
timer=new Timer(delay,this);
timer.start();
}
public void paint(Graphics g)
{
// background
g.setColor(Color.black);
g.fillRect(1, 1, 692, 592);
// drawing map
map.draw((Graphics2D) g);
// borders
g.setColor(Color.yellow);
g.fillRect(0, 0, 3, 592);
g.fillRect(0, 0, 692, 3);
g.fillRect(691, 0, 3, 592);

// the scores
g.setColor(Color.white);
g.setFont(new Font("serif",Font.BOLD, 25));
g.drawString(""+score, 590,30);
// the paddle
g.setColor(Color.green);
g.fillRect(playerX, 550, 100, 8);
// the ball
g.setColor(Color.yellow);
g.fillOval(ballposX, ballposY, 20, 20);

 Brick Breaker Game. Page 8


// when you won the game
if(totalBricks <= 0)
{
play = false;
ballXdir = 0;
ballYdir = 0;
g.setColor(Color.RED);
g.setFont(new Font("serif",Font.BOLD, 30));
g.drawString("You Won", 260,300);
g.setColor(Color.RED);
g.setFont(new Font("serif",Font.BOLD, 20));
g.drawString("Press (Enter) to Restart", 230,350);
}

// when you lose the game


if(ballposY > 570)
{
play = false;
ballXdir = 0;
ballYdir = 0;
g.setColor(Color.RED);
g.setFont(new Font("serif",Font.BOLD, 30));
g.drawString("Game Over, Scores: "+score, 190,300);

g.setColor(Color.RED);
g.setFont(new Font("serif",Font.BOLD, 20));
g.drawString("Press (Enter) to Restart", 230,350);

 Brick Breaker Game. Page 9


}

g.dispose();
}

public void keyPressed(KeyEvent e)


{
if (e.getKeyCode() == KeyEvent.VK_RIGHT)
{
if(playerX >= 600)
{
playerX = 600;
}
else
{
moveRight();
}
}
if (e.getKeyCode() == KeyEvent.VK_LEFT)
{
if(playerX < 10)
{
playerX = 10;
}
else
{
moveLeft();

 Brick Breaker Game. Page 10


}
}
if (e.getKeyCode() == KeyEvent.VK_ENTER)
{
if(!play)
{
play = true;
ballposX = 120;
ballposY = 350;
ballXdir = -1;
ballYdir = -2;
playerX = 310;
score = 0;
totalBricks = 21;
map = new MapGenerator(3, 7);

repaint();
}
}
}

public void keyReleased(KeyEvent e) {}


public void keyTyped(KeyEvent e) {}

public void moveRight()


{
play = true;

 Brick Breaker Game. Page 11


playerX+=20;
}

public void moveLeft()


{
play = true;
playerX-=20;
}

public void actionPerformed(ActionEvent e)


{
timer.start();
if(play)
{
if(new Rectangle(ballposX, ballposY, 20, 20).intersects(new
Rectangle(playerX, 550, 30, 8)))
{
ballYdir = -ballYdir;
ballXdir = -2;
}
else if(new Rectangle(ballposX, ballposY, 20, 20).intersects(new
Rectangle(playerX + 70, 550, 30, 8)))
{
ballYdir = -ballYdir;
ballXdir = ballXdir + 1;
}
else if(new Rectangle(ballposX, ballposY, 20, 20).intersects(new
Rectangle(playerX + 30, 550, 40, 8)))

 Brick Breaker Game. Page 12


{
ballYdir = -ballYdir;
}

// check map collision with the ball


A: for(int i = 0; i<map.map.length; i++)
{
for(int j =0; j<map.map[0].length; j++)
{
if(map.map[i][j] > 0)
{
//scores++;
int brickX = j * map.brickWidth + 80;
int brickY = i * map.brickHeight + 50;
int brickWidth = map.brickWidth;
int brickHeight = map.brickHeight;

Rectangle rect = new Rectangle(brickX, brickY,


brickWidth, brickHeight);
Rectangle ballRect = new Rectangle(ballposX,
ballposY, 20, 20);
Rectangle brickRect = rect;

if(ballRect.intersects(brickRect))
{
map.setBrickValue(0, i, j);
score+=5;
totalBricks--;

 Brick Breaker Game. Page 13


// when ball hit right or left of brick
if(ballposX + 19 <= brickRect.x || ballposX
+ 1 >= brickRect.x + brickRect.width)
{
ballXdir = -ballXdir;
}
// when ball hits top or bottom of brick
else
{
ballYdir = -ballYdir;

break A;
}
}
}
}

ballposX += ballXdir;
ballposY += ballYdir;

if(ballposX < 0)
{
ballXdir = -ballXdir;
}
if(ballposY < 0)

 Brick Breaker Game. Page 14


{
ballYdir = -ballYdir;
}
if(ballposX > 670)
{
ballXdir = -ballXdir;
}
repaint();
}
}
}

 Brick Breaker Game. Page 15


Output

 Brick Breaker Game. Page 16


CONCLUSION
creating a brick breaker game in Java is a fantastic way to apply your programming skills and
have some fun. By designing the game board, handling user input, implementing ball movement
and collision detection, and adding exciting features like power-ups and special bricks, you can
create an engaging and challenging game experience.

Throughout the project, remember to stay creative and add your own personal touch to make the
game unique. Don't be afraid to experiment with different designs and features to make it even
more enjoyable.

By completing this project, you'll gain valuable experience in game development, graphics
programming, and user interaction. Plus, you'll have a cool game that you can share with your
friends and family.

So, get coding and let your imagination run wild! I'm excited to see what you create. If you have
any more questions or need further assistance, feel free to reach out. Good luck and have a blast
building your brick breaker game!

 Brick Breaker Game. Page 17


REFERENCE

[1]. "Beginning Java Game Development with LibGDX" by Lee Stemkoski: This book provides
a comprehensive guide to game development using the LibGDX framework, which can be a
great resource for building your brick breaker game.

[2]. "Java Game Development with LibGDX" by Lee Stemkoski: Another book by Lee
Stemkoski that focuses specifically on game development in Java using the LibGDX framework.
It covers various game development concepts and provides practical examples.

[3]. "Killer Game Programming in Java" by Andrew Davison: This book covers the
fundamentals of game programming in Java, including topics like animation, collision detection,
and game physics. It can be a valuable resource for understanding the core concepts behind
building a brick breaker game.

[4]. Online tutorials and resources: Websites like GameDev.net, Java-Gaming.org, and Oracle's
Java Game Development Tutorials can provide step-by-step tutorials, code samples, and
discussions on game development in Java.

[5]. Online game development communities: Joining online communities like the LibGDX
forum, Reddit's r/gamedev subreddit, or Stack Overflow's game-development tag can give you
access to a community of game developers who can provide guidance, answer questions, and
share their experiences.

 Brick Breaker Game. Page 18

You might also like