Basic Java
Basic Java
Basic Java
import java.util.Scanner;
class Main {
while (!gameEnded) {
if (player1) {
System.out.println(p1 + ", it's your
turn (x):");
} else {
System.out.println(p2 + ", it's your
turn (o):");
}
char c = '-';
if (player1) {
c = 'x';
} else {
c = 'o';
}
int row = 0;
int col = 0;
while (true) {
System.out.print("Enter the row
number: ");
row = in.nextInt();
System.out.print("Enter the column
number: ");
col = in.nextInt();
if (row < 0 || col < 0 || row >= n ||
col >= n) {
System.out.println("Invalid
position! Please try again.");
} else if (board[row][col] != '-') {
System.out.println("That
position is already taken! Please try again.");
} else {
break;
}
}