Note that there are some explanatory texts on larger screens.

plurals
  1. PO2 player Tic-Tac-Toe Game
    primarykey
    data
    text
    <p>I am trying to make a two player tic-tac-toe game but I cannot get it so that when Its the next players turn it will print out an O and then when its the next player it will print print out an X.</p> <pre><code>import java.util.Scanner; public class TicTacToeMain{ public static void main(String[]args){ Scanner scan = new Scanner(System.in); String[][] Board = new String[][] { {" ", " ", " "}, {" ", " ", " "," "}, {" ", " ", " "," "},{" "," "," "," "},{" "," "," "}}; grid1(Board,scan); System.out.println("Where do you wan't your x to be?"); move1(Board,scan); } public static void grid1(String[][] Board, Scanner scan){ System.out.println("A " + Board[0][1] +Board[0][0]+ " | " + Board[3][1] + " | "+ Board[0][2]); System.out.println(" -------------"); System.out.println("B " + Board[1][1] +Board[1][0]+ " | " + Board[3][2] + " | "+ Board[1][2]); System.out.println(" -------------"); System.out.println("C " + Board[3][3] +Board[2][0]+ " | " + Board[2][1] + " | "+ Board[2][2]); } public static void move1(String[][] Board, Scanner scan){ int Input = scan.nextInt(); for (int i = 0;i&lt;100;i++){ if (Input == 1){ Board[0][1]="X"; grid1(Board, scan); move2(Board,scan); } else if(Input == 2){ Board[3][1]="X"; grid1(Board,scan); move2(Board,scan); } else if(Input == 3){ Board[0][2]="X"; grid1(Board,scan); move2(Board,scan); } else if(Input == 4){ Board[1][1]="X"; grid1(Board,scan); move2(Board,scan); } else if(Input ==5){ Board[3][2]="X"; grid1(Board,scan); move2(Board,scan); } else if(Input ==6){ Board[1][2]="X"; grid1(Board,scan); move2(Board,scan); } else if(Input ==7){ Board[3][3]="X"; grid1(Board,scan); move2(Board,scan); } else if(Input == 8){ Board[2][1]="X"; grid1(Board,scan); move2(Board,scan); } else if(Input ==9){ Board[2][2]="X"; grid1(Board,scan); move2(Board,scan); } } } public static void move2(String[][] Board, Scanner scan) { System.out.println("Where do you wan't your O to be?"); int Input = scan.nextInt(); if (Input == 1){ Board[0][1]="O"; grid1(Board, scan); move3(Board, scan,Input); } else if(Input == 2){ Board[3][1]="O"; grid1(Board,scan); move3(Board, scan,Input); } else if(Input == 3){ Board[0][2]="O"; grid1(Board,scan); move3(Board, scan,Input); } else if(Input == 4){ Board[1][1]="O"; grid1(Board,scan); } else if(Input ==5){ Board[3][2]="O"; grid1(Board,scan); move3(Board, scan,Input); } else if(Input ==6){ Board[1][2]="O"; grid1(Board,scan); move3(Board, scan,Input); } else if(Input ==7){ Board[3][3]="O"; grid1(Board,scan); move3(Board, scan,Input); } else if(Input == 8){ Board[2][1]="O"; grid1(Board,scan); move3(Board, scan,Input); } else if(Input ==9){ Board[2][2]="O"; grid1(Board,scan); move3(Board, scan,Input); } } public static void move3(String[][] Board, Scanner scan, int Input){ if (Input == 1){ Board[0][1]="X"; grid1(Board, scan); } else if(Input == 2){ Board[3][1]="X"; grid1(Board,scan); } else if(Input == 3){ Board[0][2]="X"; grid1(Board,scan); } else if(Input == 4){ Board[1][1]="X"; grid1(Board,scan); } else if(Input ==5){ Board[3][2]="X"; grid1(Board,scan); } else if(Input ==6){ Board[1][2]="X"; grid1(Board,scan); } else if(Input ==7){ Board[3][3]="X"; grid1(Board,scan); } else if(Input == 8){ Board[2][1]="X"; grid1(Board,scan); } else if(Input ==9){ Board[2][2]="X"; grid1(Board,scan); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload