├── Screenshot (64).png ├── Screenshot (65).png ├── Screenshot (66).png ├── README.md └── tic_tac_toe.c /Screenshot (64).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nasrum190/Tic-Tac-Toe_Game_Project/HEAD/Screenshot (64).png -------------------------------------------------------------------------------- /Screenshot (65).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nasrum190/Tic-Tac-Toe_Game_Project/HEAD/Screenshot (65).png -------------------------------------------------------------------------------- /Screenshot (66).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nasrum190/Tic-Tac-Toe_Game_Project/HEAD/Screenshot (66).png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Tic-Tac-Toe_Game_Project_with_C 2 | It is very enjoyable game. 3 | I also tried to give some colors and animation in my projetcs. 4 | Enjoy!Thank You. 5 | -------------------------------------------------------------------------------- /tic_tac_toe.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | char box[10]={'o','1','2','3','4','5','6','7','8','9'}; 4 | void Game_Board() 5 | { 6 | printf(" Player 1 (O) --- Player 2 (X)\n\n\n"); 7 | printf(" \x1b[36m| |\x1b[0m \n"); 8 | printf(" %c \x1b[36m|\x1b[0m %c \x1b[36m|\x1b[0m %c \n",box[1],box[2],box[3]); 9 | printf(" \x1b[36m _______|_______|_______\x1b[0m\n"); 10 | printf(" %c \x1b[36m|\x1b[0m %c \x1b[36m|\x1b[0m %c \n",box[4],box[5],box[6]); 11 | printf(" \x1b[36m_______|_______|_______\x1b[0m\n"); 12 | printf(" %c \x1b[36m|\x1b[0m %c \x1b[36m|\x1b[0m %c \n",box[7],box[8],box[9]); 13 | printf(" \x1b[36m | |\x1b[0m \n"); 14 | 15 | } 16 | int check_for_winner() 17 | { 18 | if(box[1]==box[2] && box[2]==box[3]) 19 | { 20 | return 1; 21 | } 22 | else if(box[4]==box[5] && box[5]==box[6]) 23 | { 24 | return 1; 25 | } 26 | else if (box[7] == box[8] && box[8] == box[9]) 27 | { 28 | return 1; 29 | } 30 | 31 | else if (box[1] == box[4] && box[4] == box[7]) 32 | { 33 | return 1; 34 | } 35 | else if (box[2] == box[5] && box[5] == box[8]) 36 | { 37 | return 1; 38 | } 39 | else if (box[3] == box[6] && box[6] == box[9]) 40 | { 41 | 42 | return 1; 43 | } 44 | else if (box[1] == box[5] && box[5] == box[9]) 45 | { 46 | return 1; 47 | } 48 | else if (box[3] == box[5] && box[5] == box[7]) 49 | { 50 | return 1; 51 | } 52 | else if (box[1] != '1' && box[2] != '2' && box[3] != '3' && 53 | box[4] != '4' && box[5] != '5' && box[6] != '6' && box[7] 54 | != '7' && box[8] != '8' && box[9] != '9') 55 | { 56 | return 0; 57 | } 58 | else 59 | { 60 | return -1; 61 | 62 | } 63 | } 64 | int main() 65 | { 66 | int player=1; 67 | int i,choice; 68 | char sign,start; 69 | printf(" =================================\n"); 70 | printf("\x1b[32m Welcome to My Tic-Tac-Toe Game\x1b[0m\n"); 71 | printf(" =================================\n\n"); 72 | printf("1.Please Enter \x1b[32mS\x1b[0m to Start The Game\n2.Please Enter \x1b[31mE\x1b[0m for Exit From the Game\n"); 73 | scanf("%c",&start); 74 | if(start=='S'){ 75 | do 76 | { 77 | Game_Board(); 78 | if(player % 2!=0) 79 | { 80 | player=1; 81 | } 82 | else 83 | { 84 | player=2; 85 | } 86 | printf("Player %d Enter Your Box Number=",player); 87 | scanf("%d",&choice); 88 | if(player==1) 89 | { 90 | sign='O'; 91 | } 92 | else 93 | { 94 | sign='X'; 95 | } 96 | if(choice==1 && box[1]=='1') 97 | { 98 | box[1]=sign; 99 | } 100 | else if(choice==2 && box[2]=='2'){ 101 | box[2]=sign; 102 | } 103 | else if ( choice==3 && box[3]=='3'){ 104 | box[3]=sign; 105 | } 106 | else if( choice==4 && box[4]=='4'){ 107 | box[4]=sign; 108 | } 109 | else if ( choice==5 && box[5]=='5'){ 110 | box[5]=sign; 111 | } 112 | else if ( choice==6 && box[6]=='6'){ 113 | box[6]=sign; 114 | } 115 | else if ( choice==7 && box[7]=='7'){ 116 | box[7]=sign; 117 | } 118 | else if ( choice==8 && box[8]=='8'){ 119 | box[8]=sign; 120 | } 121 | else if( choice==9 && box[9]=='9'){ 122 | box[9]=sign; 123 | } 124 | else { 125 | printf("Your move is invalid. Please Try Again\n"); 126 | player=player-1; 127 | getch(); 128 | } 129 | i=check_for_winner(); 130 | player++; 131 | 132 | } 133 | while (i==-1); 134 | 135 | Game_Board(); 136 | if(i==1) 137 | { for(int a=1;a<=20;a++) 138 | { 139 | printf("_|*|_"); 140 | } 141 | printf("\n\n\x1b[33mPlayer %d Won The Match\x1b[0m\n\n",player=player-1); 142 | for(int b=1;b<=20;b++) 143 | { 144 | printf("_|*|_"); 145 | } 146 | } 147 | else{ 148 | printf("\x1b[31m -----Match Draw-----\x1b[0m"); 149 | } 150 | } 151 | else if(start=='E') 152 | { 153 | return 0; 154 | } 155 | getch(); 156 | 157 | 158 | } 159 | --------------------------------------------------------------------------------