Question
Hello this is a Java Code for a tick tac toe game , It does not work , Can anyone help me finish it? ,
Hello this is a Java Code for a tick tac toe game , It does not work , Can anyone help me finish it? , Please just Retype the whole code using my parts to finish it . Thank you so much
import java.util.Scanner;
public class Main {
public static final int EMPTY = 0;
public static final int CROSS = 1;
public static final int CIRCLE = 2;
public static final int PLAYING = 0;
public static final int DRAW = 1;
public static final int CROSS_WON = 2;
public static final int CIRCLE_WON = 3;
public static final int ROWS = 3, COLS = 3;
public static int[][] board = new int[ROWS][COLS];
public static int currentState;
public static int currentPlayer;
public static int currentRow, currentCol;
public static Scanner in = new Scanner(System.in);
public static void main(String[] args) {
initGame();
printBoard();
if (currentState == CROSS_WON) {
System.out.println("'X' won!");
} else if (currentState == CIRCLE_WON) {
System.out.println("'O' won!");
} else if (currentState == DRAW) {
System.out.println("It's a Draw!");
}
if (currentPlayer == CROSS){
currentPlayer = CIRCLE;
}
else{
currentPlayer = CROSS;
//}
}
}
public static void initGame() {
for (int row = 0; row < ROWS; ++row) {
for (int col = 0; col < COLS; ++col) {
board[row][col] = EMPTY; // all cells empty
}
}
currentState = PLAYING; // ready to play
currentPlayer = CROSS; // cross plays first
}
public static void printBoard() {
for (int row = 0; row < ROWS; ++row) {
for (int col = 0; col < COLS; ++col) {
printCell(board[row][col]); // print each of the cells
if (col != COLS - 1) {
System.out.print("|"); // print vertical partition
}
}
System.out.println();
if (row != ROWS - 1) {
System.out.println("-----------"); // print horizontal partition
}
}
System.out.println();
}
public static void printCell(int cell) {
if (cell == EMPTY){
System.out.print(" ");
}
else if (cell == CIRCLE){
System.out.print(" O ");
}
else if (cell == CROSS){
System.out.print(" X ");
}
}
public static void playerMove(int theTurn){
}
//Update the current state of the game (PLAYING, DRAW, CROSS_WON, CIRCLE_WON)
public static void updateGame(){
}
public static boolean draw(){
return true;
}
public static boolean won(int theTurn, int currentRow, int currentCol){
return true;
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started