Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Checking for Winners and Managing the Game All code is correct but there are two methods highlighted below where you need to do the logic
Checking for Winners and Managing the Game
All code is correct but there are two methods highlighted below where you need to do the logic for the game. Basically, checking the board to see if anyone has won and if there are more spaces to be selected.
import javax.swing.;
import java.awt.geom.;
import java.awt.;
import java.awt.event.;
import java.awt.Color;
public class TicTacToe extends JPanel implements ActionListener
JLabel greeting new JLabelTic Tac Toe";
JLabel promptLabel new JLabelChoose one button";
JLabel result new JLabel;
Font headlineFont new FontHelvetica Font.BOLD,
;
Font mediumFont new FontHelvetica Font.BOLD, ;
final int SIZE ;
final static int ROWSIZE ;
final static int COLSIZE ;
int x y;
JButton gameGrid new JButtonROWSIZECOLSIZE;
final static String BLANK ;
final static String XString X;
final static String OString O;
int row col ;
int num;
boolean spotFound;
boolean isDone false;
boolean playersTurn true;
boolean isWinPossible false;
String msg ;
String gridString;
char winChar;
public static boolean checkForWinnerJButton
gameGrid
boolean isDone false;
Your code goes here
The code to check for winners needs to be implemented
checkForWinner returns a boolean value representing a winner or not
return isDone;
public static boolean spacesRemainJButton grid
Your code goes here
spacesRemain returns a boolean value indicating that there are stillDigitsLeft
spaces to be selected.
return stillDigitsLeft;
public static void chooseSpotJButton gameGrid
int x y;
boolean placementMade false;
forx ; x ROWSIZE && placementMade; x
ifgameGridxgetTextequalsOString &&
gameGridxgetTextequalsOString &&
gameGridxgetTextequalsBLANK
gameGridxsetTextOString;
placementMade true;
else
ifgameGridxgetTextequalsOString &&
gameGridxgetTextequalsOString &&
gameGridxgetTextequalsBLANK
gameGridxsetTextOString;
placementMade true;
else
ifgameGridxgetTextequalsOString &&
gameGridxgetTextequalsOString &&
gameGridxgetTextequalsBLANK
gameGridxsetTextOString;
placementMade true;
fory ; y COLSIZE && placementMade; y
ifgameGridygetTextequalsOString &&
gameGridygetTextequalsOString &&
gameGridygetTextequalsBLANK
gameGridysetTextOString;
placementMade true;
else
ifgameGridygetTextequalsOString &&
gameGridygetTextequalsOString &&
gameGridygetTextequalsBLANK
gameGridysetTextOString;
placementMade true;
else
ifgameGridygetTextequalsOString &&
gameGridygetTextequalsOString &&
gameGridygetText
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