Question: 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 JLabel("Tic Tac Toe");
JLabel promptLabel = new JLabel("Choose one button");
JLabel result = new JLabel();
Font headlineFont = new Font("Helvetica", Font.BOLD,
20);
Font mediumFont = new Font("Helvetica", Font.BOLD, 14);
final int SIZE =9;
final static int ROW_SIZE =3;
final static int COL_SIZE =3;
int x, y;
JButton[][] gameGrid = new JButton[ROW_SIZE][COL_SIZE];
final static String BLANK ="";
final static String XString ="X";
final static String OString ="O";
int row =0, col =0;
int num;
boolean spotFound;
boolean isDone = false;
boolean playersTurn = true;
boolean isWinPossible = false;
String msg ="";
String gridString;
char winChar;
public static boolean checkForWinner(JButton [][]
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 spacesRemain(JButton[][] grid)
{
// Your code goes here
// spacesRemain returns a boolean value indicating that there are stillDigitsLeft
// spaces to be selected.
return stillDigitsLeft;
}
public static void chooseSpot(JButton[][] gameGrid)
{
int x, y;
boolean placementMade = false;
for(x =0; x < ROW_SIZE && !placementMade; ++x)
{
if(gameGrid[x][0].getText().equals(OString) &&
gameGrid[x][1].getText().equals(OString) &&
gameGrid[x][2].getText().equals(BLANK))
{
gameGrid[x][2].setText(OString);
placementMade = true;
}
else
if(gameGrid[x][0].getText().equals(OString) &&
gameGrid[x][2].getText().equals(OString) &&
gameGrid[x][1].getText().equals(BLANK))
{
gameGrid[x][1].setText(OString);
placementMade = true;
}
else
if(gameGrid[x][1].getText().equals(OString) &&
gameGrid[x][2].getText().equals(OString) &&
gameGrid[x][0].getText().equals(BLANK))
{
gameGrid[x][0].setText(OString);
placementMade = true;
}
}
for(y =0; y < COL_SIZE && !placementMade; ++y)
{
if(gameGrid[0][y].getText().equals(OString) &&
gameGrid[1][y].getText().equals(OString) &&
gameGrid[2][y].getText().equals(BLANK))
{
gameGrid[2][y].setText(OString);
placementMade = true;
}
else
if(gameGrid[0][y].getText().equals(OString) &&
gameGrid[2][y].getText().equals(OString) &&
gameGrid[1][y].getText().equals(BLANK))
{
gameGrid[1][y].setText(OString);
placementMade = true;
}
else
if(gameGrid[1][y].getText().equals(OString) &&
gameGrid[2][y].getText().equals(OString) &&
gameGrid[0][y].getText

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!