Ghislain_Mike

tictactoe

Apr 26th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.09 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. void message_1() {
  4.     puts("+-----------------------------------------+");
  5.     puts("|     Welcome to TIC TAC TOE Game!        |");
  6.     puts("| Align 3 [x] characters to score points  |");
  7.     puts("| 1. Start playing now                    |");
  8.     puts("| Press any other key to exit             |");
  9.     puts("+-----------------------------------------+");
  10. }
  11.  
  12. void print_board(int points[9]) {
  13.     puts("    + - + - + - +");
  14.     puts("    | 1 | 2 | 3 |");
  15.     puts("+ - + - + - + - + - +");
  16.  
  17.     if (points[0] == 1) {
  18.         printf("| 1 | X |");
  19.     } else {
  20.         printf("| 1 |   |");
  21.     }
  22.  
  23.     if (points[1] == 1) {
  24.         printf(" X ");
  25.     } else {
  26.         printf("   ");
  27.     }
  28.  
  29.     if (points[2] == 1) {
  30.         printf("| X | 3 |\n");
  31.     } else {
  32.         printf("|   | 3 |\n");
  33.     }
  34.  
  35.     puts("+ - + - + - + - + - +");
  36.  
  37.     if (points[3] == 1) {
  38.         printf("| 4 | X |");
  39.     } else {
  40.         printf("| 4 |   |");
  41.     }
  42.  
  43.     if (points[4] == 1) {
  44.         printf(" X ");
  45.     } else {
  46.         printf("   ");
  47.     }
  48.  
  49.     if (points[5] == 1) {
  50.         printf("| X | 6 |\n");
  51.     } else {
  52.         printf("|   | 6 |\n");
  53.     }
  54.  
  55.     puts("+ - + - + - + - + - +");
  56.  
  57.     if (points[6] == 1) {
  58.         printf("| 7 | X |");
  59.     } else {
  60.         printf("| 7 |   |");
  61.     }
  62.  
  63.     if (points[7] == 1) {
  64.         printf(" X ");
  65.     } else {
  66.         printf("   ");
  67.     }
  68.  
  69.     if (points[8] == 1) {
  70.         printf("| X | 9 |\n");
  71.     } else {
  72.         printf("|   | 9 |\n");
  73.     }
  74.  
  75.     puts("+ - + - + - + - +");
  76.     puts("    | 7 | 8 | 9 |");
  77.     puts("    + - + - + - +");
  78. }
  79.  
  80. int main() {
  81.     int choice, points[9], count = 0;
  82.  
  83.     message_1();
  84.     scanf("%d", &choice);
  85.  
  86.     switch (choice) {
  87.     case 1:
  88.         while(count <= 9) {
  89.             system("@cls||clear");
  90.             print_board(points);
  91.  
  92.             printf(" Enter position number: ");
  93.             scanf("%d", &choice);
  94.             points[choice - 1] = 1;
  95.             count++;
  96.         }
  97.  
  98.         break;
  99.     default:
  100.         exit(0);
  101.     }
  102.  
  103.     return 0;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment