Sunteți pe pagina 1din 22

A Project Report On

Tic TAC toe game

Submitted By
RUPESH KUMAR PANDEY
Class: XII B
Under the Guidance of
Mrs. Anshu Rani
PGT (Computer Science)
Department of Computer Science
Kendriya Vidyalaya Air Force Station
Bidar, KARNATAKA.

Department of Computer Science


Kendriya Vidyalaya Air Force Station
Bidar, KARNATAKA.

This is to certify that RUPESH KUMAR PANDEY


Of Class XII B has prepared the report on the Project entitled
Tic Tac Toe game. The report is the result of his efforts &
endeavors. The report is found worthy of acceptance as final
project report for the subject Computer Science of Class XII. He
has prepared the report under my guidance.

(Mrs. Anshu Rani)


PGT (Computer Science)
Department of Computer Science
Kendriya Vidyalaya AFS BIDAR.

Department of Computer Science


Kendriya Vidyalaya AFS Bidar.

CERTIFICAT
E
The project report entitled
Tic Tac Toe game,

Submitted by RUPESH KUMAR PANDEY of Class


XII B for the CBSE Senior Secondary Examination class
XII of Computer Science at Kendriya Vidyalaya AFS
Bidar has been examined.

SIGNATURE OF EXAMINER

D E C LAR AT I O N
I hereby declare that the project work entitled
TIC TAC TOE GAME, submitted to
Department of Computer Science, Kendriya
Vidyalaya AFS Bidar Karnataka is prepared by
me. All the coding is result of my personal
efforts.

RUPESH KUMAR
PANDEY
Class XII B

ACKNOWLEDGEMENT
I would like to express a deep sense of thanks & gratitude to my
project guide Mrs.Anshu Rani for guiding me immensely through the
course of the project. She always evinced keen interest in my work. His
constructive advice & constant motivation have been responsible for the
successful completion of this project.
My sincere thanks goes to Shri Krishna Kumar K.K, Our principal
sir, for his co-ordination in extending every possible support for the
completion of this project.
I also thanks to my parents for their motivation & support. I must
thanks to my classmates for their timely help & support for compilation
of this project.
Last but not the least, I would like to thank all those who had
helped directly or indirectly towards the completion of this project.

RUPESH KUMAR PANDEY


Class: XII B

CONTENTS

1. HEADER FILES USED. . . . . . . . . . . . . . . . .

2. WORKING DESCRIPTION. . . . . . . . . . . . .

3. CODING . . . . . . . . . .. . . . . . . . . . . . . . . .
4. OUTPUT SCREENS. . . . . . . . . . . . . . . . . . .
....
5. BIBLIOGRAPHY. . . . . . . . . . . . . . . . . . . . .

....

HEADER FILES USED


1.FSTREAM.H for file handling, cin and cout

2. PROCESS.H for exit() function


3. CONIO.H for clrscr() and
getch() functions
4. STDIO.H for standard I/O operations
5. STRING.H for string handling
6. MATH.Hfor
operations

doing

mathematical

WORKING DESCRIPTION

This program is based on the simple logic game


named Tic Tac Toe(X and O)
This program consists of two players who can
play the game
1.
2.

PLAYER ONE IS ASSIGNED X


PLAYER TWO IS ASSIGNED O

3.

EACH PLAYER HAS TO ENTER


NUMBER APPEARING IN TABLE
AND
GET
THEIR
SYMBOL
ALLIGNED ALL IN ROW OR
COLOUMN OF ANY OF THE
DIAGONAL.

4.

ONE WHO DOES THE ABOVE


MENTIONED WINS THE GAME.

