Coders Packet

JAVA Title: TIC TAC TOE Game

By Rayven Santosh Thakur

In this article, We gonna see how to create a fun game. A game that is a perfect time killer. TIC TAC TOE We will see how to create a Tic tac toe game in the Java Language.

Step 1: Create New Project.


Step 2: Select New Jframe.


Step 3: Select GridLayout.


Step 4: Add Require gaps , Horizontal , vertical fields(in this project 5 Horizontal , 3 Vertical, 2 gaps).


Step 5: Add Atleast 15 jButtons and design accordingly.

Step 6: Create 3 methods 
1. private void gamescore()

{
jlbplayerx.setText(String.valueOf(xCount));
jlbplayery.setText(String.valueOf(oCount));
}


2.private void choose_a_player()

{
if(Startgame.equalsIgnoreCase("X"))
{
Startgame ="O";
}
else
Startgame="X";
}

3.public void winner()

{
String b1 = jButton1.getText();
String b2 = jButton2.getText();
String b3 = jButton3.getText();

String b4 = jButton4.getText();
String b5 = jButton5.getText();
String b6 = jButton6.getText();

String b7 = jButton7.getText();
String b8 = jButton8.getText();
String b9 = jButton9.getText();

if(b1==("X")&& b2==("X")&& b3==("X"))
{
JOptionPane.showMessageDialog(this,"Player X Win","Tic tac toe",JOptionPane.INFORMATION_MESSAGE);
xCount++;
gamescore();
jButton1.setBackground(Color.yellow);
jButton2.setBackground(Color.yellow);
jButton3.setBackground(Color.yellow);
}

 and many more possible winning rows columns and crosses.

Download Complete Code

Comments

No comments yet