Вы находитесь на странице: 1из 50

c p  





 
 


 













Lecturer: Dr.Houria
Course : ECE 
Name : Maha Nour
VPa ge

  

   

Introduction to the program 3

Problem statement 3

Requirements part 1 (eclips) 4


Requirements part 2 (NetBeans) 4

Design part 1 (eclips) 5


Design part 2 (NetBeans) 8

Implementation part 1
TicTacToe Class 11
GameTest Class 16

Implementation part 2
TicTacToe Class 19
JTic class design 23
JTic class source 23

Testing and Validation part 1 42


Testing and Validation part 2 46

Conclusion 50
uPa ge

     

The general goal of this project is to join all the experience from ECE 102
and ECE 202 to make a complete program.

The specific purpose of this project is to design and implement java


application allowing two players to play Tic-Tac-Toe game.

 

Tic-Tac-Toe game needs a big box divided in 3 rows and in 3 columns to create 9
equal empty cells. Also it requires 2 players one of them is X-player and the other
one will be O-player. In each player turn he/she should fill only one empty cell
with X if it was X-player turn , and with O if it was O-player turn. The winner in
this game who can fill a 3 cells in a straight line with the same character. Either
vertically or horizontally or even in a slope form.

To design this game we use to integrated design environments (IDE) which they
are Eclips and NetBeans.

Eclips was un professional, time consuming and tiresome in short it was not
friendly to use. But in the other hand Net Beans was friendly to use it has buttons
and zero requirements from the user.
ÿPa ge

     


1. The program displays welcome Message , then it displays empty game board to
the user.
2. The player is requested to enter the number of the row and the number of the
column to chose the position that he/she want to play in.
3. Error message will be display if the position is not valid and the prog ram will ask
the user to chose other position.
4. if the move is valid then the program will display the new state of the board
after the play.
5. If there isn't an winner or an equal game then game will continue. The program
will switch the player turn and all the steps before will be repeated.
6. If there is a winner the program will d isplay a message to the winner player . If
the game is Tie then it will display Tie game. In the both cases the program will
ask the user if he /she want to play a new game.
7. If the user's answer is yes then a clear game board will display to start a new
game. If the user's answer is no thanks message will display then exit the game.
If the answer is anything else error message will display.

   V 


1. the program display user interface game board with 9 empty buttons and
one long white box to show the players turns and the game state. Also it has 2
buttons in the end of the game board one to have a new game and the other
to exit.
2. The program starts with X- player turn.
3. The player is requested to click on the button that he/ she want to play in
then the program will appear the player 's character in the button that he/she
clicked on.
4. After that directly the program will change the player turn and displ ay the
new player's turn in the white box if there is no winner or tie game.
5. If there is a winner or the game end with Tie then the program will show the
players the winner player or a Tie game in the white box.
6. If the user clicked a new game button the players will have clear buttons in
the game board.
7. If the user clicked exit the game board will diaper
Pa ge

 

Ë   
!     

public class TicTacToe

//Data fields:

// the main data fields:


private char[][] gameBoard ;
//3 x 3 board to hold plays.
private char player;
// declare player of type character to be X or O player.
private int row;
// row number that the user want to play in .
private int column;
//column number that the user want to play in.

// data fields to check if a places in the game is used before:


private int r [];
// declare row array of type integer to save all the rows
entered by the user.
private int c [];
// declare column array of type integer to save all the
columns entered by the user.
private int noOfTries ;
// number of users(players) tries starting from zero.

// Methods:

public TicTacToe()
// constructor method toCreates and Initializes the board to empty.
public void play(int i, int j)
//initialize the row to the row entered by the user
// initialize the column to the column entered by the user .
public char possition ()
// in to fill the game board position (row, column) with X or O character.
public boolean checkWin()
// returns true if there is a winner and false I f not.
public boolean noWinner()
// test if there is no winner and the game should continue.
//it returns true if there is no winner.
public boolean checkEquals()
// test if all the game board positions are filled with out a winner.
public void displayBoard()
// to display the game board .
public void newGame()
// to Clear the board for a new game.
public char getPlayer()
mPa ge

// Returns the character corresponding to the current player (X or O).


public void switchPlayer()

// to switch the player by changing the current player from X to O or from O


to X.

// Methods to check places in the game if it used before:


public int getnoOfTries()
// to get the number of users tries.
public int incrementNO()
// this method to increment and get the number of users tries.
public int getRowArray()
// to save and get all the rows entered by the user in arrays.
public int getColumnArray()
// to save and get all the columns entered by the user in arrays.
public boolean UsedPlace( int num)
// to test if the places in gameBoard is used before or not.

public class GameTest

// Methods:

public static void main(String[] args)


Pa ge

    "    


Î Display welcome Message.
Î 

- Display the game board.


- 
get the row from the user.
- l  the row not equal 0 or 1 or 2.
- 
get the column from the user.
- l  the column not equal 0 or 1 or 2.
- Test " the position (row, column) is chosen before  :
Display error message

Ask the user to chose other position.
l  row or column not equal 0 or 1 or 2.
- Display the game board again.
- Test " there is a winner  :
Display a message to the player winner.
- ƒwitch the players.

Î l  no winner and no equal game.


Î " the game is equal  
- Display Tie game.
Î 
- Ask the players " they want to play again :
" the answer is yes 
Display a new game.
# " the answer is no 
Display thank message
# " the answer not yes or no 
Display error message
Î l  the answer is yes.
-Pa ge

Ë  V 
!   

public class TicTacToe

//Data fields:

public char[][] gameBoard; //3 x 3 board to hold plays.


private char player; // declare player of type character to be X or O player.
private int row; // row number that the user want to play in .
private int column; //column number that the user want to play in.

// Methods:

