0% found this document useful (0 votes)
12 views16 pages

AJP Report

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)
12 views16 pages

AJP Report

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/ 16

A

Micro Project On

“Flappy Bird Game”

Submitted By

50. Janhavi Shinde

Under Guidance of

Ms. K. S. Jadhav

Diploma Course in Information Technology


(As per directives of I Scheme, MSBTE)

Sinhgad Institutes
Sinhgad Technical Education Society’s
SOU. VENUTAI CHAVAN POLYTECHNIC, PUNE - 411041
ACADEMIC YEAR 2024 -2025
Maharashtra State Board of technical
Education Certificate
This is to certify that Ms. Janhavi Amit Shinde with Roll No. 50
of Fifth Semester of Diploma in Information Technology of
Institute Sou. Venutai Chavan Polytechnic (Code:0040) has
successfully completed the Micro-Project in Advanced Java
Programming (22517) for the academic year 2024- 2025.

Place: SVCP, Pune Enrollment No:2200400201

Date: Exam Seat No: 169415

Ms. K. S. Jadhav Mr. U. S. Shirshetti Dr. M.S. Jadhav


Course Teacher Head of Department Principal
Annexure – I
Part A-Micro project proposal

A. BRIEF INTRODUCTION:
This Java Flappy Bird game uses Swing for graphics and Oracle JDBC to manage high scores. The player
controls a bird, avoiding pipes by pressing spacebar to jump. It includes lifelines, gravity mechanics, and
collision detection, with dynamic pipe generation, scoring, and high score tracking stored in a database for
a complete gameplay experience.

B. AIM OF THE PROJECT:

The aim of the project is to develop a Java-based Flappy Bird game with real-time mechanics, including
scoring, lifelines, and database-integrated high score tracking.

C. INTENTED COURSE OUTCOME:

a) Develop programs using GUI Framework (AWT and Swing).


b) Handle event of AWT and Swing components.
c) Develop programs to handle events in Java Programming.
d) Develop Java programs using network concepts.
e) Develop programs using database.
f) Develop programs using Servlets.

D. RESOURCES REQUIRED:

Name of Resource
Sr . No. Specification
Required
1 Laptop Intel (R) Core i5- 8GB RAM
2 Operating system Windows 11
3 Software VS Code
ACTION PLAN:

SR.NO. DETAIL OF ACTIVITY WEEK


1 Discussion and finalization of topic 05-08-24

2 Preparation and submission of Abstract 12-08-24

3 Literature Review 02-09-24

4 Collection of Data 09-09-24

5 Discussion and outline of Content 23-09-24


6 Editing and proof Reading of Content 07-10-24

7 Compilation of Report and Presentation 21-10-24

8 Final submission of Micro Project 21-10-24

GROUP MEMBERS:

Roll. No. Name of group members


54 Janhavi Shinde
Annexure II
Part B- Micro-Project
1. Rationale
The rationale behind this project is to apply Java programming concepts and database integration in a
practical, interactive game. It enhances understanding of real-time game mechanics, user interaction, and
data handling, providing hands-on experience with graphics, collision detection, and database operations.

2. Course Outcome Addressed


a) Develop programs using GUI Framework (AWT and Swing) .
b) Handle event of AWT and Swing components.
c) Develop programs to handle events in Java Programming.
e) Develop programs using database.

3. Actual Method Followed

The process for this micro project is to make a “Flappy Bird Game.”
We collect information and organize by following points:
1. Collect the information on how to develop a report.
2. Show the information to faculty.
3. Learn about advanced java.
4. First make a raw report and then correct it.
5. After all the corrections make a proposal.
6. Then prepare a project on “Flappy Bird Game.”
7. Make pdf of report and print it.
8. We learn more about Advanced Java Programming.
ANNEXURE III
Evaluation Sheet for the Micro Project
Academic Year: 2024-2025 Name of the Faculty: Ms. K. S. Jadhav

Course: Advanced Java Programming Course Code:22517 Semester: Fifth

Title of the project: “Flappy Bird Game”

COs addressed by Micro Project:

S. No Course Outcomes

a) Develop programs using GUI Framework (AWT and Swing).

b) Handle events of AWT and Swing components.

c) Develop programs to handle events in Java Programming.

e) Develop programs using database

Major learning outcomes achieved by students by doing the project

(a) Practical outcome:


18. Write a program to insert and retrieve the data from database using JDBC.
19. Write a program to demonstrate use of PreparedStatement and ResultSet interface.
20. Write a program to update and delete a record from database table.

(b) Unit outcomes in Cognitive domain:


