JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

हिंदी माध्यम नोट्स

Categories: C Language in hindi

C Project : Tic Tac Toe Game in hindi in c language टिक टक टोए गेम क्या है c प्रोजेक्ट हिंदी में

टिक टक टोए गेम क्या है c प्रोजेक्ट हिंदी में C Project : Tic Tac Toe Game in hindi in c language :-
Tic Tac Toe Game कभी कभी हम सब ने खेला होगा |आज हम इस प्रोजेक्ट मे Tic Tac Toe Gameके c प्रोग्राम को read करेगे |
logic :
Tic Tac Toe Game प्रोग्राम मे ,array based है इसमें एक array जिसका नाम है game |
इस array के element है इसकी position |जैसे row=0 और column=0 होने पर array element 0 होगा |
row 0 और colunm=1 होने पर array element 1 होगा |row=0 और column=2 होने पर array element 2 होगा |
फिर row =1 और colunm=0 होने पर array element 4 होगा | row =1 और colunm=1 होने पर array element 5 होगा | row =1 और colunm=2 होने पर array element 6 होगा |
फिर row =2 और colunm=0 होने पर array element 7 होगा |row =2 और colunm=1 होने पर array element 8 होगा |row =1 और colunm=2 होने पर array element 9 होगा |
main() function मे , दो=while loop चलता है|सबसे पहले display() function run होता है जिससे की game की board print होती है |
फिर player = (player % 2) ? 1 : 2; statement से प्लेयर की value set हो जाती है |अगर सम सख्या आती है तब प्लेयर 2 और विषम आती तब प्लेयर 1 choose होता है |
mark = (player == 1) ? ‘X’ : ‘O’;statement ‘X’ या ‘O’ को choose करगे |
और printf(“Player %d, enter a number: “, player); statement से प्लेयर number choose करवाते है जिसे उसे सेलेक्ट करना है |
अगर प्लेयर द्वारा choose की position और array game की position सही होने पर array की उस position पर mark ‘X’ या ‘O’ store हो जाता है |
और सारी position फुल हो tab invalid मूव का message आस जाता है |
और सही होने पर win() function चलता है जिसमे game को जितने की condition check हो ती है |
अगर 1 return होता तब GAME IS OVER WITH RESULT, अगर -1 return होता है तब FOR GAME IS IN PROGRESS और अगर O return होता है तब GAME IS OVER AND NO RESULT होता है |
Source code :
#include <stdio.h>
#include <conio.h>

char game[10] = { ‘o’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’ }; 

int win();
void board();
 

int main()
{
int player = 1, i, choice;
 

char mark;
do
{
display();
player = (player %
2) ? 1 : 2;
printf(

“Player %d, enter a number: “, player);
scanf(
“%d”, &choice);
mark = (player ==

1) ? ‘X’ : ‘O’; 

if (choice == 1 && game[1] == ‘1’)
square[
1] = mark;
 

else if (choice == 2 && game[2] == ‘2’)
square[2]
= mark;
 

else if (choice == 3 && game[3] == ‘3’)
square[3]
= mark;
 

else if (choice == 4 && game[4] == ‘4’)
square[4]
= mark;
 

else if (choice == 5 && game[5] == ‘5’)
square[5]
= mark;
 

else if (choice == 6 && gamne[6] == ‘6’)
square[6]
= mark;
 

else if (choice == 7 && game[7] == ‘7’)
square[7]
= mark;
 

else if (choice == 8 && game[8] == ‘8’)
square[8]
= mark;
 

else if (choice == 9 && game[9] == ‘9’)
square[9]
= mark;
 

else
{
printf(
“Invalid move “);
player–;
getch();
}
i = win();

player++;
}

while (i == – 1);display();

 

if (i == 1)
printf(
” It is Player %d win “, –player);
else
printf(“It is a Game draw”)
;
getch();

 

return 0;
}
 

 

int win()
{
if (game[1] == game[2] && game[2] == game[3])
return 1;
 

else if (game[4] == game[5] && game[5] == game[6])
return 1
;
 

else if (game[7] == game[8] && game[8] == game[9])
return 1
;
 

else if (game[1] == game[4] && game[4] == game[7])
return 1
;
 

else if (game[2] == game[5] && game[5] == game[8])
return 1
;
 

else if (game[3] == game[6] && game[6] == game[9])
return 1
;
 

else if (game[1] == game[5] && game[5] == game[9])
return 1
;
 

else if (game[3] == game[5] && game[5] == game[7])
return 1
;
 

else if (game[1] != ‘1’ && game[2] != ‘2’ && game[3] != ‘3’ && game[4] != ‘4’ && game[5] != ‘5’ && game[6] != ‘6’ && game[7] != ‘7’ && game[8] != ‘8’ && game[9] != ‘9’)
return 0
;
else
return1;
}
 

/* Code For Display*/
void board()
{
system(
“cls”);
printf(
“\n\n\tTic Tac Toe\n\n”);
printf(

“Player 1 (X) – Player 2 (O)\n\n\n”);printf(

” | | \n”);
printf(
” %c | %c | %c \n”, game[1], game[2], game[3]);
printf(

“_____|_____|_____\n”);
printf(
” | | \n”);
printf(

” %c | %c | %c \n”, game[4], game[5], game[6]);printf(

“_____|_____|_____\n”);
printf(
” | | \n”);
printf(

” %c | %c | %c \n”, game[7], game[8], game[9]);printf(

” | | \n\n”);
}

Sbistudy

Recent Posts

Question Tag Definition in english with examples upsc ssc ias state pcs exames important topic

Question Tag Definition • A question tag is a small question at the end of a…

2 weeks ago

Translation in english grammer in hindi examples Step of Translation (अनुवाद के चरण)

Translation 1. Step of Translation (अनुवाद के चरण) • मूल वाक्य का पता करना और उसकी…

2 weeks ago

Report Writing examples in english grammer How to Write Reports explain Exercise

Report Writing • How to Write Reports • Just as no definite rules can be laid down…

2 weeks ago

Letter writing ,types and their examples in english grammer upsc state pcs class 12 10th

Letter writing • Introduction • Letter writing is an intricate task as it demands meticulous attention, still…

2 weeks ago

विश्व के महाद्वीप की भौगोलिक विशेषताएँ continents of the world and their countries in hindi features

continents of the world and their countries in hindi features विश्व के महाद्वीप की भौगोलिक…

2 weeks ago

भारत के वन्य जीव राष्ट्रीय उद्यान list in hin hindi IAS UPSC

भारत के वन्य जीव भारत में जलवायु की दृष्टि से काफी विविधता पाई जाती है,…

2 weeks ago
All Rights ReservedView Non-AMP Version
X

Headline

You can control the ways in which we improve and personalize your experience. Please choose whether you wish to allow the following:

Privacy Settings
JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now