public class TicTacToe3 {
public static void main(String[] args){
}
int input = 0, turn = 0, mov = 0;
String sq1;
int[][] table = new int[3][3];
int play;
public void table()
{
for (int row=0; row < 3; row++)
for (int col=0; col < 3; col++)
table[row][col] = ((row * 3) + col + 1);
for (int row=0; row < 3; row++)
{
for (int col=0; col < 3; col++)
System.out.print(table[row][col] + "t");
System.out.println();
}
}
public int[][] playgame(int m)
{
mov = m;
if (turn%2==0)
play = 10;
else
play = 11;
switch(mov)
{
case 1:
table[0][0] = play;
break;
case 2:
table[0][1] = play;
break;
case 3:
table[0][2] = play;
break;
case 4:
table[1][0] = play;
break;
case 5:
table[1][1] = play;
break;
case 6:
table[1][2] = play;
break;
case 7:
table[2][0] = play;
break;
case 8:
table[2][1] = play;
break;
case 9:
table[2][2] = play;
break;
}
return table;
}
public void mov()
{
for (int row=0; row < 3; row++)
for (int col=0; col < 3; col++)
if (table[row][col]==play){
table[row][col]=play;
}
for (int row=0; row < 3; row++)
{
for (int col=0; col < 3; col++)
if (table[row][col]==10)
System.out.print("X"+"t");
else if (table[row][col]==11)
System.out.print("O"+"t");
else
System.out.print(table[row][col] + "t");
System.out.println();
}
turn++;
}
public boolean cwin()
{
boolean win;
if (table[0][1]==table[1][1]&&table[1][1]==table[2][1])
win = true;
else
if (table[0][2]==table[1][2]&&table[1][2]==table[2][2])
win = true;
else
if (table[0][0]==table[1][1]&&table[1][1]==table[2][2])
win = true;
else
if (table[2][0]==table[1][1]&&table[1][1]==table[0][2])
win = true;
else
if (table[0][0]==table[0][1]&&table[0][1]==table[0][2])
win = true;
else
if (table[1][0]==table[1][1]&&table[1][1]==table[1][2])
win = true;
else
if (table[2][0]==table[2][1]&&table[2][1]==table[2][2])
win = true;
else
if (table[0][0]==table[1][0]&&table[1][0]==table[2][0])
win = true;
else
win = false;
return win;
}
}
bigbags911 0 Newbie Poster
parry_kulk 14 Junior Poster Team Colleague
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.