Beruflich Dokumente
Kultur Dokumente
of
Bachelor of Technology
In
APRIL 2019
SRM INSTITUTE OF SCIENCE AND TECHNOLOGY
KATTANKULATHUR
BONAFIDE CERTIFCATE
Certified that this project report on “TIC TAC TOE GAME” is the bonafide work of “ASHIM SINGH
out the project work as part of their course 15SE205J – PROGRAMMING IN JAVA.
SIGNATURE SIGNATURE
INTERNAL EXAMINER
Department of Computer Science and Engineering
SRM Institute of Science & Technology
Own Work* Declaration Form
This sheet must be filled in (each box ticked to show that the condition has been met). It must
be signed and dated along with your student registration number and included with all assignments
you submit – work will not be marked unless this is done.
To be completed by the student for all assessments
: Challa Rohit
: RA1711003011481
I / We hereby certify that this assessment compiles with the University’s Rules and Regulations relating to Academic
misconduct and plagiarism**, as listed in the University Website, Regulations, and the Education Committee guidelines.
I / We confirm that all the work contained in this assessment is my / our own except where indicated, and that I / We have
met the following conditions:
I understand that any false claim for this work will be penalised in accordance with the University policies and
regulations.
DECLARATION:
I am aware of and understand the University’s policy on Academic misconduct and plagiarism and I certify that this
assessment is my / our own work, except where indicated by referring, and that I have followed the good academic
practices noted above.
If you are working in a group, please write your registration numbers and sign with the date for every student in your
group.
Please Note: If you are still unsure about what plagiarism is or need advice on how to avoid it, you can
1. Consult your programme handbook
2. Refer the University website or
3. Contact any one of the following assistances:
Your Faculty, Course Co-ordinator, Project Supervisor, Faculty Advisor, Head of the Department
OBJECTIVE
The project that we made is our first step towards
learning the basics of swing.
We hope our project to help people pass their
time while playing the game.
They can either play with the computer or their
friend. It’s their choice.
Since tic tac toe is a popular game, we thought of
making it as our first miniproject using swing.
Its simple yet time consuming game.
Hope people enjoy it.
CONTRIBUTION
The project is made with the help of google,
YouTube. We used both of them for making
our project.
Our faculty also played an important role in
helping us making the project. She taught us
the thing which is most important in making
the project i.e. she taught us java.
As for myself I worked hard with my associate
Akash to bring the project to life.
Numerous attempts were made before the
project could be compiled.
After several failed attempts we were able to
bring the game which we wanted to life.
In this project both me and my associate
worked hard so that we can finish what we
started.
And thus, here it is THE TIC TAC TOE GAME.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class TTT1 extends JFrame implements
ItemListener, ActionListener{
int i,j,ii,jj,x,y,yesnull;
int
a[][]={{10,1,2,3,11},{10,1,4,7,11},{10,1,5,9,11},{1
0,2,5,8,11},
{10,3,5,7,11},{10,3,6,9,11},{10,4,5,6,11},
{10,7,8,9,11} };
int
a1[][]={{10,1,2,3,11},{10,1,4,7,11},{10,1,5,9,11},{
10,2,5,8,11},
{10,3,5,7,11},{10,3,6,9,11},{10,4,5,6,11},{10,7,8,9,
11} };
boolean state,type,set;
Icon ic1,ic2,icon,ic11,ic22;
Checkbox c1,c2;
JLabel l1,l2;
JButton b[]=new JButton[9];
JButton reset;
x=10; y=10;j=0;
for(i=0;i<=8;i++,x+=100,j++){
b[i]=new JButton();
if(j==3)
{j=0; y+=100; x=10;}
b[i].setBounds(x,y,100,100);
add(b[i]);
b[i].addActionListener(this);
}
reset=new JButton("RESET");
reset.setBounds(100,350,100,50);
add(reset);
reset.addActionListener(this);
}
}
if(set==false)
break;
}
}
TTT1(){
super("tic tac toe by ashwani");
state=true;type=true;set=true;
ic1=new ImageIcon("ic1.jpg");
ic2=new ImageIcon("ic2.jpg");
ic11=new ImageIcon("ic11.jpg");
ic22=new ImageIcon("ic22.jpg");
setLayout(null);
setSize(330,450);
setVisible(true);
setDefaultCloseOperation(JFrame.DISPOSE_ON_
CLOSE);
}
else if(c2.getState())
{ type=true;
}
remove(c1);remove(c2);
repaint(0,0,330,450);
showButton();
}
if(type==true)//logicfriend
{
if(e.getSource()==reset){
for(i=0;i<=8;i++){
b[i].setIcon(null);
} for
}
else{
for(i=0;i<=8;i++){
if(e.getSource()==b[i]){
if(b[i].getIcon()==null){
if(state==true){ icon=ic2;
state=false;} else{ icon=ic1; state=true; }
b[i].setIcon(icon);
}
}
}
}
}
else if(type==false){
if(e.getSource()==reset){
for(i=0;i<=8;i++){
b[i].setIcon(null);
}//eof for
for(i=0;i<=7;i++)
for(j=0;j<=4;j++)
a[i][j]=a1[i][j]; //again initialsing array
}
else{ //complogic
for(i=0;i<=8;i++){
if(e.getSource()==b[i]){
if(b[i].getIcon()==null){
b[i].setIcon(ic1);
if(b[4].getIcon()==null){
b[4].setIcon(ic2);
this.check(5);
} else{
this.complogic(i);
}
}
}
}
}
}
for(i=0;i<=7;i++){
Icon icon1=b[(a[i][1]-1)].getIcon();
Icon icon2=b[(a[i][2]-1)].getIcon();
Icon icon3=b[(a[i][3]-1)].getIcon();
if((icon1==icon2)&&(icon2==icon3)&&(icon1!=nu
ll)){
if(icon1==ic1){
b[(a[i][1]-1)].setIcon(ic11);
b[(a[i][2]-1)].setIcon(ic11);
b[(a[i][3]-1)].setIcon(ic11);
JOptionPane.showMessageDialog(TTT1.this,"!!!Y
OU won!!! click reset");
break;
}
else if(icon1==ic2){
b[(a[i][1]-1)].setIcon(ic22);
b[(a[i][2]-1)].setIcon(ic22);
b[(a[i][3]-1)].setIcon(ic22);
JOptionPane.showMessageDialog(TTT1.this,"wo
n! click reset");
break;
}
}
}