I know this is really simple. I have a tick tack toe game and when i run it it works and there are no errors. but the X's and O'x do not show in the board can someone please look at the code and show me the right way to do it. i know this is kinda lame question but i have been looking all over the net and cant seem to figure out the proper way to do it. I know the problem is in the "gameBoard" method and its cause i am telling the code to print the same board every time but i dont know how to do it the right way
package chap7MDA;
import java.util.Scanner;
public class chapexe7we {
public static void main(String[] args) {
char[][] board = new char [3][3];//make a game board
gameBoard(board);// call the method game board to make the board
do {
makeAMove(board, 'X');
gameBoard(board);
if(wiNNing('X', board)) {
System.out.println("X player won");
System.exit(1);
}
else if(tie(board)) {
System.out.println("No body won, It's a Draw Partners");
System.exit(2);
}
makeAMove(board, 'O');
gameBoard(board);
if(wiNNing('O', board)) {
System.out.println("O player won");
System.exit(3);
}
else if(tie(board)) {
System.out.println("No body won, It's a Draw Partners");
System.exit(4);
}
} while(true);
}//end main
public static void gameBoard(char [][] gBoard){
for(int i = 0; i < 3; i++){//populate the board with boarders
for(int j = 0; j < i; j++) {
System.out.println("\n-------------");
System.out.print("| | | | ");
}
}
System.out.println("\n-------------");//put a line at the bottom
}//end gameBoard
public static void makeAMove (char [][]board, char XsAnd0s){
Scanner input = new Scanner(System.in);//make a scanner object called input
boolean turn = false;
do{
System.out.println("Please enter the row for " + XsAnd0s + ":" );//prompt user
int row = input.nextInt();//take in a value for the row
System.out.println("Please enter the column for " + XsAnd0s + ":");//prompt user
int col = input.nextInt();//take in a value for the column
if (board[row][col] == 0){
board[row][col] = XsAnd0s;
turn = true;
}
else {
System.out.println("The other player already has this spot");
}
}
while(!turn);
}
public static boolean wiNNing(char XOs, char[][]board ){
for (int i = 0; i <3; i++)
if(XOs == board[i][0] && XOs == board[i][1] && XOs ==board[i][2])
return true;
for (int j = 0; j < 3; j++)
if (XOs == board[0][j] && XOs == board[1][j] && XOs == board[2][j])
return true;
if(XOs == board[0][0] && XOs == board[1][1] && XOs == board[2][2])
return true;
return XOs == board[0][2] && XOs == board[1][1] && XOs == board[2][0];
}
public static boolean tie (char[][] board){
boolean noWinner = false;
for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++)
if(board[i][j] == 0)
return noWinner;
}
return true;
}
}//end exercise7