0% found this document useful (0 votes)
9 views

Oop Project Reports

The document describes an OOP project report for a rock paper scissors game. It includes three classes - a login frame, account setup frame, and the game frame. The login frame allows logging in or signing up. The setup frame creates new accounts. The game frame displays the rock paper scissors game between the user and computer over 5 rounds.

Uploaded by

Hamza Ramay
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Oop Project Reports

The document describes an OOP project report for a rock paper scissors game. It includes three classes - a login frame, account setup frame, and the game frame. The login frame allows logging in or signing up. The setup frame creates new accounts. The game frame displays the rock paper scissors game between the user and computer over 5 rounds.

Uploaded by

Hamza Ramay
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

NATIONAL UNIVERSITY OF MODERN LANGUAGES

DEPARTMENT OF COMPUTER SCIENCES

OOP
PROJECT REPORT
Participants:
Hamza Nazir
(NUML-S22-27839)
Zeeshan Abbas
(NUML-S22-37638)
Subhan Saeed
(NUML-S22-41887)
Hassan Shakeel
(NUML-S22-13874)
Submitted to:
Sir bilal

DATE:05/01/2023

CLASS: BSCS-40B (2nd Semester) Evening

Department of Computer Sciences


NATIONAL UNIVERSITY OF MODERN LANGUAGES
NATIONAL UNIVERSITY OF MODERN LANGUAGES
DEPARTMENT OF COMPUTER SCIENCES

Description
How to login or set up your account:
In this project we created 3 frame of separate classes. The 1 st frame is set to be login frame
named as login_game user enter username and password if you don,t have an account simply
click sign up and it will route you to sign up frame (2 nd frame) named as set_up_login and
create account by entering your information and press sign up. And your account will be set
up. Then you will be routed to 1 st frame where you have to enter your information and tap on
log in. 2nd frame has an additional button as well that will route on 1 st frame if you already an
account and if you tap on sign up by mistake.
Game description:
3rd frame is game frame named as game_project.It is simple rock paper scissor game. It has
three buttons, named as rock paper scissor. It is two person game.But in our it is one person
and other is computer.It has a set of rules that are Rock crushes scissors, scissors cut paper,
and paper covers rock. It will have five rounds the one who has scored more will be winner.
And a dialog box will pop up which will show you result and it has two option at the bottom
through which you can restart the game by pressing “ ok ” or you can simply close the game
by pressing “cancel”.
First Frame(login_game):

import javax.swing.*;
import java.awt.event.*;

