Question: The code when ran does not catch whether x , 0 , or of its a tie. How to fix it ? package games.boards; import
The code when ran does not catch whether x or of its a tie. How to fix it
package games.boards;
import java.awt.event.ActionEvent;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import java.awt.event.ActionListener;
public class TicTacToeGame extends JFrame
private Board gb;
private int turn;
public static void mainString args
SwingUtilities.invokeLaternew Runnable
public void run
new TicTacToeGame;
;
static intgameboard;
static final int EMPTY ;
static final int NOUGHT ;
static final int CROSS ;
Set a square on the board must be empty
public static void setint val, int row, int col throws IllegalArgumentException
if gameboardrowcol EMPTY
gameboardrowcol val;
else throw new IllegalArgumentExceptionPlayer already there!";
public int getOutcome
for int i ; i ; i
if gameboardi gameboardi gameboardi NOUGHT
gameboardi gameboardi gameboardi NOUGHT
return ;
else if gameboardi gameboardi gameboardi CROSS
gameboardi gameboardi gameboardi CROSS
return ;
Check diagonals
if gameboard gameboard gameboard NOUGHT
gameboard gameboard gameboard NOUGHT
return ;
else if gameboard gameboard gameboard CROSS
gameboard gameboard gameboard CROSS
return ;
Check tie
for int i ; i ; i
for int j ; j ; j
if gameboardij EMPTY
return ;
return ;
public void takeTurnCell c
Mark curMark turn
Mark.NOUGHT: Mark.CROSS;
gbsetCellcurMarkcgetRowcgetColumn;
int outcome getOutcome;
JOptionPane.showMessageDialogthis;
System.exit;
private TicTacToeGame
gb new Board new ActionListener
public void actionPerformedActionEvent al
Cell c Cell algetSource;
takeTurnc;
;
this.addgb;
this.setDefaultCloseOperationEXITONCLOSE;
this.setTitleTICTACTOE";
this.setSize;
this.setVisibletrue;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