2b. Develop a Graphical user interface (GUI) programs using swing components for given problem.
2d. Develop a Graphical user interface (GUI) programs using advanced swing components for the
given problem.
3b. Use relevant AWT/Swing component(s) to handle the given event.
5a. Choose JDBC or ODBC depending on the given application requirement.
5c. Use relevant type of JDBC Driver for the specified environment.
5d. Elaborate steps with example to establish connectivity with specified database.

Comments/suggestions about teamwork /leadership/inter-personal communication (if


any)
…………………………………………………………………………………………………

Marks out of 6 for Marks out of 4 for


Roll performance in performance in
No Name of the Student group activity (D5 oral/ presentation Total Marks out
Col.8) (D5 Col.9) of 10
50 Janhavi Shinde

(Name & Signature)


INTRODUCTION
This project is a Java-based implementation of the classic Flappy Bird game, utilizing Swing for graphical
user interface (GUI) design and Oracle JDBC for database connectivity. Players control a bird that must
navigate through pipes while avoiding collisions, with gravity mechanics and lifelines for added challenge.
The game features real-time scoring and high score tracking, providing an engaging and interactive
experience while showcasing essential programming concepts in Java.

ALGORITHM:
1. Initialize game variables, including board dimensions, lifelines, and images for the background, bird,
and pipes.
2. Establish a database connection to retrieve and prepare to update the high score.
3. Create the bird object and initialize an empty list for pipes.
4. Set up and start timers for placing pipes and updating the game loop.
5. Define the pipe placement method to generate new pipes at random heights.
6. Override the `paintComponent` method to draw the game components on the screen.
7. In the game loop, apply gravity to the bird's position and move pipes horizontally.
8. Update the score when the bird successfully passes a pipe.
9. Implement collision detection to manage interactions between the bird and pipes.
10. If the game ends, stop timers and display a game over message, updating the high score if applicable.
11. If a lifeline is available after a collision, reset the game without starting over.

CODE:
FlappyBird.java
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.Random;
import javax.swing.*;
import java.sql.*;

public class FlappyBird extends JPanel implements ActionListener, KeyListener {


int boardWidth = (int) (360*1.5);
int boardHeight = (int) (640*1.5);
int lifeline = 2;

Image backgroundImg;
Image birdImg;
Image topPipeImg;
Image bottomPipeImg;

int birdX = boardWidth/8;


int birdY = boardWidth/2;
int birdWidth = 34;
int birdHeight = 24;

class Bird {
int x = birdX;
int y = birdY;
int width = birdWidth;
int height = birdHeight;
Image img;
Bird(Image img) {

this.img = img;
}
}

int pipeX = boardWidth;


int pipeY = 0;
int pipeWidth = 64;
int pipeHeight = 512;

class Pipe {
int x = pipeX;
int y = pipeY;
int width = pipeWidth;
int height = pipeHeight;
boolean collided;
Image img;
boolean passed = false;

Pipe(Image img) {
this.img = img;
}
}

Bird bird;
int velocityX = -4; //move pipes to the left speed
int velocityY = 0; //move bird up or down
int gravity = 1;

ArrayList<Pipe> pipes;
Random random = new Random();

Timer gameLoop;
Timer placePipeTimer;
boolean gameOver = false;
double score = 0;
PreparedStatement pstmt;
Statement stmt;
int hs;

FlappyBird() {
setPreferredSize(new Dimension(boardWidth, boardHeight));
setFocusable(true);
addKeyListener(this);

try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con =
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","system");
System.out.println("Connection Established!");
pstmt = con.prepareStatement("update highscore set hs=?"); //used to assign valus dynamically like
the highscore for instance
stmt = con.createStatement();// retrive current highscore
ResultSet rs = stmt.executeQuery("select hs from highscore");
rs.next();

hs = rs.getInt(1);

}catch(Exception e){}

backgroundImg = new ImageIcon(getClass().getResource("./flappybirdbg.png")).getImage();


birdImg = new ImageIcon(getClass().getResource("./flappybird.png")).getImage();
topPipeImg = new ImageIcon(getClass().getResource("./toppipe.png")).getImage();
bottomPipeImg = new ImageIcon(getClass().getResource("./bottompipe.png")).getImage();
bird = new Bird(birdImg);

pipes = new ArrayList<Pipe>();


placePipeTimer = new Timer(1500, new ActionListener() {

public void actionPerformed(ActionEvent e) {


placePipes();
}
});
placePipeTimer.start();

gameLoop = new Timer(1000/60, this);


gameLoop.start();
}