public TicTacToe()
// Creates and Initializes the board to empty.
public void play(int i, int j)
//initialize the row to the row entered by the user
// initialize the column to the column entered by the user .
public char possition ()
// in to fill the game board position (row, column) with X or O character.
public boolean checkWin()
// returns true if there is a winner and false If not.
public boolean noWinner()
// test if there is no winner and the game should continue.
//it returns true if there is no winner.
public boolean checkEquals()
// test if all the game board positions are filled with out a winner.
public void newGame()
// to Clear the board for a new game.
public char getPlayer()
// Returns the character corresponding to the current player (X or O)
public void switchPlayer()
// to switch the player by changing the current player from X to O or from O
to X.
›Pa ge

public class JTic extends javax.swing.JFrame

// variables :
JButton board [][]; // board is array of type JButton

// create a game object from TicTacToe class.


TicTacToe game = new TicTacToe();

// methods:

public JTic() //JFrame class


private void initComponents()
// tic tac toe buttons:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) // position (0,0)
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) // position (0,1)
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) // position (0,2)
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) // position (1,0)
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) // position (1,1)
private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) // position (1,2)
private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) // position (2,0)
private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) // position (2,1)
private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) // position (2,2)
// new game button:
private void jButton10ActionPerformed(java.awt.event.ActionEvent evt)
// Exit button :
private void jButton11ActionPerformed(java.awt.event.ActionEve nt evt)
// main class:
public static void main(ƒtring args[])
$  P a g e

Ë     "  V

Display a user interface game board


    "   

Î Initialize the position in board to zero row and zero column.


Î Test " the button is empty and no winner 

- Display the player character in button 1.


- Test " there is a winner 
Display the winner player in TextField2
- Test " there is no winner and the game should continue  
o ƒwitch the players turns.
o Display the player turn in TextField2.
o Test if the game is end with tie then :
Display Tie game in TextField2
- # display error message.

  all the buttons from 2 to 9 have the same Pseudo code but the difference
will be in initializing the board position. The other difference will be in display
the player character in button(number) instead of button1.

    " %    $ 

Î Clear all the buttons

    " #
    

Î Exit the game board.


  P a g e

  

Ë    !     

          

import javax.swing.JOptionPane;

