I have made a 2-player console tic tac toe program but the board that is displayed while playing the game is blank cells except for the side and bottom notation. I would like print lines in between the rows and columns but I don't know how. Here is the code involving my board:
public void createBoard()
{
//This method creates the 3x3 board and fills the board with 0s
for (int row = 0; row < board.length; row++) {
for (int column = 0; column < board[0].length; column++) {
board[row][column] = 0;
}
}
//calls displayBoard method
displayBoard();
}
public void displayBoard(){
//creates right amount of cells for 3 rows
for (int row=0; row < board.length; row++)
{
//spaces between row notation and board + prints row notation
System.out.print("\t" +(char)('a'+ row) + " ");
//creates right amount of cells for the 3 columns
for (int column=0; column < board.length; column++)
{
if(board[row][column]==BLANK){
System.out.print("\t");
}
else if(board[row][column]==X){
System.out.print("\tX");
}
else{
System.out.print("\tO");
}
}
System.out.println();//blanks on right side of board
}
System.out.println("\t \t1 \t2 \t3"); //column notation on bottom
checkTie();
}
Aucun commentaire:
Enregistrer un commentaire