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

Report (Stake)

The document outlines a micro-project proposal for a card-based game called Stake Game, developed using Java Swing. The game involves players navigating a grid of cards to find diamonds while avoiding mines, with features like user authentication and score tracking. It includes a detailed action plan, required resources, and course outcomes achieved by the team members involved in the project.

Uploaded by

shivamteli63
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)
12 views21 pages

Report (Stake)

The document outlines a micro-project proposal for a card-based game called Stake Game, developed using Java Swing. The game involves players navigating a grid of cards to find diamonds while avoiding mines, with features like user authentication and score tracking. It includes a detailed action plan, required resources, and course outcomes achieved by the team members involved in the project.

Uploaded by

shivamteli63
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/ 21

Name Roll.

No
Shivam Teli 22203A0008
Tanuj Rane 22203A0022
Shriyash Kumbhar 22203A0023

Department of Computer Engineering


Vidyalankar Polytechnic
Wadala (E), Mumbai -37
(Affiliated to MSBTE)
2022-2023

PART-A (About 2-3 Pages)


Part-A
Format for Micro-Project Proposal
For 1st to 4th Semester
Title of Micro Project: Stake Game

1.0 Brief Introduction:


We’ve developed a stake game using java In this game,the stake game is an interactive card-
based game developed using Java Swing, designed to engage players in a fun and challenging
environment. The game's objective is to navigate a grid of cards, each concealing either a
diamond or a mine. Players click on the cards to reveal their contents, with the goal of
accumulating points for each diamond found while avoiding mines that end the game

2.0 Aim of the Micro Project:


The Stake Game aims to create an engaging card game where players uncover diamonds
while avoiding mines, featuring user authentication and score tracking in a database.
3.0 Action Plan (Sequence and time required for major activities for 8 weeks)

Sr. Details of Activity Planned Planned Name of


Responsible
No. Start Finish Team Members
Date Date

1 Topic selection 20-10- 18-10- Team


2024 2024

2 Development of project 27-10- 27-10- Team


2024 2024

3 Report 30-10- 30-10- Shivam Teli


2024 2024

4.0 Resources Required (Such as raw material, some machining facility, software
etc.)
Sr. Name of Specifications Qty Remarks
Resource/Material
No.
1. VS code
2. Laptop
3. XAMPP server
Annexure-IA
PART-B (Outcomes after Execution and Format for Micro-Project Report,
About 6-10 Pages)
For 1st to 4th Semester

Title of Micro Project: Stake Game

1.0 Brief Description: (Importance of the project, in about 100 to 200 words)
We’ve developed a stake game using java In this game,the stake game is an interactive
card-based game developed using Java Swing, designed to engage players in a fun and
challenging environment. The game's objective is to navigate a grid of cards, each
concealing either a diamond or a mine. Players click on the cards to reveal their contents,
with the goal of accumulating points for each diamond found while avoiding mines that
end game

2.0 Aim of Micro Project: (in about 100 to 200 words) :


The Stake Game aims to create an engaging card game where players uncover
diamonds while avoiding mines, featuring user authentication and score tracking in a
database.

3.0 Course Outcomes Integrated (Add to the earlier list if more CO’s are addressed)
 Develop Program using GUI Program(AWT OR Swing)
 Handle events of AWT and swing components
 Develop program to handle events in java programming
 Develop program using database

4.0 Actual Procedure followed

 Developed the Login Screen to validate user credentials against the MySQL database.
 Created the Main Menu with options for starting a game and viewing score history.
 Implemented game logic in the Stake class, using a CardLayout to manage card
interactions and scoring.
 Integrated methods for inserting scores and retrieving score history from the
database

5.0 Actual Resources Used: (Mention the actual resources used)

Sr. Name of Resource/Material Specifications Qty Remarks


No.

1 VS code

2 Laptop
3 XAMPP server

6.0 Outputs of the Micro Projects


Flowchart