CODING
#include <fstream.h>
#include <conio.h>
#include<process.h>
#include<math.h>
#include<stdio.h>
#include<stdlib.h>
char square[10] = {'o','1','2','3','4','5','6','7','8','9'};
int checkwin();
void board();
int main()
{
int player = 1,i,choice;
char mark;
clrscr();
do
{
board();
player=(player%2)?1:2;
cout << "Player " << player << ", enter a
number: ";
cin >> choice;
mark=(player == 1) ? 'X' : 'O';
if (choice == 1 && square[1] == '1')
square[1] = mark;
else if (choice == 2 && square[2] == '2')
square[2] = mark;
else if (choice == 3 && square[3] == '3')

else
else
else
else
else
else
else
{

";

square[3] = mark;
if (choice == 4 && square[4]
square[4] = mark;
if (choice == 5 && square[5]
square[5] = mark;
if (choice == 6 && square[6]
square[6] = mark;
if (choice == 7 && square[7]
square[7] = mark;
if (choice == 8 && square[8]
square[8] = mark;
if (choice == 9 && square[9]
square[9] = mark;

== '4')
== '5')
== '6')
== '7')
== '8')
== '9')

cout<<"Invalid move ";


player--;
getch();

}
i=checkwin();
player++;
}while(i==-1);
board();
if(i==1)
cout<<"==>\aPlayer "<<--player<<" win
else

cout<<"==>\aGame draw";
getch();
return 0;
}

/*********************************************
FUNCTION TO RETURN GAME STATUS
1 FOR GAME IS OVER WITH RESULT
-1 FOR GAME IS IN PROGRESS
O GAME IS OVER AND NO RESULT
**********************************************/
int checkwin()
{
if (square[1] == square[2] && square[2] ==
square[3])
return 1;
else if (square[4] == square[5] && square[5]
== square[6])
return 1;
else if (square[7] == square[8] && square[8]
== square[9])
return 1;
else if (square[1] == square[4] && square[4]
== square[7])
return 1;
else if (square[2] == square[5] && square[5]
== square[8])
return 1;
else if (square[3] == square[6] && square[6]
== square[9])
return 1;
else if (square[1] == square[5] && square[5]
== square[9])
return 1;
else if (square[3] == square[5] && square[5]
== square[7])

return 1;
else if (square[1] != '1' && square[2] != '2' &&
square[3] != '3' &&
square[4] != '4' && square[5] != '5' &&
square[6] != '6' &&
square[7] != '7' && square[8] != '8' &&
square[9] != '9')
return 0;
else
return -1;
}

/
*******************************************************
************
FUNCTION TO DRAW BOARD OF TIC TAC TOE
WITH PLAYERS MARK
*******************************************************
*************/

void board()
{
clrscr();
cout <<
cout <<
<< endl;
cout <<
cout <<

"\n\n\tTic Tac Toe\n\n";


"Player 1 (X) - Player 2 (O)" << endl
endl;
"
|

" << endl;

cout << " " << square[1] << " | " <<
square[2] << " | " << square[3] << endl;
cout << "_____|_____|_____" << endl;
cout << "
|
|
" << endl;
cout << " " << square[4] << " | " <<
square[5] << " | " << square[6] << endl;
cout << "_____|_____|_____" << endl;
cout << "
|
|
" << endl;
cout << " " << square[7] << " | " <<
square[8] << " | " << square[9] << endl;
cout << "
|
|
" << endl << endl;
}
/
*******************************************************
************
END OF PROJECT
*******************************************************
*************/

OUTPUT
SCREEN
1) PLAYER 1 ENTER
A NUMBER.

2)PLAYER 1 ENTERS
1
3)PLAYER 2 ENTER A
NUMBER

4)PLAYER 2 ENTERS
6
5)PLAYER 1 ENTER A
NUMBER

6)PLAYER 1 ENTERS
2
7)PLAYER 2 ENTER A
NUMBER

8)PLAYER 2 ENTERS
8
9)PLAYER 1 ENTER A
NUMBER

10)PLAYER 1
ENTERS 3
11)PLAYER 1 WINS
THE GAME

BIBLIOGRAP
HY
1)SL ARORA TEXT.
2)SEEMA
BHATNAGARS
BOOK
3)WWW.CPPSCHO

OL.COM
4)WWW.ICBSE.CO
M

S-ar putea să vă placă și