public class TicTacToe {

//Data fields:

// the main data fields:


private char[][] gameBoard ;//3 x 3 board to hold plays.
private char player; // declare player of type character to be X or O
player.
private int row; // row number that the user want to play in .
private int column; //column number that the user want to play in.

// data fields to check if a places in the game is used before:


private int r []; // declare row array of type integer to save all the
rows entered by the user.
private int c []; // declare column array of type integer to save all
the columns entered by the user.
private int noOfTries ; // number of users(players) tries starting from
zero.

// Methods:

// Creates and Initializes the board to empty.


public TicTacToe()
{
player='X'; //Initialize the fist player to be the X -player.
gameBoard= new char [3][3];//Initialize the game board to be 3 x
3 board.
noOfTries=0; //Initialize number of users(players) tries to
Zero(note :the first try is 0 try ).
r=new int [30]; //Initialize the row array to 30 to hold 30 try
for the players.
c = new int [30];//Initialize the column array to 30 to hold 30
try for the players.
}

public void play(int i, int j) // The current players plays at position


(i, j)
{
row=i; //initialize the row to row entered by the user .
column=j; // initialize the column to column entered by the user.
}

// this method of character to fill the game board position with X or O


character.
public char possition ()
{
V  P a g e

// assign the game board position to X or O character depend on


the player tu rn.
return gameBoard [row][column]=player;
}

// this method of type boolean to check if any of the players win.


// returns true if there is a winner
public boolean checkWin()
{
if ((row==0||row==1||row==2)&&(column==0||column==1||column==2))
{
// test if there is a winner in vertical form :
if
((gameBoard[0][column]==gameBoard[1][column])&&(gameBoard[1][column]==gameBoa
rd[2][column]))
return true;
else
// test if there is a winner in horizontal form
:

if((gameBoard[row][0]==gameBoard [row][1])&&(gameBoard[row][1]==gameBoar
d[row][2]))
return true;
else
// check if there is a winner in a slope
form :
if(gameBoard [1][1]=='X' || gameBoard [1][1]=='O'
)
{
if
((gameBoard[0][0]==gameBoard [1][1])&&( gameBoard[1][1]==gameBoard [2][2]))
return true;
else
if
((gameBoard[0][2]==gameBoard [1][1])&&( gameBoard[1][1]==gameBoard [2][0]))
return true;
else
return false;

}else return false;

}else return false;


}

// this is method of type boolean to test if there is no winner and the


game should continue.
//it returns true if there is no winner in the game and false if there
is.
public boolean noWinner()
{
if ((!checkW in()))//
return true;
else
return false;

// this is method of type boolean to test if all the game board


positions are filled with out a winner.
// return true if the game is over and there is no winner
u  P a g e

public boolean checkEquals()


{
if
((gameBoard[0][0]=='X'||gameBoard[0][0]=='O')&&(gameBoard[0][1]=='X'||gameBoa
rd[0][1]=='O')&&(gameBoard [0][2]=='X'||gameBoard [0][2]=='O'))
if
((gameBoard[1][0]=='X'||gameBoard[1][0]=='O')&&(gameBoard[1][1]=='X'||gameBoa
rd[1][1]=='O')&&(gameBoard [1][2]=='X'||gameBoard [1][2]=='O'))
if
((gameBoard[2][0]=='X'||gameBoard[2][0]=='O')&&(gameBoard[2][1]=='X'||gameBoa
rd[2][1]=='O')&&(gameBoard [2][2]=='X'||gameBoard [2][2]=='O'))
if
((gameBoard[0][0]=='X'||gameBoard[0][0]=='O')&&(gameBoard[0][0]=='X'||gameBoa
rd[0][0]=='O')&&(gameBoard [0][0]=='X'||gameBoard [0][0]=='O'))
if
((gameBoard[0][1]=='X'||gameBoard[0][1]=='O')&&(gameBoard[0][1]=='X'||gameBoa
rd[0][1]=='O')&&(gameBoard [0][1]=='X'||gameBoard [0][1]=='O'))

if
((gameBoard[0][2]=='X'||gameBoard[0][2]=='O')&&(gameBoard[0][2]=='X'||gameBoa
rd[0][2]=='O')&&(gameBoard [0][2]=='X'||gameBoard [0][2]=='O'))

return true;

else return false;


else
return false;
else return
false;
else return false;
else return false;
else return false;

// this method of type void to display the game board.


public void displayBoard()
{
// each position display the gameBoard array that represent it .
JOptionPane. × ××  (null,"------ TicTacToe Game ------
\n" +
"| "+gameBoard[0][0]+" |
"+gameBoard[0][1]+" | " +gameBoard[0][2]+" |" +
"\n-------------------------------------
\n" +
"| "+gameBoard[1][0]+" |
"+gameBoard[1][1]+" | " +gameBoard[1][2]+" |\n " +
"----------------------------
---------\n" +
"| "+gameBoard[2][0]+"
| "+gameBoard[2][1]+" | " +gameBoard[2][2]+" |" +
"\n--------------
----------------------- ");
}

// this method of type void to Clear the board for a new game.
public void newGame()
{
player='X';// initialize the first player in the new game to X
gameBoard= new char [3][3]; // make new game board with the same
size 3 x 3.
ÿ  P a g e

// this method of type character to get the player.


// Returns the character corresponding to the current player (X or O)
public char getPlayer()
{
return player;
}

// this method to switch the player by changing the current player from
X to O or from O to X
public void switchPlayer()
{
if (player =='X')
player = 'O';
else
player = 'X';

// the method of type integer to get the number of users tries.


public int getnoOfTries()
{
return noOfTries ;
}

// this method of type integer to increment and get the number of users
tries.
public int incrementNO()
{
return noOfTries ++;
}

//the method of type integer to save and get all the rows entered by
the user.
public int getRowArray()
{
return r[noOfTries ]=row; // assign and get number of users tries
row array to the current row.
}

//the method of type integer to save and ge t all the column entered by
the user.
public int getColumnArray()
{
return c[noOfTries ]=column;// assign and get number of users
tries column array to the current column.
}

// this method of type boolean to test if the places in gameBoard is


used before or not:
public boolean UsedPlace( int num)// this method with one parameter of
type integer
{
// start checking the Used Places from the second try and all
after.
if (noOfTries>=1)
{
// test if the current row equals to any row entered before
.
  P a g e

// and test if the recent entered column is equal to any


column entered before.

if ((r[num]==r[noOfTries ])&&(c[num]==c[noOfTries ]))


return true; // mean the place that the user chose is
used before.
else
return false; // mean the place that the user chose
is empty.
}
else// mean the first try when the number of tries is zero and
all the places are empty.
return false;

}
m  P a g e

&         

import javax.swing.JOptionPane;

public class GameTest {

public static void main(String[] args) {

// declare variables:
String answer;
String str;
int numOfLoob=0;
int r;
int c;

// Display welcome message to the game.


JOptionPane. × ××  (null," WELCOME \n To
TicTacToe Game" );

do
{
TicTacToe game= new TicTacToe(); // create a new object game
from TicTacToe class.
game.displayBoard(); // display the game board.

do
{
// get the row & make sure it is 0 or 1 or 2.
do{
//get the row from the user
str =
JOptionPane. × 
  (game.getPlayer()+ "-player, Enter the row you want
to play at." );
r = Integer. ×
(str);// convert it from
string to integer.

//Display error message if the user entered


other than 0,1 and 2.
if ((r!=0&&r!=1&&r!=2))
JOptionPane. × ××  (null,"Error
Message \n plase enter 0 or or 1 or 2" );
}while (r!=0&&r!= 1&&r!=2); //ask the user to enter a
new row if the user entered wrong row.

// get the column & make sure it is 0 or 1 or 2.


do{
//get the column from the user
str =
JOptionPane. × 
  (game.getPlayer()+ "-player, Enter the column you
want to play at." );
c = Integer. ×
(str);

//Display error message if the user entered


other than 0,1 and 2.
if ((c!=0&&c!=1&&c!=2))
JOptionPane. × ××  (null,"Error
Message \n plase enter 0 or or 1 or 2");
  P a g e

}while (c!=0&&c!=1&&c!=2); //ask the user to enter a


new column if the user entered wrong row.

game.play(r,c); // call the play method from TicTacToe


by using game object.
game.getRowArray(); // call the getRowArray method
from TicTacToeby using game object.
game.getColumnArray(); // call the getColumnArray
method from TicTacToe by using game object.

// To check if the places in game Board is used


before or not:

for(numOfLoob=0;numOfLoob< game.getnoOfTries();numOfLoob++) // test the


current position to all the positions before.
{
// if user chose a used position Error message
will be displayed.
// and ask the user to enter other position
if (game.UsedPlace(numOfLoob))
{
JOptionPane. × ××  (null,"ERROR
MESSAGE\nPlease cho ose other position " );

do{
//get a new row from the user
str =
JOptionPane. × 
  (game.getPlayer()+ "-player, Enter the row you want
to play at." );
r = Integer. ×
(str);

//Display error message if the user


entered other than 0,1 and 2.
if ((r!=0&&r!=1&&r!=2))

JOptionPane. × ××  (null,"Error Message \n plase enter 0 or


or 1 or 2" );
}while (r!=0&&r!=1&&r!=2); //ask the user
to enter a new row if the user entered wrong row.

// get a new column & make sure it is 0


or 1 or 2.
do{
//get the column from the user
str =
JOptionPane. × 
  (game.getPlayer()+ "-player, Enter the column you
want to play at." );
c = Integer. ×
(str);

//Display error message if the user


entered other than 0,1 and 2.
if ((c!=0&&c!=1&&c!=2))

JOptionPane. × ××  (null,"Error Message \n plase enter 0 or


or 1 or 2" );
}while (c!=0&&c!=1&&c!=2);

game.play(r,c);
game.getRowArray();
-  P a g e

game.getColumnArray();
}

}
game.incrementNO(); // call incrementNO method from
TicTacToe class by using game object
game.possition (); // call possition method.
game.displayBoard(); // display the game board again
after the entered position.

//check if any of the players win:


if (game.checkWin())
JOptionPane. × ××  (null," player "
+game.getPlayer()+ " is the winner" );

// call switchPlayer method to change the current


player from X to O or from O to X
game.switchPlayer();

}while (game.noWinner()&&!game.checkEquals()); // test if no


winner and no Tie game then the game will continue

//Display Tie game if all the game board positions are


filled with out a winner.
if (game.checkEquals())
JOptionPane. × ××  (null,"TIE GAME" );

do
{
// ask the user if he / she want to play an new game.
answer = JOptionPane. × 
  ("DO you want to
play a new game ? " );

// if the user type yes an new game will display.


if (answer.equalsIgnoreCase( "yes"))
game.newGame();
else
if (answer.equalsIgnoreCase( "no"))// if the
user type no thank message will be displayed
JOptionPane. × ××  (null,"Thank
you");
else// if the user typed something wrong, error
message will display.
JOptionPane. × ××  (null,"ERROR
MESSAGE \n PLEASE ANSWE YES OR NO." );

}while
((!answer.equalsIgnoreCase( "yes"))&&(!answer.equalsIgnoreCase( "no")));// ask
the user again if he/she typed something wrong.

}while (answer.equalsIgnoreCase( "yes"));// if the user typed a


yes all the main method will run again .

}
›  P a g e

Ë  V  !   
          

public class TicTacToe {

//Data fields:

public char[][] gameBoard;//3 x 3 board to hold plays.


private char player; // declare player of type character to be X or O player.
private int row; // row number that the user want to play in .
private int column; //column number that the user want to play in.

// Methods:

// Creates and Initializes the board to empty.


public TicTacToe()
{
player='X'; //Initialize the fist player to be the X -player.
gameBoard= new char [3][3];//Initialize the game board to be 3 x 3
board.
}

public void play(int i, int j) // The current players plays at position (i, j)
{
row=i; //initialize the row to row entered by the user .
column=j; // initialize the column to column entered by the user.
}

// this method of character to fill the game board position with X or O


character.
public char possition ()
{
// assign the game board position to X or O character depend on the
player turn.
return gameBoard[row][column]=player;
}

// this method of type boolean to check if any of the players win.


// returns true if there is a winner
public boolean checkWin()
{
if
((row==0||row==1||row==2)&&(column==0||column==1||column==2))
V$  P a g e

{
// test if there is a winner in vertical form :
if
((gameBoard[0][column]==gameBoard[1][column])&&(gameBoard[1][column]==game
Board[2][column]))
return true;
else
// test if there is a winner in horizontal form :

if((gameBoard[row][0]==gameBoard[row][1])&&(gameBoard[row][1]==gameBo
ard[row][2]))
return true;
else
// check if there is a winner in a slope form
:
if(gameBoard[1][1]=='X' || gameBoard[1][1]=='O' )
{
if
((gameBoard[0][0]==gameBoard[1][1])&&(gameBoard[1][1]==gameBoard[2][2]))
return true;
else
if
((gameBoard[0][2]==gameBoard[1][1])&&(gameBoard[1][1]==gameBoard[2][0]))
return true;
else
return false;

}else return false;

}else return false;


}

// this is method of type boolean to test if there is no winner and the game
should continue.
//it returns true if there is no winner in the game and false if there is.
public boolean noWinner()
{
if ((!checkWin()))//
return true;
else
return false;

// this is method of type boolean to test if all the game board positions are filled
with out a winner.
V  P a g e

// return true if the game is over and there is no wi nner


public boolean checkEquals()
{
if
((gameBoard[0][0]=='X'||gameBoard[0][0]=='O')&&(gameBoard[0][1]=='X'||gameBoar
d[0][1]=='O')&&(gameBoard[0][2]=='X'||gameBoard[0][2]=='O'))
if
((gameBoard[1][0]=='X'||gameBoard[1][0]=='O')&&(gameBoard[1][1]=='X'||gameBoar
d[1][1]=='O')&&(gameBoard[1][2]=='X'||gameBoard[1][2]=='O'))
if
((gameBoard[2][0]=='X'||gameBoard[2][0]=='O')&&(gameBoard[2][1]=='X'||gameBoar
d[2][1]=='O')&&(gameBoard[2][2]=='X'||gameBoard[2][2]=='O'))
if
((gameBoard[0][0]=='X'||gameBoard[0][0]=='O')&&(gameBoard[0][0]=='X'||gameBoar
d[0][0]=='O')&&(gameBoard[0][0]=='X'||gameBoard[0][0]=='O'))

if
((gameBoard[0][1]=='X'||gameBoard[0][1]=='O')&&(gameBoard[0][1]=='X'||gameBoar
d[0][1]=='O')&&(gameBoard[0][1]=='X'||gameBoard[0][1]=='O'))

if
((gameBoard[0][2]=='X'||gameBoard[0][2]=='O')&&(gameBoard[0][2]=='X'||gameBoar
d[0][2]=='O')&&(gameBoard[0][2]=='X'||gameBoard[0][2]=='O'))

return true;

else return false;

else return false;


else return
false;
else return false;
else return false;
else return false;

// this method of type void to Clear the board for a new game.
public void newGame()
{
player='X';// initialize the first player in the new game to X
gameBoard= new char [3][3]; // make new game board with the same
size 3 x 3.
}

// this method of type character to get the player.


VV  P a g e

// Returns the character corresponding to the current player (X or O)


public char getPlayer()
{
return player;
}

// this method to switch the player by changing the current player from X to O
or from O to X
public void switchPlayer()
{
if (player =='X')
player = 'O';
else
player = 'X';

}
Vu  P a g e

'         

  

( 
import javax.swing.JOptionPane;
import javax.swing.JButton;

public class JTic extends javax.swing.JFrame {

// Data fields :

JButton board [][];

// create a game object from TicTacToe class.


TicTacToe game = new TicTacToe();

/** Creates new form JTic */


public JTic() {
initComponents();
// create board array of type JButton with size :3 x 3
board = new JButton[3][3];

// each board array poision assigend to its button


board[0][0]=jButton1;
Vÿ  P a g e

board[0][1]=jButton2;
board[0][2]=jButton3;

board[1][0]=jButton4;
board[1][1]=jButton5;
board[1][2]=jButton6;

board[2][0]=jButton7;
board[2][1]=jButton8;
board[2][2]=jButton9;

}
@ƒuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

jPanel1 = new javax.swing.JPanel();


jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
jButton5 = new javax.swing.JButton();
jButton6 = new javax.swing.JButton();
jButton7 = new javax.swing.JButton();
jButton8 = new javax.swing.JButton();
jButton9 = new javax.swing.JButton();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jButton10 = new javax.swing.JButton();
jButton11 = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOƒE);

jPanel1.setFocusTraversalPolicyProvider(true);

jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
V  P a g e

jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});

jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});

jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});

jButton5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton5ActionPerformed(evt);
}
});

jButton6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton6ActionPerformed(evt);
}
});

jButton7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton7ActionPerformed(evt);
}
});

jButton8.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton8ActionPerformed(evt);
}
});
Vm  P a g e

jButton9.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton9ActionPerformed(evt);
}
});

jTextField1.setBackground(new java.awt.Color(153, 204, 255));


jTextField1.setFont(new java.awt.Font("Euphemia", 1, 14));
jTextField1.setHorizontalAlignment(javax.swing.JTextField.CENTER);
jTextField1.setText("Tic Tac Toe Game");

javax.swing.GroupLayout jPanel1Layout = new


javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(

jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING
)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanel1Layout.createƒequentialGroup()
.addContainerGap()

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignme
nt.TRAILING)
.addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_ƒIZE,
262, ƒhort.MAX_VALUE)
.addGroup(jPanel1Layout.createƒequentialGroup()

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignme
nt.TRAILING)
.addComponent(jButton7,
javax.swing.GroupLayout.DEFAULT_ƒIZE, 85, ƒhort.MAX_VALUE)
.addComponent(jButton4,
javax.swing.GroupLayout.DEFAULT_ƒIZE, 85, ƒhort.MAX_VALUE)
.addComponent(jButton1,
javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_ƒIZE, 85, ƒhort.MAX_VALUE))

.addPreferredGap(javax.swing.Layoutƒtyle.ComponentPlacement.RELATED)
V  P a g e

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignme
nt.TRAILING)
.addComponent(jButton8,
javax.swing.GroupLayout.DEFAULT_ƒIZE, 83, ƒhort.MAX_VALUE)
.addComponent(jButton2,
javax.swing.GroupLayout.DEFAULT_ƒIZE, 83, ƒhort.MAX_VALUE)
.addComponent(jButton5,
javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_ƒIZE, 83, ƒhort.MAX_VALUE))

.addPreferredGap(javax.swing.Layoutƒtyle.ComponentPlacement.RELATED)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignme
nt.LEADING)
.addComponent(jButton3,
javax.swing.GroupLayout.DEFAULT_ƒIZE, 82, ƒhort.MAX_VALUE)
.addComponent(jButton6,
javax.swing.GroupLayout.DEFAULT_ƒIZE, 82, ƒhort.MAX_VALUE)
.addComponent(jButton9,
javax.swing.GroupLayout.Alignment.TRAILING,
javax.swing.GroupLayout.DEFAULT_ƒIZE, 82, ƒhort.MAX_VALUE))))
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(

jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING
)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanel1Layout.createƒequentialGroup()
.addContainerGap()
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_ƒIZE,
javax.swing.GroupLayout.DEFAULT_ƒIZE,
javax.swing.GroupLayout.PREFERRED_ƒIZE)
.addGap(18, 18, 18)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignme
nt.LEADING, false)
.addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_ƒIZE,
47, ƒhort.MAX_VALUE)
V-  P a g e