void placePipes() {
int randomPipeY = (int) (pipeY - pipeHeight/4 - Math.random()*(pipeHeight/2));
int openingSpace = boardHeight/4;//space for bird to fly

Pipe topPipe = new Pipe(topPipeImg);


topPipe.y = randomPipeY;
pipes.add(topPipe);

Pipe bottomPipe = new Pipe(bottomPipeImg);


bottomPipe.y = topPipe.y + pipeHeight + openingSpace;
pipes.add(bottomPipe);
}

public void paintComponent(Graphics g) {


super.paintComponent(g);
draw(g);
}

public void draw(Graphics g) {

g.drawImage(backgroundImg, 0, 0, this.boardWidth, this.boardHeight, null);

g.drawImage(birdImg, bird.x, bird.y, bird.width, bird.height, null);

for (int i = 0; i < pipes.size(); i++) {


Pipe pipe = pipes.get(i);
g.drawImage(pipe.img, pipe.x, pipe.y, pipe.width, pipe.height, null);
}
g.setColor(Color.white);
g.setFont(new Font("Arial", Font.PLAIN, 32));

g.drawString("Score: " + (int) score, 10, 35);


g.drawString("Lifeline: " + lifeline, 10, 75);
g.drawString("HighScore: " + hs, 320, 35);

if (gameOver && lifeline == 0) {


g.drawString("Game Over", boardWidth / 2 - 70, boardHeight / 2);
try
{

if(hs < score)


{
pstmt.setDouble(1,score);
int b = pstmt.executeUpdate();

}
}catch(Exception e)
{
System.out.println("Exception in HighScore Database!");
System.err.println(e);
}

}
}

public void move() {


velocityY += gravity;
bird.y += velocityY;
bird.y = Math.max(bird.y, 0); //bird cant go off the top
for (int i = 0; i < pipes.size(); i++) {
Pipe pipe = pipes.get(i);
pipe.x += velocityX;

if (!pipe.passed && bird.x > pipe.x + pipe.width) {


score += 0.5;
pipe.passed = true;
if(score == 10)
{
backgroundImg = new ImageIcon(getClass().getResource("./back2.jpg")).getImage();
revalidate(); repaint();
}
}

if (collision(bird, pipe)) {
if (lifeline > 0 && !pipe.collided) {
System.out.println("Lifeline: " + lifeline);
lifeline--;
pipe.collided = true;//prevent mul reductions
resetGameAfterCollision();
} else if (lifeline == 0) {
gameOver = true;
placePipeTimer.stop();
gameLoop.stop();
}
}

}
if (bird.y > boardHeight) {
if (lifeline > 0) {
lifeline--;
resetGameAfterCollision(); // Reset game after bird falls
} else {
gameOver = true;
placePipeTimer.stop();
gameLoop.stop();
}
}
}
void resetGameAfterCollision() {
bird.y = birdY;

velocityY = 0;
pipes.clear();
}

boolean collision(Bird a, Pipe b) {


return a.x < b.x + b.width &&
a.x + a.width > b.x &&
a.y < b.y + b.height &&
a.y + a.height > b.y;
}

public void actionPerformed(ActionEvent e)


{
if (!gameOver) {
move();
repaint();
}
}

public void keyPressed(KeyEvent e) {


if (e.getKeyCode() == KeyEvent.VK_SPACE) {
velocityY = -9;
if (gameOver && lifeline > 0) {
gameOver = false;
gameLoop.start();
placePipeTimer.start();
}
}
}

public void keyTyped(KeyEvent e) {}

public void keyReleased(KeyEvent e) {}


}
App.java
import javax.swing.*;
public class App {
public static void main(String[] args) throws Exception {
int boardWidth = (int) (360*1.5);
int boardHeight =(int) (640*1.5);
JFrame frame = new JFrame("Flappy Bird");
frame.setSize(boardWidth, boardHeight);
frame.setLocationRelativeTo(null);
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

FlappyBird flappyBird = new FlappyBird();


frame.add(flappyBird);
frame.pack();//sets the proper layout as per components used within
flappyBird.requestFocus();
frame.setVisible(true);
}
}
OUTPUT:

Connection Establishment with Database:

Starting interface:
Interface when the player crosses score 15:

Interface when the player loses all their lifelines:


Conclusion:

In conclusion, the Flappy Bird project successfully demonstrates key programming concepts in Java,
including GUI design, event handling, and database integration. By combining these elements, the game
offers an engaging user experience that enhances skills in real-time application development. The project
not only reinforces theoretical knowledge but also provides practical insights into game mechanics and
database management, making it a valuable learning experience for aspiring developers.
References:

1. https://www.oreilly.com/library/view/java-swing-2nd/0596004087/
2. https://www.geeksforgeeks.org/what-is-advanced-java/
3. https://www.w3schools.com/java/

You might also like