हेलो दोस्तों !
आज की इस Tic tac toe game project using graphics in C language in Hindi पोस्ट में हम tic tac toe game का project C language की मदद से graphics का यूज़ करके बनाना सीखेंगे। तो दोस्तों अगर आप graphics का use करके tic tac toe game का project C programming की मदद से बनाना सीखना चाहते है तो इस पोस्ट को अंत तक जरूर पढ़े।
इस पोस्ट के मुख्य टॉपिक्स निन्म है -
- tic tac toe game project overview.
- इस प्रोजेक्ट को बनाने के स्टेप्स।
- tic tac toe game project source code.
- project explanation वीडियो।
1.tic tac toe game project overview :-
- startGame function
- gameBody function
- checkGameResult function
main function :-
startGame function :-
drawGameBody function :-
checkGameResult function :-
2.इस प्रोजेक्ट को बनाने के स्टेप्स :-
step 1 :-
step 2 :-
step 3 :-
step 4 :-
step 5 :-
3.tic tac toe game project source code :-
project source code :-
#include< conio.h >
#include< graphics.h >
#include< stdio.h >
#include< dos.h >
int box1=1,box2=2,box3=3,box4=4,box5=5,box6=6,box7=7,box8=8,box9=9;
int count1=0,count2=0,count3=0,count4=0,count5=0;
int count6=0,count7=0,count8=0,count9=0;
int counta1=0,counta2=0,counta3=0,counta4=0,counta5=0;
int counta6=0,counta7=0,counta8=0,counta9=0;
int draw=0;
int win1=0,win2=0,win3=0,win4=0,win5=0,win6=0,win7=0,win8=0;
int win21=0,win22=0,win23=0,win24=0,win25=0,win26=0,win27=0,win28=0;
char temp[2];
void checkGameResult()
{
clrscr();
if(draw==9)
{
settextstyle(1,0,3);
outtextxy(230,200,"Game is draw");
}else if(win1==3)
{
settextstyle(1,0,3);
outtextxy(270,170,"Congrat's!");
outtextxy(180,200,"First Player win the game");
}else if(win21==3)
{
settextstyle(1,0,3);
outtextxy(270,170,"Congrat's!");
outtextxy(180,200,"Second Player win the game");
}else if(win2==3)
{
settextstyle(1,0,3);
outtextxy(270,170,"Congrat's!");
outtextxy(180,200,"First Player win the game");
}else if(win22==3)
{
settextstyle(1,0,3);
outtextxy(270,170,"Congrat's!");
outtextxy(180,200,"Second Player win the game");
}else if(win3==3)
{
settextstyle(1,0,3);
outtextxy(270,170,"Congrat's!");
outtextxy(180,200,"First Player win the game");
}else if(win23==3)
{
settextstyle(1,0,3);
outtextxy(270,170,"Congrat's!");
outtextxy(180,200,"Second Player win the game");
}else if(win4==3)
{
settextstyle(1,0,3);
outtextxy(270,170,"Congrat's!");
outtextxy(180,200,"First Player win the game");
}else if(win24==3)
{
settextstyle(1,0,3);
outtextxy(270,170,"Congrat's!");
outtextxy(180,200,"Second Player win the game");
}else if(win5==3)
{
settextstyle(1,0,3);
outtextxy(270,170,"Congrat's!");
outtextxy(180,200,"First Player win the game");
}else if(win25==3)
{
settextstyle(1,0,3);
outtextxy(270,170,"Congrat's!");
outtextxy(180,200,"Second Player win the game");
}else if(win6==3)
{
settextstyle(1,0,3);
outtextxy(270,170,"Congrat's!");
outtextxy(180,200,"First Player win the game");
}else if(win26==3)
{
settextstyle(1,0,3);
outtextxy(270,170,"Congrat's!");
outtextxy(180,200,"Second Player win the game");
}else if(win7==3)
{
settextstyle(1,0,3);
outtextxy(270,170,"Congrat's!");
outtextxy(180,200,"First Player win the game");
}else if(win27==3)
{
settextstyle(1,0,3);
outtextxy(270,170,"Congrat's!");
outtextxy(180,200,"Second Player win the game");
}else if(win8==3)
{
settextstyle(1,0,3);
outtextxy(270,170,"Congrat's!");
outtextxy(180,200,"First Player win the game");
}else if(win28==3)
{
settextstyle(1,0,3);
outtextxy(270,170,"Congrat's!");
outtextxy(180,200,"Second Player win the game");
}
}
void gameBody()
{
clrscr();
setcolor(9);
line(200,100,420,100);
line(200,160,420,160);
line(200,220,420,220);
line(200,280,420,280);
line(200,100,200,280);
line(270,100,270,280);
line(350,100,350,280);
line(420,100,420,280);
setcolor(4);
settextstyle(1,0,2);
if(count1==1)
{
box1=79;
outtextxy(450,180,"Press 0 to Exit");
sprintf(temp,"%c",box1);
outtextxy(235,125,temp);
}else if(counta1==1)
{
box1=88;
outtextxy(450,180,"Press 0 to Exit");
sprintf(temp,"%c",box1);
outtextxy(235,125,temp);
}else
{
outtextxy(450,180,"Press 0 to Exit");
sprintf(temp,"%d",box1);
outtextxy(235,125,temp);
}
if(count2==2)
{
box2=79;
outtextxy(450,180,"Press 0 to Exit");
sprintf(temp,"%c",box2);
outtextxy(305,125,temp);
}else if(counta2==2)
{
box2=88;
outtextxy(450,180,"Press 0 to Exit");
sprintf(temp,"%c",box2);
outtextxy(305,125,temp);
}else
{
outtextxy(450,180,"Press 0 to Exit");
sprintf(temp,"%d",box2);
outtextxy(305,125,temp);
}
if(count3==3)
{
box3=79;
outtextxy(450,180,"Press 0 to Exit");
sprintf(temp,"%c",box3);
outtextxy(375,125,temp);
}else if(counta3==3)
{
box3=88;
outtextxy(450,180,"Press 0 to Exit");
sprintf(temp,"%c",box3);
outtextxy(375,125,temp);
}else
{
outtextxy(450,180,"Press 0 to Exit");
sprintf(temp,"%d",box3);
outtextxy(375,125,temp);
}
if(count4==4)
{
box4=79;
outtextxy(450,180,"Press 0 to Exit");
sprintf(temp,"%c",box4);
outtextxy(235,185,temp);
}else if(counta4==4)
{
box4=88;
outtextxy(450,180,"Press 0 to Exit");
sprintf(temp,"%c",box4);
outtextxy(235,185,temp);
}else
{
outtextxy(450,180,"Press 0 to Exit");
sprintf(temp,"%d",box4);
outtextxy(235,185,temp);
}
if(count5==5)
{
box5=79;
outtextxy(450,180,"Press 0 to Exit");
sprintf(temp,"%c",box5);
outtextxy(305,185,temp);
}else if(counta5==5)
{
box5=88;
outtextxy(450,180,"Press 0 to Exit");
sprintf(temp,"%c",box5);
outtextxy(305,185,temp);
}else
{
outtextxy(450,180,"Press 0 to Exit");
sprintf(temp,"%d",box5);
outtextxy(305,185,temp);
}
if(count6==6)
{
box6=79;
outtextxy(450,180,"Press 0 to Exit");
sprintf(temp,"%c",box6);
outtextxy(375,185,temp);
}else if(counta6==6)
{
box6=88;
outtextxy(450,180,"Press 0 to Exit");
sprintf(temp,"%c",box6);
outtextxy(375,185,temp);
}else
{
outtextxy(450,180,"Press 0 to Exit");
sprintf(temp,"%d",box6);
outtextxy(375,185,temp);
}
if(count7==7)
{
box7=79;
outtextxy(450,180,"Press 0 to Exit");
sprintf(temp,"%c",box7);
outtextxy(235,245,temp);
}else if(counta7==7)
{
box7=88;
outtextxy(450,180,"Press 0 to Exit");
sprintf(temp,"%c",box7);
outtextxy(235,245,temp);
}else
{
outtextxy(450,180,"Press 0 to Exit");
sprintf(temp,"%d",box7);
outtextxy(235,245,temp);
}
if(count8==8)
{
box8=79;
outtextxy(450,180,"Press 0 to Exit");
sprintf(temp,"%c",box8);
outtextxy(305,245,temp);
}else if(counta8==8)
{
box8=88;
outtextxy(450,180,"Press 0 to Exit");
sprintf(temp,"%c",box8);
outtextxy(305,245,temp);
}else
{
outtextxy(450,180,"Press 0 to Exit");
sprintf(temp,"%d",box8);
outtextxy(305,245,temp);
}
if(count9==9)
{
box9=79;
outtextxy(450,180,"Press 0 to Exit");
sprintf(temp,"%c",box9);
outtextxy(375,245,temp);
}else if(counta9==9)
{
box9=88;
outtextxy(450,180,"Press 0 to Exit");
sprintf(temp,"%c",box9);
outtextxy(375,245,temp);
}else
{
outtextxy(450,180,"Press 0 to Exit");
sprintf(temp,"%d",box9);
outtextxy(375,245,temp);
}
}
int startGame(int check)
{
int position;
if(check==1)
{
there1:
gameBody();
outtextxy(220,300,"First player turn");
outtextxy(220,330,"Choose position");
if(!kbhit())
{
position=getch();
switch(position)
{
case '0':
return 1;
case '1':
box1=79;
sprintf(temp,"%c",box1);
outtextxy(235,125,temp);
if(counta1==0)
{
count1=1;
counta1=2;
draw++;
win1++;
win4++;
win7++;
}
if(draw==9)
{
return 1;
}else if(win1==3)
{
return 1;
}else if(win4==3)
{
return 1;
}else if(win7==3)
{
return 1;
}
goto there;
case '2':
box2=79;
sprintf(temp,"%c",box2);
outtextxy(305,125,temp);
if(counta2==0)
{
count2=2;
counta2=3;
draw++;
win1++;
win5++;
}
if(draw==9)
{
return 1;
}else if(win1==3)
{
return 1;
}else if(win5==3)
{
return 1;
}
goto there;
case '3':
box3=79;
sprintf(temp,"%c",box3);
outtextxy(375,125,temp);
if(counta3==0)
{
count3=3;
counta3=2;
draw++;
win1++;
win6++;
win8++;
}
if(draw==9)
{
return 1;
}else if(win1==3)
{
return 1;
}else if(win6==3)
{
return 1;
}else if(win8==3)
{
return 1;
}
goto there;
case '4':
box4=79;
sprintf(temp,"%c",box4);
outtextxy(235,185,temp);
if(counta4==0)
{
count4=4;
counta4=2;
draw++;
win2++;
win4++;
}
if(draw==9)
{
return 1;
}else if(win2==3)
{
return 1;
}else if(win4==3)
{
return 1;
}
goto there;
case '5':
box5=79;
sprintf(temp,"%c",box5);
outtextxy(305,185,temp);
if(counta5==0)
{
count5=5;
counta5=2;
draw++;
win2++;
win5++;
win7++;
win8++;
}
if(draw==9)
{
return 1;
}else if(win2==3)
{
return 1;
}else if(win5==3)
{
return 1;
}else if(win7==3)
{
return 1;
}else if(win8==3)
{
return 1;
}
goto there;
case '6':
box6=79;
sprintf(temp,"%c",box6);
outtextxy(375,185,temp);
if(counta6==0)
{
count6=6;
counta6=2;
draw++;
win2++;
win6++;
}
if(draw==9)
{
return 1;
}else if(win2==3)
{
return 1;
}else if(win6==3)
{
return 1;
}
goto there;
case '7':
box7=79;
sprintf(temp,"%c",box7);
outtextxy(235,245,temp);
if(counta7==0)
{
count7=7;
counta7=2;
draw++;
win3++;
win4++;
win8++;
}
if(draw==9)
{
return 1;
}else if(win3==3)
{
return 1;
}else if(win4==3)
{
return 1;
}else if(win8==3)
{
return 1;
}
goto there;
case '8':
box8=79;
sprintf(temp,"%c",box8);
outtextxy(305,245,temp);
if(counta8==0)
{
count8=8;
counta8=2;
draw++;
win3++;
win5++;
}
if(draw==9)
{
return 1;
}else if(win3==3)
{
return 1;
}else if(win5==3)
{
return 1;
}
goto there;
case '9':
box9=79;
sprintf(temp,"%c",box9);
outtextxy(375,245,temp);
if(counta9==0)
{
count9=9;
counta9=2;
draw++;
win3++;
win6++;
win7++;
}
if(draw==9)
{
return 1;
}else if(win3==3)
{
return 1;
}else if(win6==3)
{
return 1;
}else if(win7==3)
{
return 1;
}
goto there;
default:outtextxy(210,360,"Invalid position choose again");
goto there1;
}
}
}
if(check==2)
{
there:
gameBody();
outtextxy(220,300,"Second player turn");
outtextxy(220,330,"Choose position");
if(!kbhit())
{
position=getch();
switch(position)
{
case '0':
return 1;
case '1':
box1=88;
sprintf(temp,"%c",box1);
outtextxy(235,125,temp);
if(count1==0)
{
count1=2;
counta1=1;
draw++;
win21++;
win24++;
win27++;
}
if(draw==9)
{
return 1;
}else if(win21==3)
{
return 1;
}else if(win24==3)
{
return 1;
}else if(win27==3)
{
return 1;
}
goto there1;
case '2':
box2=88;
sprintf(temp,"%c",box2);
outtextxy(305,125,temp);
if(count2==0)
{
count2=3;
counta2=2;
draw++;
win21++;
win25++;
}
if(draw==9)
{
return 1;
}else if(win21==3)
{
return 1;
}else if(win25==3)
{
return 1;
}
goto there1;
case '3':
box3=88;
sprintf(temp,"%c",box3);
outtextxy(375,125,temp);
if(count3==0)
{
count3=2;
counta3=3;
draw++;
win21++;
win26++;
win28++;
}
if(draw==9)
{
return 1;
}else if(win21==3)
{
return 1;
}else if(win26==3)
{
return 1;
}else if(win28==3)
{
return 1;
}
goto there1;
case '4':
box4=88;
sprintf(temp,"%c",box4);
outtextxy(235,185,temp);
if(count4==0)
{
count4=2;
counta4=4;
draw++;
win22++;
win24++;
}
if(draw==9)
{
return 1;
}else if(win22==3)
{
return 1;
}else if(win24==3)
{
return 1;
}
goto there1;
case '5':
box5=88;
sprintf(temp,"%c",box5);
outtextxy(305,185,temp);
if(count5==0)
{
count5=2;
counta5=5;
draw++;
win22++;
win25++;
win27++;
win28++;
}
if(draw==9)
{
return 1;
}else if(win22==3)
{
return 1;
}else if(win25==3)
{
return 1;
}else if(win27==3)
{
return 1;
}else if(win28==3)
{
return 1;
}
goto there1;
case '6':
box6=88;
sprintf(temp,"%c",box6);
outtextxy(375,185,temp);
if(count6==0)
{
count6=2;
counta6=6;
draw++;
win22++;
win26++;
}
if(draw==9)
{
return 1;
}else if(win22==3)
{
return 1;
}else if(win26==3)
{
return 1;
}
goto there1;
case '7':
box7=88;
sprintf(temp,"%c",box7);
outtextxy(235,245,temp);
if(count7==0)
{
count7=2;
counta7=7;
draw++;
win23++;
win24++;
win28++;
}
if(draw==9)
{
return 1;
}else if(win23==3)
{
return 1;
}else if(win24==3)
{
return 1;
}else if(win28==3)
{
return 1;
}
goto there1;
case '8':
box8=88;
sprintf(temp,"%c",box8);
outtextxy(305,245,temp);
if(count8==0)
{
count8=2;
counta8=8;
draw++;
win23++;
win25++;
}
if(draw==9)
{
return 1;
}else if(win23==3)
{
return 1;
}else if(win25==3)
{
return 1;
}
goto there1;
case '9':
box9=88;
sprintf(temp,"%c",box9);
outtextxy(375,245,temp);
if(count9==0)
{
count9=2;
counta9=9;
draw++;
win23++;
win26++;
win27++;
}
if(draw==9)
{
return 1;
}else if(win23==3)
{
return 1;
}else if(win26==3)
{
return 1;
}else if(win27==3)
{
return 1;
}
goto there1;
default:outtextxy(210,360,"Invalid position choose again");
goto there;
}
}
}
return 2;
}
void main()
{
char check;
int gameComplete;
int graphicsDriver=DETECT,graphicsMode;
clrscr();
initgraph(&graphicsDriver,&graphicsMode,"");
settextstyle(1,0,1);
setcolor(4);
outtextxy(150,100,"WELCOME TO TIC TAC TOE GAME");
outtextxy(100,150,"First player sign O Second player sign X");
outtextxy(150,200,"Which player want to start game");
outtextxy(70,250,"Press 1 for first player Press 2 for second player");
there:
if(!kbhit())
{
check=getch();
if(check==49)
{
while(gameComplete!=1)
{
gameComplete=startGame(1);
delay(30);
}
checkGameResult();
}else if(check==50)
{
while(gameComplete!=1)
{
gameComplete=startGame(2);
delay(30);
}
checkGameResult();
}else
{
clrscr();
outtextxy(200,200,"Invalid press try again");
goto there;
}
}
getch();
closegraph();
}
project output :-
4.project explanation वीडियो :-
इन पोस्ट को भी पढ़े -
Author :- तो दोस्तों अब हमारी यह Tic tac toe game project using graphics in C language in Hindi पोस्ट ख़त्म होती है। हम आशा करते है की आपको हमारी यह पोस्ट जरूर पसंद आई होगी और आप tic tac toe game का project C language के graphics सिस्टम का यूज़ करके बनाना सीख गए होंगे। तो दोस्तों आज के लिए बस इतना ही फिर मिलेंगे ऐसी ही किसी और मजेदार पोस्ट में तब तक के लिए अलविदा !
0 Comments
Do not enter any spam comments please.