.addComponent(jButton2, javax.swing.GroupLayout.DEFA ULT_ƒIZE,


47, ƒhort.MAX_VALUE)
.addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_ƒIZE,
javax.swing.GroupLayout.DEFAULT_ƒIZE, ƒhort.MAX_VALUE))

.addPreferredGap(javax.swing.Layoutƒtyle.ComponentPlacement.RELATED)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignme
nt.LEADING)
.addGroup(jPanel1Layout.createƒequentialGroup()

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLa yout.Alignme
nt.BAƒELINE)
.addComponent(jButton4,
javax.swing.GroupLayout.PREFERRED_ƒIZE, 49,
javax.swing.GroupLayout.PREFERRED_ƒIZE)
.addComponent(jButton5,
javax.swing.GroupLayout.PREFERRED_ƒIZE, 49,
javax.swing.GroupLayout.PREFERRED_ƒIZE))
.addGap(6, 6, 6))
.addGroup(jPanel1Layout.createƒequentialGroup()
.addComponent(jButton6, javax.swing.GroupLayout.DEFAULT_ƒIZE,
49, ƒhort.MAX_VALUE)

.addPreferredGap(javax.swing.Layoutƒtyle.ComponentPlacement.RELATED)))

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignme
nt.TRAILING)
.addComponent(jButton9,
javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_ƒIZE, 44, ƒhort.MAX_VALUE)
.addComponent(jButton8,
javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_ƒIZE, 44, ƒhort.MAX_VALUE)
.addComponent(jButton7,
javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_ƒIZE, 44, ƒhort.MAX_VALUE))
.addContainerGap())
);
V›  P a g e

jTextField2.setFont(new java.awt.Font("Gulim", 1, 12));


