Add to Favorites    Make Home Page 1936 Online  
 Language Categories  
 Our Services  

Home » C Home » Games and Graphics Home » Tic Tac Toe Game

A D V E R T I S E M E N T

Search Projects & Source Codes:

Title Tic Tac Toe Game
Author Yashodhan Bhave
Author Email yashodhan_bhave [at] rediffmail.com
Description This is the basic tic tac toe game
(also known as 0 X) played by two persons...
Created by using graphics & Simple logic behind the game,Both user can
play using the same keyboard,Some enhancement would result it to get
compatibiliy with two nodes
Category C » Games and Graphics
Hits 382794
Code Select and Copy the Code
:/* Tic Tac Toe */ #include<graphics.h> #include<iostream.h> #include <conio.h> void main() { start: int a[3][3]={5,6,7,8,9,10,11,12,13},i,j,k,x,y,t,cn=0,co=0; char c; static int nod=0,nn=0,sc[2]={0,0}; nod++; clrscr(); int driver=DETECT,mode; initgraph(&driver,&mode,"c:\tc\bgi"); setbkcolor(RED); line(100,200,400,200); line(100,300,400,300); line(200,100,200,400); line(300,100,300,400); gotoxy(20,2); cout<<"TIC TAC TOE"; gotoxy(20,3); cout<<"Unregistered Vesion 1.0"; gotoxy(10,5);cout<<" BOX NO "; gotoxy(15,7);cout<<"0"; gotoxy(30,7);cout<<"1"; gotoxy(45,7);cout<<"2"; gotoxy(15,14);cout<<"3"; gotoxy(30,14);cout<<"4"; gotoxy(45,14);cout<<"5"; gotoxy(15,21);cout<<"6"; gotoxy(30,21);cout<<"7"; gotoxy(45,21);cout<<"8"; gotoxy(55,22);cout<<"RESULT"; gotoxy(55,23);cout<<"*************************"; gotoxy(55,15);cout<<"P1-"<<sc[0]; gotoxy(55,16);cout<<"P2-"<<sc[1]; for(i=0;i<=2;i++) { for(j=0;j<=2;j++) { re:gotoxy(65,4); k=((i+j)%2+1); cout<<"Enter player"<<k; gotoxy(60,5); cout<<" Box no from 0 to 8 "; gotoxy(58,6);cout<<"[ ]"; gotoxy(60,6); t=getch(); t=t-48; if(t==0){x=0;y=0;goto play;} if(t==1){x=1;y=0;goto play;} if(t==2){x=2;y=0;goto play;} if(t==3){x=0;y=1;goto play;} if(t==4){x=1;y=1;goto play;} if(t==5){x=2;y=1;goto play;} if(t==6){x=0;y=2;goto play;} if(t==7){x=1;y=2;goto play;} if(t==8){x=2;y=2;goto play;} else {goto re ;} play: if((a[x][y]==1)||(a[x][y]==2)) {goto re;} if((a[x][y]!=1)&&(a[x][y]!=2)) { if(k==1) {circle(100*x+100+50,100*y+100+50,50); a[x][y]=k;co++;} if(k==2) {line(x*100+100,y*100+100,x*100+200,y*100+200); line(x*100+100,y*100+200,x*100+200,y*100+100); a[x][y]=k;co++;} } gotoxy(60,23); if((a[0][0]==a[1][0])&&(a[1][0]==a[2][0])) {cout<<"Player "<<k<<" wins";cn=1;sc[k-1]++;} if((a[0][0]==a[0][1])&&(a[0][1]==a[0][2])) {cout<<"Player "<<k<<" wins";cn=1;sc[k-1]++;} if((a[0][0]==a[1][1])&&(a[1][1]==a[2][2])) {cout<<"Player "<<k<<" wins";cn=1;sc[k-1]++;} if((a[1][0]==a[1][1])&&(a[1][1]==a[1][2])) {cout<<"Player "<<k<<" wins";cn=1;sc[k-1]++;} if((a[2][0]==a[2][1])&&(a[2][1]==a[2][2])) {cout<<"Player "<<k<<" wins";cn=1;sc[k-1]++;} if((a[2][0]==a[1][1])&&(a[1][1]==a[0][2])) {cout<<"Player "<<k<<" wins";cn=1;sc[k-1]++;} if((a[0][2]==a[1][2])&&(a[1][2]==a[2][2])) {cout<<"Player "<<k<<" wins";cn=1;sc[k-1]++;} if((a[0][1]==a[1][1])&&(a[1][1]==a[2][1])) {cout<<"Player "<<k<<" wins";cn=1;sc[k-1]++;} if(cn==1) {goto que;} if(co==9) {gotoxy(62,23); cout<<"DRAW"; nn++; goto que;} } } que: gotoxy(60,24); cout<<"Play again y/n"; c=getch(); if((c=='y')||(c=='Y')) { goto start;} else if((c=='n')||(c=='N')) {goto end;} else goto que; end: closegraph(); cout<<"Final score is "<<sc[k-1]<<"-"<<nod-nn-sc[k-1]; gotoxy(20,10); cout<<"Thanks for playing this game"; gotoxy(20,12); cout<<"Contact (+91)-9890427816"; gotoxy(20,14); cout<<"Mail to [email protected]"; getch(); }

Related Source Codes

Script Name Author
The Game Opposite as seen on Nokia 2300 Mobile Manikanta
RECURSIVE BALANCED QUICK SORT ashish
Radix Sort ashish
Change your mouse pointer Ashim
The blinking star Shashank
Data Validation Crylittlebaby
To search a file by giving file type like mp3 or mpeg or doc Prashanth SR
Menus Demonstration B.Chidhambaram
Employee Database Project Using C. Reenku Raman Nayak
Creating a Lexical Analyzer in c fahad bader al-buhairi �դ ?�� ��??���
Calendar Program Omkar & Devendra
Stop double Process for start in C Cedrik Jurak
Stop double Process for start in C Cedrik Jurak
Time Scheduler Atiq Anwar
A timepass game between atmost two players Rahul Roy

A D V E R T I S E M E N T




Google Groups Subscribe to SourceCodesWorld - Techies Talk
Email:

Free eBook - Interview Questions: Get over 1,000 Interview Questions in an eBook for free when you join JobsAssist. Just click on the button below to join JobsAssist and you will immediately receive the Free eBook with thousands of Interview Questions in an ebook when you join.

New! Click here to Add your Code!


ASP Home | C Home | C++ Home | COBOL Home | Java Home | Pascal Home
Source Codes Home Page

 Advertisements  

Google Search

Google

Source Codes World.com is a part of Vyom Network.

Vyom Network : Web Hosting | Dedicated Server | Free SMS, GRE, GMAT, MBA | Online Exams | Freshers Jobs | Software Downloads | Interview Questions | Jobs, Discussions | Placement Papers | Free eBooks | Free eBooks | Free Business Info | Interview Questions | Free Tutorials | Arabic, French, German | IAS Preparation | Jokes, Songs, Fun | Free Classifieds | Free Recipes | Free Downloads | Bangalore Info | Tech Solutions | Project Outsourcing, Web Hosting | GATE Preparation | MBA Preparation | SAP Info | Software Testing | Google Logo Maker | Freshers Jobs

Sitemap | Privacy Policy | Terms and Conditions | Important Websites
Copyright ©2003-2024 SourceCodesWorld.com, All Rights Reserved.
Page URL: http://www.sourcecodesworld.com/source/show.asp?ScriptID=512


Download Yahoo Messenger | Placement Papers | Free SMS | C Interview Questions | C++ Interview Questions | Quick2Host Review