public class login_game implements ActionListener {

String username;

String password;
JFrame f;

JTextField ttf1;
JPasswordField ttf2;
JLabel l1, l2, l3;
JButton B1, B2;

// login_game(String username, String password) {


// this.username=username;
// this.password=password;
// new login_game();
// }

Department of Computer Sciences


NATIONAL UNIVERSITY OF MODERN LANGUAGES
NATIONAL UNIVERSITY OF MODERN LANGUAGES
DEPARTMENT OF COMPUTER SCIENCES

login_game(String username, String password) {


this.username = username;;
this.password = password;

// login_game(){

f = new JFrame("login");
JLabel lab=new JLabel("If you have already account fill these
instruction ");
JLabel lab1=new JLabel("click login If you don't have account click
sign up ");
lab1.setBounds(05,15,300,30);
lab.setBounds(05,0,300,30);
B1 = new JButton("login");
B1.setBounds(50, 210, 95, 50);
B2 = new JButton("sign up");
B2.setBounds(50, 275, 95, 50);
l1 = new JLabel("user name");
l1.setBounds(50, 70, 150, 25);// l1.setEditable(false);
ttf1 = new JTextField();
ttf1.setBounds(50, 95, 150, 25);
l2 = new JLabel("password");
l2.setBounds(50, 130, 150, 25);// l1.setEditable(false);
l3 = new JLabel();
l3.setBounds(50, 180, 400, 25);// l1.setEditable(false);
ttf2 = new JPasswordField();
ttf2.setBounds(50, 155, 150, 25);
f.add(lab);f.add(lab1);
f.add(l3);
f.add(B1);
f.add(l1);
f.add(l2);
f.add(ttf2);
f.add(ttf1);
//f.add(B);
f.add(B2);
f.setSize(310, 400);
f.setLayout(null);
f.setVisible(true);

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

B1.addActionListener(this);
B2.addActionListener(this);

public static void main(String[] args) {


new login_game(null,null);
}

@Override
public void actionPerformed(ActionEvent e) {

String usertf1 = ttf1.getText();


String passtf2 = ttf2.getText();

if (e.getSource() == B1) {

if (usertf1.equals(username) && passtf2.equals(password))

Department of Computer Sciences


NATIONAL UNIVERSITY OF MODERN LANGUAGES
NATIONAL UNIVERSITY OF MODERN LANGUAGES
DEPARTMENT OF COMPUTER SCIENCES

{
new game_project();
f.dispose();
} else if (usertf1 != username)
{
l3.setText("your username is incorrect pleae try gain");
} else {
l3.setText("your password is incorrect pleae try gain");
}

}
if (e.getSource() == B2) {
new set_up_login();
f.dispose();
}

}
}

Output:

Second Frame(set_up_login):

import javax.swing.*;
import java.awt.event.*;

public class set_up_login implements ActionListener {


JFrame f;

JTextField tf1,tf2,tf3;
JLabel l1,l2,l3;
JButton B1, B2;

Department of Computer Sciences


NATIONAL UNIVERSITY OF MODERN LANGUAGES
NATIONAL UNIVERSITY OF MODERN LANGUAGES
DEPARTMENT OF COMPUTER SCIENCES

set_up_login()
{
f=new JFrame("sign Up");
JLabel lab=new JLabel("If you have already account click login If you
");
JLabel lab1=new JLabel("crate account fill these instruction click sign
up ");
lab1.setBounds(05,15,300,30);
lab.setBounds(05,0,300,30);
B1=new JButton("Sign up"); B1.setBounds(50, 245, 95, 50);
B2=new JButton("login"); B2.setBounds(50, 305, 95, 50);
l1=new JLabel("Complete Name"); l1.setBounds(50,70,150,25);//
l1.setEditable(false);
tf1=new JTextField();tf1.setBounds(50,95,150,25);
l2=new JLabel("Username");l2.setBounds(50,130,150,25);//
l1.setEditable(false);
tf2=new JTextField();tf2.setBounds(50,155,150,25);
l3=new JLabel("Password");l3.setBounds(50,180,150,25);//
l1.setEditable(false);
tf3=new
JTextField();tf3.setBounds(50,205,150,25);tf3.setEditable(true);

f.add(B1);f.add(B2);f.add(l1);f.add(l2);f.add(l3);f.add(tf2);f.add(tf1);f.add(t
f3);f.add(lab);f.add(lab1);
f.setSize(310,500);
f.setLayout(null);
f.setVisible(true);

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

B1.addActionListener(this);
B2.addActionListener(this);

@Override
public void actionPerformed(ActionEvent e) {
//String box1 = tf1.getText();
String box2 = tf2.getText();
String box3 = tf3.getText();

if (e.getSource() == B1) {

new login_game(box2,box3);
f.dispose();

} else if (e.getSource() == B2) {


new login_game(null,null);
//hum ne isliyye null kiya os k liye hamey koi asi chez me ye data
store krna hoga jaha se delete na ho
f.dispose();

Department of Computer Sciences


NATIONAL UNIVERSITY OF MODERN LANGUAGES
NATIONAL UNIVERSITY OF MODERN LANGUAGES
DEPARTMENT OF COMPUTER SCIENCES

}
}

Output:

Third frame(game_project):

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

public class game_project {


JFrame f;
JTextField show_result;
JLabel label_for_your_scour;
JLabel label_for_cop_scour;
JLabel label_for_tie;
JTextField tf_for_your_scour;
JTextField tf_for_cop_scour;
JTextField tf_for_tie;
JButton rockButton;
JButton paperButton;
JButton scissorsButton;
int user = 0;
int com = 0;

Department of Computer Sciences


NATIONAL UNIVERSITY OF MODERN LANGUAGES
NATIONAL UNIVERSITY OF MODERN LANGUAGES
DEPARTMENT OF COMPUTER SCIENCES

int ties =0;

int round=0;

game_project()
{
f=new JFrame("Rock Paper Scissors Game");
JLabel lab=new JLabel("This game have 5 rounds");
// JLabel lab1=new JLabel("Rock crushes scissors, scissors cut paper,
and paper covers rock");
// lab1.setBounds(05,15,400,30);
lab.setBounds(05,0,400,30); f.add(lab);//f.add(lab1);
show_result =new JTextField();
show_result.setBounds(7,280,420,30);
show_result.setEditable(false);
// Image Icon = Toolkit.getDefaultToolkit().getImage("hamza1");
// f.setIconImage(Icon);

label_for_your_scour =new JLabel(" YOUR SCORE ");


tf_for_your_scour = new JTextField();
label_for_your_scour.setBounds(75,50,125,30);
tf_for_your_scour.setBounds(75,80,90,30);
label_for_cop_scour =new JLabel("COMPUTER SCORE");
tf_for_cop_scour =new JTextField();
label_for_cop_scour.setBounds(180,50,125,30);
tf_for_cop_scour.setBounds(180,80,90,30);

label_for_tie =new JLabel(" TIE ");

tf_for_tie = new JTextField();


label_for_tie.setBounds(285,50,125,30);
tf_for_tie.setBounds(285,80,90,30);
tf_for_cop_scour.setEditable(false);
tf_for_tie.setEditable(false);
tf_for_your_scour.setEditable(false);
rockButton=new JButton("ROCK");
paperButton=new JButton("PAPER");
scissorsButton=new JButton("SCISSOR");
rockButton.setBounds(75,140,90,90);
paperButton.setBounds(180,140,90,90);
scissorsButton.setBounds(285,140,90,90);

rockButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
round ++;
game_start(0);
}
});
paperButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
round ++;
game_start(1);
}
});
scissorsButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
round ++;
game_start(2);
}

Department of Computer Sciences


NATIONAL UNIVERSITY OF MODERN LANGUAGES
NATIONAL UNIVERSITY OF MODERN LANGUAGES
DEPARTMENT OF COMPUTER SCIENCES

});
f.add(show_result);
f.add(rockButton);
f.add(paperButton);
f.add( scissorsButton);
f.add(tf_for_your_scour);
f.add(label_for_your_scour);
f.add(label_for_cop_scour);
f.add(tf_for_cop_scour);
f.add(label_for_tie);
f.add(tf_for_tie);