jTextField2.setHorizontalAlignment(javax.swing.JTextField.CENTER);
jTextField2.setText("X - player turn ");
jTextField2.setCaretColor(new java.awt.Color(255, 0, 0));

jButton10.setFont(new java.awt.Font("Calisto MT", 1, 14));


jButton10.setText("New Game");
jButton10.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton10ActionPerformed(evt);
}
});

jButton11.setFont(new java.awt.Font("Calisto MT", 1, 14));


jButton11.setText("Exit");
jButton11.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton11ActionPerformed(evt);
}
});

javax.swing.GroupLayout layout = new


javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createƒequentialGroup()
.addGap(31, 31, 31)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEAD
ING)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_ƒIZE,
javax.swing.GroupLayout.DEFAULT_ƒIZE,
javax.swing.GroupLayout.PREFERRED_ƒIZE)
.addGroup(layout.createƒequentialGroup()
.addGap(10, 10, 10)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEAD
ING, false)
u$  P a g e

.addComponent(jTextField2,
javax.swing.GroupLayout.PREFERRED_ƒIZE, 261,
javax.swing.GroupLayout.PREFERRED_ƒIZE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createƒequentialGroup()
.addComponent(jButton10)

.addPreferredGap(javax.swing.Layoutƒtyle.ComponentPlacement.RELATED,
javax.swing.GroupLayout.DEFAULT_ƒIZE, ƒhort.MAX_VALUE)
.addComponent(jButton11,
javax.swing.GroupLayout.PREFERRED_ƒIZE, 105,
javax.swing.GroupLayout.PREFERRED_ƒIZE)))))
.addGap(35, 35, 35))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createƒequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_ƒIZE,
javax.swing.GroupLayout.DEFAULT_ƒIZE,
javax.swing.GroupLayout.PREFERRED_ƒIZE)

.addPreferredGap(javax.swing.Layoutƒtyle.ComponentPlacement.RELATED)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_ƒIZE,
javax.swing.GroupLayout.DEFAULT_ƒIZE,
javax.swing.GroupLayout.PREFERRED_ƒIZE)

.addPreferredGap(javax.swing.Layoutƒtyle.ComponentPlacement.RELATED)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BAƒE
LINE)
.addComponent(jButton10,
javax.swing.GroupLayout.PREFERRED_ƒIZE, 27,
javax.swing.GroupLayout.PREFERRED_ƒIZE)
.addComponent(jButton11,
javax.swing.GroupLayout.PREFERRED_ƒIZE, 25,
javax.swing.GroupLayout.PREFERRED_ƒIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_ƒIZE,
ƒhort.MAX_VALUE))
);
u  P a g e

