0
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;
    }
}

Edited by peter_budo: Correcting code tags

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by parry_kulk
1

You are having no code in the main method. The JVM is just executing the main method but nothing else.

.........
public static void main(String[] args){
}
...........

If you want to call any method on the TicTacToe3 object you will first have to instantiate it and than call the appropriate method

e.g.

.........
public static void main(String[] args){
	TicTacToe3 objT3 = new TicTacToe3(); //Instantiating the TicTacToe3 object
	objT3.table(); //Calling a method on it. Call suitable method required by you here
}
...........
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.