Code :

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
import java.util.Vector;

public class StakeGame {


public static void main(String[] args) {
new LoginScreen();
}
}

class LoginScreen extends JFrame {


private JTextField usernameField;
private JPasswordField passwordField;

LoginScreen() {
setTitle("Login");
setSize(300, 150);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new GridLayout(3, 2));

JLabel usernameLabel = new JLabel("Username:");


usernameField = new JTextField();
JLabel passwordLabel = new JLabel("Password:");
passwordField = new JPasswordField();
JButton loginButton = new JButton("Login");
JButton registerButton = new JButton("Register");

loginButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String username = usernameField.getText();
String password = new
String(passwordField.getPassword());
if (validateLogin(username, password)) {
new MainMenu(username);
dispose();
} else {
JOptionPane.showMessageDialog(null, "Incorrect
username or password.", "Login Error", JOptionPane.ERROR_MESSAGE);
}
}
});

registerButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new RegisterScreen();
dispose();
}
});

add(usernameLabel);
add(usernameField);
add(passwordLabel);
add(passwordField);
add(loginButton);
add(registerButton);

setVisible(true);
}

private boolean validateLogin(String username, String password)


{
String databaseURL = "jdbc:mysql://localhost:3306/stake";
String user = "root";
String dbPassword = "";

try (Connection connection =


DriverManager.getConnection(databaseURL, user, dbPassword)) {
String sql = "SELECT * FROM user WHERE username = ? AND
password = ?";
PreparedStatement preparedStatement =
connection.prepareStatement(sql);
preparedStatement.setString(1, username);
preparedStatement.setString(2, password);
ResultSet resultSet = preparedStatement.executeQuery();
return resultSet.next();
} catch (SQLException ex) {
ex.printStackTrace();
}
return false;
}
}

class RegisterScreen extends JFrame {


private JTextField usernameField;
private JPasswordField passwordField;

RegisterScreen() {
setTitle("Register");
setSize(300, 150);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new GridLayout(3, 2));

JLabel usernameLabel = new JLabel("Username:");


usernameField = new JTextField();
JLabel passwordLabel = new JLabel("Password:");
passwordField = new JPasswordField();
JButton registerButton = new JButton("Register");

registerButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String username = usernameField.getText();
String password = new
String(passwordField.getPassword());
if (registerUser(username, password)) {
JOptionPane.showMessageDialog(null,
"Registration successful!", "Success",
JOptionPane.INFORMATION_MESSAGE);
new LoginScreen();
dispose();
} else {
JOptionPane.showMessageDialog(null,
"Registration failed.", "Error", JOptionPane.ERROR_MESSAGE);
}
}
});

add(usernameLabel);
add(usernameField);
add(passwordLabel);
add(passwordField);
add(new JLabel());
add(registerButton);

setVisible(true);
}

private boolean registerUser(String username, String password) {


String databaseURL = "jdbc:mysql://localhost:3306/stake";
String user = "root";
String dbPassword = "";

try (Connection connection =


DriverManager.getConnection(databaseURL, user, dbPassword)) {
String sql = "INSERT INTO user (username, password)
VALUES (?, ?)";
PreparedStatement preparedStatement =
connection.prepareStatement(sql);
preparedStatement.setString(1, username);
preparedStatement.setString(2, password);
int rowsAffected = preparedStatement.executeUpdate();
return rowsAffected > 0;
} catch (SQLException ex) {
ex.printStackTrace();
}
return false;
}
}

class MainMenu extends JFrame {


MainMenu(String username) {
setTitle("Main Menu");
setSize(400, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());

JButton newGameButton = new JButton("New Game");


newGameButton.setFont(new Font("Arial", Font.PLAIN, 24));

JButton scoreHistoryButton = new JButton("Score History");


scoreHistoryButton.setFont(new Font("Arial", Font.PLAIN,
24));
JButton logoutButton = new JButton("Logout");
logoutButton.setFont(new Font("Arial", Font.PLAIN, 24));

JPanel buttonPanel = new JPanel();


buttonPanel.add(newGameButton);
buttonPanel.add(scoreHistoryButton);
buttonPanel.add(logoutButton);
add(buttonPanel, BorderLayout.CENTER);

newGameButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new Stake(username);
dispose();
}
});

scoreHistoryButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new ScoreHistory(username, MainMenu.this);
}
});

logoutButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
new LoginScreen();
}
});

setVisible(true);
}
}
class Stake extends JFrame {
private JPanel[] upperPanels;
private JPanel[] lowerPanels;
private CardLayout[] cardLayouts;
private JLabel[] imageLabels;
private JLabel scoreLabel;
private int score = 0;
private String username;

Stake(String username) {
this.username = username;
setLayout(new BorderLayout());

scoreLabel = new JLabel("Score: 0");


JPanel scorePanel = new JPanel(new
FlowLayout(FlowLayout.LEFT));
scorePanel.add(scoreLabel);
add(scorePanel, BorderLayout.NORTH);

JPanel gridPanel = new JPanel(new GridLayout(5, 4));


upperPanels = new JPanel[20];
lowerPanels = new JPanel[20];
cardLayouts = new CardLayout[20];
imageLabels = new JLabel[20];

ImageIcon diamondIcon = new ImageIcon("diamond_image.png");


ImageIcon mineIcon = new ImageIcon("mine_image.png");

Image diamondImg =
diamondIcon.getImage().getScaledInstance(50, 50,
Image.SCALE_SMOOTH);
Image mineImg = mineIcon.getImage().getScaledInstance(50,
50, Image.SCALE_SMOOTH);
ImageIcon scaledDiamondIcon = new ImageIcon(diamondImg);
ImageIcon scaledMineIcon = new ImageIcon(mineImg);

boolean[] isMine = new boolean[20];


int minesPlaced = 0;
while (minesPlaced < 6) {
int randomIndex = (int) (Math.random() * 20);
if (!isMine[randomIndex]) {
isMine[randomIndex] = true;
minesPlaced++;
}
}

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


final int index = i;

cardLayouts[i] = new CardLayout();


upperPanels[i] = new JPanel(cardLayouts[i]);
lowerPanels[i] = new JPanel();

imageLabels[i] = new JLabel(isMine[i] ? scaledMineIcon :


scaledDiamondIcon, SwingConstants.CENTER);
lowerPanels[i].add(imageLabels[i]);

JButton button = new JButton("Click me");


upperPanels[i].add(button, "Upper");
upperPanels[i].add(lowerPanels[i], "Lower");

button.addActionListener((ActionEvent e) -> {
cardLayouts[index].next(upperPanels[index]);
if
(imageLabels[index].getIcon().equals(scaledMineIcon)) {
JOptionPane.showMessageDialog(null, "Game Over!
You clicked on a Mine.");
insertScoreToDatabase(username, score);
dispose();
new MainMenu(username);
} else {
score += 5;
scoreLabel.setText("Score: " + score);
}
});

gridPanel.add(upperPanels[i]);
}

add(gridPanel, BorderLayout.CENTER);
setTitle("Stake Game");
setSize(800, 400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}

private void insertScoreToDatabase(String username, int score) {


String databaseURL = "jdbc:mysql://localhost:3306/stake";
String user = "root";
String password = "";

try (Connection connection =


DriverManager.getConnection(databaseURL, user, password)) {
String userIdQuery = "SELECT id FROM user WHERE username
= ?";
PreparedStatement userIdStatement =
connection.prepareStatement(userIdQuery);
userIdStatement.setString(1, username);
ResultSet userIdResult = userIdStatement.executeQuery();

if (userIdResult.next()) {
int userId = userIdResult.getInt("id");

String sql = "INSERT INTO score (user_id, score,


insert_time) VALUES (?, ?, CURRENT_TIMESTAMP)";
PreparedStatement preparedStatement =
connection.prepareStatement(sql);
preparedStatement.setInt(1, userId);
preparedStatement.setInt(2, score);
preparedStatement.executeUpdate();
} else {
System.out.println("User not found in the
database.");
}
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}

class ScoreHistory extends JFrame {


ScoreHistory(String username, JFrame parentFrame) {
setTitle("Score History");
setSize(400, 300);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

Vector<String> columnNames = new Vector<>();


columnNames.add("Score");
columnNames.add("Time");

Vector<Vector<Object>> data = new Vector<>();

String databaseURL = "jdbc:mysql://localhost:3306/stake";


String user = "root";
String password = "";

try (Connection connection =


DriverManager.getConnection(databaseURL, user, password)) {
String userIdQuery = "SELECT id FROM user WHERE username
= ?";
PreparedStatement userIdStatement =
connection.prepareStatement(userIdQuery);
userIdStatement.setString(1, username);
ResultSet userIdResult = userIdStatement.executeQuery();

if (userIdResult.next()) {
int userId = userIdResult.getInt("id");

String sql = "SELECT score, insert_time FROM score


WHERE user_id = ? ORDER BY insert_time DESC";
PreparedStatement preparedStatement =
connection.prepareStatement(sql);
preparedStatement.setInt(1, userId);
ResultSet resultSet =
preparedStatement.executeQuery();

while (resultSet.next()) {
Vector<Object> row = new Vector<>();
row.add(resultSet.getInt("score"));
row.add(resultSet.getTimestamp("insert_time"));
data.add(row);
}
}
} catch (SQLException ex) {
ex.printStackTrace();
}

JTable scoreTable = new JTable(data, columnNames);


JScrollPane scrollPane = new JScrollPane(scoreTable);
add(scrollPane);

setLocationRelativeTo(parentFrame);
setVisible(true);
}
}

Output:
7.0 Skill Developed/Learning out of this Micro Project.
 Learnt to implement arrays , functions and loops in javascript
 Learnt to implement event listener in javascript

Name of Student: Shivam Teli EnrollmentNo:2205680008


Name of Programmed: CO Semester:Fifth
Course Title: Advance java programming Code:22519
Title of the Micro Project: Stake game
Course Outcomes Achieved:
 Develop Program using GUI Program(AWT OR Swing)
 Handle events of AWT and swing components
 Develop program to handle events in java programming
 Develop program using database

Name of Student: Tanuj Rane EnrollmentNo:2205680022


Name of Programmed: CO Semester:Fifth
Course Title: Advance java programming Code:22519
Title of the Micro Project: Stake game
Course Outcomes Achieved:
 Develop Program using GUI Program(AWT OR Swing)
 Handle events of AWT and swing components
 Develop program to handle events in java programming
 Develop program using database
Name of Student: Shriyash Kumbhar EnrollmentNo:2205680023
Name of Programmed: CO Semester:Fifth
Course Title: Advance java programming Code:22519
Title of the Micro Project: Stake game
Course Outcomes Achieved:
 Develop Program using GUI Program(AWT OR Swing)
 Handle events of AWT and swing components
 Develop program to handle events in java programming
 Develop program using database

Micro Project Evaluation Sheet

Process Assessment Product Assessment Total Marks


10
Part-A Project Part-B Individual
Project Methodology Project Presentation/
Proposal Report/
(Mark-2) Viva
(Mark-2) Working
Model (Marks-4)

(Marks-2)

Comments/Suggestions about team work/leadership/inter-personal communication


(if any)
----------------------------------------------------------------------------------------------------------
------------------

----------------------------------------------------------------------------------------------------------
------------------

Any other Comments:

----------------------------------------------------------------------------------------------------------
------------------

----------------------------------------------------------------------------------------------------------
------------------

Name and Designation of Faculty Members

Signature:

You might also like