pack();
}// </editor-fold>

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {


// call the play method from TicTacToe by using game object.
game.play (0,0);// position (0,0) is jbutton1 location.
//call the possition() method from TicTacToe by using game object.
game.possition();

// test if the poition is not used before and no winner to diplay the player
charachter.
if (jButton1.getText().equals("")&&
(!jTextField2.getText().equals(" player " +game.getPlayer()+ " is the
winner")))

{
jButton1.setText(game.getPlayer()+"");// Dissplay in button 1 the current
player.
// test for the winner
if (game.checkWin())
jTextField2.setText(" player " +game.getPlayer()+ " is the winner");

// test if there is no winner and the game should continue


if(game.noWinner())
{
// call the switchPlayer method from TicTacToe class to switch the player
game.switchPlayer();
// display the player turn.
jTextField2.setText(game.getPlayer()+"- player turn");

// test the game is Tie so message will be displayed.


if (game.checkEquals())
jTextField2.setText(" TIE GAME ");

}
}
// mean the place is used before or there is a winner.
else
JOptionPane.showMessageDialog(null, "Error ");
uV  P a g e

// TODO add your handling code here:


}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {

// call the play method from TicTacToe by using game object.


game.play (0,1);// position (0,1) is jbutton2 location.
//call the possition() method from TicTacToe by using game object.
game.possition();
// test if the the poition is not used before and no winner to diplay the
player charachter.
if (jButton2.getText().equals("")&&
(!jTextField2.getText().equals(" player " +game.getPlayer()+ " is the
winner")))

{
jButton2.setText(game.getPlayer()+"");// Dissplay in button 2 the current
player.
// test for the winner
if (game.checkWin())
jTextField2.setText(" player " +game.getPlayer()+ " is the winner");

// test if there is no winner and the game should continue


if(game.noWinner())
{
// call the switchPlayer method from TicTacToe class to switch the player
game.switchPlayer();
// display the player turn.
jTextField2.setText(game.getPlayer()+"- player turn");

// test the game is Tie so message will be displayed.


if (game.checkEquals())
jTextField2.setText(" TIE GAME ");
if (game.checkWin())
jTextField2.setText(" player " +game.getPlayer()+ " is the winner");
}
}
uu  P a g e

// mean the place is used before or there is a winner.


else
JOptionPane.showMessageDialog(null, "Error ");

// TODO add your handling code here:


}

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {


// call the play method from TicTacToe by using game object.
game.play (0,2);// position (0,2) is jbutto3 location.
//call the possition() method from TicTacToe by using game object.
game.possition();
// test if the the poition is not used before and no winner to diplay the
player charachter.
if (jButton3.getText().equals("")&&
(!jTextField2.getText().equals(" player " +game.getPlayer()+ " is the
winner")))

{
jButton3.setText(game.getPlayer()+"");// Dissplay in button 3 the current
player.
// test for the winner
if (game.checkWin())
jTextField2.setText(" player " +game.getPlayer()+ " is the winner");

// test if there is no winner and the game should continue


if(game.noWinner())
{
// call the switchPlayer method from TicTacToe class to switch the player
game.switchPlayer();
// display the player turn.
jTextField2.setText(game.getPlayer()+"- player turn");

// test the game is Tie so message will be displayed.


if (game.checkEquals())
jTextField2.setText(" TIE GAME ");
if (game.checkWin())
jTextField2.setText(" player " +game.getPlayer()+ " is the winner");
}
uÿ  P a g e

}
// mean the place is used before or there is a winner.
else
JOptionPane.showMessageDialog(null, "Error ");

// TODO add your handling code here:


}

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {


// call the play method from TicTacToe by using game object.
game.play (1,0);// position (1,0) is jbutto4 location.
//call the possition() method from TicTacToe by using game object.
game.possition();
// test if the the poition is not used before and no winner to diplay the
player charachter.
if (jButton4.getText().equals("")&&
(!jTextField2.getText().equals(" player " +game.getPlayer()+ " is the
winner")))

{
jButton4.setText(game.getPlayer()+"");// Dissplay in button 4 the current
player.
// test for the winner
if (game.checkWin())
jTextField2.setText(" player " +game.getPlayer()+ " is the winner");

// test if there is no winner and the game should continue


if(game.noWinner())
{
// call the switchPlayer method from TicTacToe class to switch the player
game.switchPlayer();
// display the player turn.
jTextField2.setText(game.getPlayer()+"- player turn");

// test the game is Tie so message will be displayed.


if (game.checkEquals())
jTextField2.setText(" TIE GAME ");
if (game.checkWin())
u  P a g e

jTextField2.setText(" player " +game.getPlayer()+ " is the winner");


}
}
// mean the place is used before or there is a winner.
else
JOptionPane.showMessageDialog(null, "Error ");

// TODO add your handling code here:


}

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {


// call the play method from TicTacToe by using game ob ject.
game.play (1,1);// position (1,1) is jbutton5 location.
//call the possition() method from TicTacToe by using game object.
game.possition();
// test if the the poition is not used before and no winner to diplay the player
charachter.
if (jButton5.getText().equals("")&&
(!jTextField2.getText().equals(" player " +game.getPlayer()+ " is the
winner")))

{
jButton5.setText(game.getPlayer()+"");// Dissplay in button 5 the current
player. // test for the winner
if (game.checkWin())
jTextField2.setText(" player " +game.getPlayer()+ " is the winner");

// test if there is no winner and the game should continue


if(game.noWinner())
{
// call the switchPlayer method from TicTacToe class to switch the player
game.switchPlayer();
// display the player turn.
jTextField2.setText(game.getPlayer()+"- player turn");

// test the game is Tie so message will be displayed.


if (game.checkEquals())
um  P a g e

jTextField2.setText(" TIE GAME ");


if (game.checkWin())
jTextField2.setText(" player " +game.getPlayer()+ " is the winner");
}
}
// mean the place is used before or there is a winner.
else
JOptionPane.showMessageDialog(null, "Error ");

// TODO add your handling code here:


}

private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {


// call the play method from TicTacToe by using game object.
game.play (1,2);// position (1,2) is jbutton6 location.
//call the possition() method from TicTacToe by using game object.
game.possition();
// test if the the poition is not used before and no winner to diplay the
player charachter.
if (jButton6.getText().equals("")&&
(!jTextField2.getText().equals(" player " +game.getPlayer()+ " is the
winner")))

{
jButton6.setText(game.getPlayer()+"");// Dissplay in button 6 the current
player.
// test for the winner
if (game.checkWin())
jTextField2.setText(" player " +game.getPlayer()+ " is the winner");

// test if there is no winner and the game should continue


if(game.noWinner())
{
// call the switchPlayer method from TicTacToe class to switch the player
game.switchPlayer();
// display the player turn.
jTextField2.setText(game.getPlayer()+"- player turn");

// test the game is Tie so message will be displayed.


u  P a g e

if (game.checkEquals())
jTextField2.setText(" TIE GAME ");
if (game.checkWin())
jTextField2.setText(" player " +game.getPlayer()+ " is the winner ");
}
}
// mean the place is used before or there is a winner.
else
JOptionPane.showMessageDialog(null, "Error ");

// TODO add your handling code here:


}

private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {


// call the play method from TicTacToe by using game object.
game.play (2,0);// position (2,0) is jbutton7 location.
//call the possition() method from TicTacToe by using game object.
game.possition();
// test if the the poition is not used before and no winner to diplay the
player charachter.
if (jButton7.getText().equals("")&&
(!jTextField2.getText().equals(" player " +game.getPlayer()+ " is the
winner")))

{
jButton7.setText(game.getPlayer()+"");// Dissplay in button 7 the current
player.
// test for the winner
if (game.checkWin())
jTextField2.setText(" player " +game.getPlayer()+ " is the winner");

// test if there is no winner and the game should continue


if(game.noWinner())
{
// call the switchPlayer method from TicTacToe class to switch the p layer
game.switchPlayer();
// display the player turn.
jTextField2.setText(game.getPlayer()+"- player turn");

// test the game is Tie so message will be displayed.


u-  P a g e

if (game.checkEquals())
jTextField2.setText(" TIE GAME ");
if (game.checkWin())
jTextField2.setText(" player " +game.getPlayer()+ " is the winner");
}
}
// mean the place is used before or there is a winner.
else
JOptionPane.showMessageDialog(null, "Error ");

// TODO add your handling code here:


}

private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {


// call the play method from TicTacToe by using game object.
game.play (2,1);// position (2,1) is jbutton8 location.
//call the possition() method from TicTacToe by using game object.
game.possition();
// test if the the poition is not used before and no winner to diplay the
player charachter.
if (jButton8.getText().equals("")&&
(!jTextField2.getText().equals(" player " +game.getPlayer()+ " is the
winner")))

{
jButton8.setText(game.getPlayer()+"");// Dissplay in button 8 the current
player.
// test for the winner
if (game.checkWin())
jTextField2.setText(" player " +game.getPlayer()+ " is the winner");

// test if there is no winner and the game should continue


if(game.noWinner())
{
// call the switchPlayer method from TicTacToe class to switch the player
game.switchPlayer();
// display the player turn.
jTextField2.setText(game.getPlayer()+"- player turn");

// test the game is Tie so message will be displayed.


u›  P a g e

if (game.checkEquals())
jTextField2.setText(" TIE GAME ");
if (game.checkWin())
jTextField2.setText(" player " +game.getPlayer()+ " is the winner");
}
}
// mean the place is used before or there is a winner.
else
JOptionPane.showMessageDialog(null, "Error ");

private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {

// call the play method from TicTacToe by using game object.


game.play (2,2);// position (2,2) is jbutton 9 location.
//call the possition() method from TicTacToe by using game object.
game.possition();
// test if the the poition is not used before and no winner to diplay the
player charachter.
if (jButton9.getText().equals("")&&
(!jTextField2.getText().equals(" player " +game.getPlayer()+ " is the
winner")))

{
jButton9.setText(game.getPlayer()+"");// Dissplay in button 9 the current
player.
// test for the winner
if (game.checkWin())
jTextField2.setText(" player " +game.getPlayer()+ " is the winner");

// test if there is no winner and the game should continue


if(game.noWinner())
{
// call the switchPlayer method from TicTacToe class to switch the player
game.switchPlayer();
// display the player turn.
jTextField2.setText(game.getPlayer()+"- player turn");
ÿ$  P a g e

// test the game is Tie so message will be displayed.


if (game.checkEquals())
jTextField2.setText(" TIE GAME ");
if (game.checkWin())
jTextField2.setText(" player " +game.getPlayer()+ " is the winner");
}
}
// mean the place is used before or there is a winner.
else
JOptionPane.showMessageDialog(null, "Error ");

// TODO add your handling code here:


}

private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {


game.newGame();
jTextField2.setText(game.getPlayer()+" - player turn");
for(int i=0;i<=2;i++)
{
for(int j=0;j<=2;j++)
board[i][j].setText("");
}

// TODO add your handling code here:


}

private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {

setVisible(false);
// TODO add your handling code here:
}

public static void main(ƒtring args[]) {


java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new JTic().setVisible(true);
}

});
ÿ  P a g e

// Variables declaration - do not modify


private javax.swing.JButton jButton1;
private javax.swing.JButton jButton10;
private javax.swing.JButton jButton11;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JButton jButton5;
private javax.swing.JButton jButton6;
private javax.swing.JButton jButton7;
private javax.swing.JButton jButton8;
private javax.swing.JButton jButton9;
private javax.swing.JPanel jPanel1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
// End of variables declaration

}
ÿV  P a g e

   )  

 

1. I want to test if the program displays the state of the board correctly after
each player and switch the player's turn. ƒo I run the program and chose a
position first and then I enter the row and column number. Then make
sure the program out put the character (X or O) in the position desired.

2. I want to make sure that the game switch the player's turn. After each
player try. Again I play the game and enter deferent positions and in each
time the player characters were sapping between X and O.
ÿu  P a g e

3. I want to test if the program show's up an error message and ask the user
to chose other position if the player chooses a filled position, and don't
when the player choose valid one. ƒo, I run the program and entered a
position. in the second player turn I entered the same position and the
error message shows up and ask me to enter a new row and a new
column. ƒo, I choose a empty cell and its valid without error message.

4. I want to examination if there is a winner in all case the program will


output a message to show the winner player. accordingly I play the game
many times and in each time I win in different way. In each time I win the
message appears in a successful way.

5. I want to check if the game is end without a winner then the program will
display a message to show that game is end with Tie. thus I play the game
again but in this time I try to fill all the cells without a winner. After filling
the last position the message appears with Tie game.
ÿÿ  P a g e

6. I want to test after the message for tie game or a winner the program will
ask the user if he /she want to play a new game. ƒo I play the game twice.
in the first time I win and in the second time I end the game with tie and in
both case the program ask me if I want to play a new game.

7. After asking the user if he/she want to play a new game. I want to
examination the program if the answer is yes it works correctly and if the
answer was no thanks message display and if any other answer and error
message shows. Therefore, after I win in the game the program ask me if I
want to play a new game so my answer was '' I don͛t know " error message
appears then it ask the same question again hence I play the game again.
In this time when I win and the question appears again my answer is no,
the thanks message appears and the game closed.
ÿ  P a g e
ÿm  P a g e

 V

1. I want to test if the program display user interface game board with 9
empty buttons , one long white box to show the players turns and the
game states , New game button and Exit button. ƒo I run the file and it
shows me 9 empty cells, the while box and it shows X-player turn and the
2 buttons.

2. I want to test if the X-player click in a button then X appears in that button
and when O-player click in a button then O appears in that button .
Therefore, I look at the player turn in the white box then I click in any
button and check if it display the same character.
ÿ  P a g e

3. I want to check after each click on a button the player turn change. ƒo I run
the file and I notice the player turn in a white box then after each time I
click in a button the player turn change directly.

4. I want to examination if there is a winner in all case the n the program will
output the winner player in the white box. accordingly I play the game
many times and in each time I win in different way. In each time I win the
winner player in the white box appears.
ÿ-  P a g e

5. I want to check if the game is end without a winner then the program will
display Tie game in white box. so I play the game again but in this time I
try to click on all buttons without a winner. After clicking on all buttons Tie
game display in the white box.

6. I want to test if the program gives error message if the user clicked on a
used button. ƒo I clicked the same button twice then error messa ge
display.

7. I want to test after tie game or a winner the program gives error message
if the user clicked on a button. Therefore , after a winner condition, I
clicked on a empty button and an error message displayed .
ÿ›  P a g e

8. I want to exanimate the new game button. accordingly I play a game then I
clicked on a new game and it clears all the buttons to start a new game.

9. Finally I want to test the exit button so I clicked on it and the game board
disappeared .
$  P a g e

  

In the end all the objectives of this program are verified. This program can be
improved in many different ways. This program let me to think in creative way
and like to learn more about programming and know that course ECE202 is never
enough. I wish if I could add some effects like sounds or motions when the
winner message or the tie message appears.

Вам также может понравиться