f.setSize( 450,400);
f.setLayout(null);
f.setVisible(true);

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

public void game_start(int abc) {


Random rc = new Random();

int n1 = abc;
int n2 = rc.nextInt(0, 2);

if ((n1 == 0 && n2 == 0 || n1 == 1 && n2 == 1) || (n1 == 2 && n2 == 2))


{

++ties;
String a = String.valueOf(ties);
tf_for_tie.setText(a);
show_result.setText("This round is tie");

if ((n1 == 1 && n2 == 0 || n1 == 0 && n2 == 2) || (n1 == 2 && n2 == 1))


{

++user;
String user1 = String.valueOf(user);
tf_for_your_scour.setText(user1);
show_result.setText(" you win this round ");

}
if ((n2 == 1 && n1 == 0 || n2 == 0 && n1 == 2) || (n2 == 2 && n1 == 1))
{

++com;
String com1 = String.valueOf(com);
tf_for_cop_scour.setText(com1);
show_result.setText("oops! you lose this round");

Department of Computer Sciences


NATIONAL UNIVERSITY OF MODERN LANGUAGES
NATIONAL UNIVERSITY OF MODERN LANGUAGES
DEPARTMENT OF COMPUTER SCIENCES

if (round == 5) {
show_result.setText("Game over! ");
rockButton.setEnabled(false);
paperButton.setEnabled(false);
scissorsButton.setEnabled(false);
JFrame f1 = new JFrame();
if (com > user) {
int a = JOptionPane.showConfirmDialog(f, "oops! you loss the
innings");
if (a == JOptionPane.YES_OPTION) {
f.dispose();
new game_project();
} else {
f.dispose();
}
} else if (user > com) {
int a = JOptionPane.showConfirmDialog(f, "congratulations you
win the innings");
if (a == JOptionPane.YES_OPTION) {
f.dispose();
new game_project();
} else {
f.dispose();
}
} else {
int a = JOptionPane.showConfirmDialog(f, "innings is tie");
if (a == JOptionPane.YES_OPTION) {
f.dispose();
new game_project();
} else {
f.dispose();
}
}
}
}
}

Output:

Department of Computer Sciences


NATIONAL UNIVERSITY OF MODERN LANGUAGES
NATIONAL UNIVERSITY OF MODERN LANGUAGES
DEPARTMENT OF COMPUTER SCIENCES

Result

Department of Computer Sciences


NATIONAL UNIVERSITY OF MODERN LANGUAGES

You might also like