Report (Stake)
Report (Stake)
No
Shivam Teli 22203A0008
Tanuj Rane 22203A0022
Shriyash Kumbhar 22203A0023
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
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
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
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
1 VS code
2 Laptop
3 XAMPP server
Code :
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
import java.util.Vector;
LoginScreen() {
setTitle("Login");
setSize(300, 150);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new GridLayout(3, 2));
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);
}
RegisterScreen() {
setTitle("Register");
setSize(300, 150);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new GridLayout(3, 2));
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);
}
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());
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);
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);
}
if (userIdResult.next()) {
int userId = userIdResult.getInt("id");
if (userIdResult.next()) {
int userId = userIdResult.getInt("id");
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();
}
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
(Marks-2)
----------------------------------------------------------------------------------------------------------
------------------
----------------------------------------------------------------------------------------------------------
------------------
----------------------------------------------------------------------------------------------------------
------------------
Signature: