0

8x8 TicTacToe

For my assignment, I am trying to make an 8x8 TicTacToe using a GUI. So far, here is most of my code: private void resetBoard(java.awt.event.ActionEvent evt) { for (JButton[] row : buttons) { for (JButton cell : row) { cell.setEnabled(true); cell.setText(""); } } } private void selectButtons(JButton button) { //JButton temp; //temp = (JButton) evt.getSource(); if (button.getText().equals("")) { if (xTurn) { button.setText(user1); checkForWinner(user1); yTurn = false; oTurn = true; xTurn = false; } else if (oTurn) { button.setText(user2); checkForWinner(user2); yTurn = true; xTurn = false; oTurn = false; } else { button.setText(user3); checkForWinner(user3); oTurn = false; yTurn = false; xTurn = true; } button.setEnabled(false); } } private void checkForWinner(String player) { String xos = ""; // place all the rows in the string for winner checking for (JButton[] row : buttons) { for (JButton cell : row) { xos = xos + cell.getText(); } xos += ","; } // do the columns for (int col = 0; col < 8; col++) { for (int row = 0; row < 8; row++) { xos = xos + buttons[row][col].getText(); } xos += ","; } There are a couple of issues though. One being that it shows the winner only if a player places 3 marks adjacent to one another in a single line instead of 4. Also when restarting the game, player 1 (or user1) should always start first. Can someone explain to me what I am missing? And Sololearn didn't let me paste all of my code because it's long!

24th Jan 2023, 5:31 AM
Gradi Maxime Kasita Mbatika
2 Answers
0
Thank you Mirielle! I’ll implement your logic into my assignment. You’re awesome! 😁👍
24th Jan 2023, 12:10 PM
Gradi Maxime Kasita Mbatika