Advertisement
DerNerd97

TicTacToe in, manual win detection

Apr 25th, 2014
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.38 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int i;
  4. int j;
  5. int l;
  6. int h;
  7. int u;
  8. int z;
  9.  
  10. int x;
  11. int y;
  12. //board[x][y]
  13. //board[rows][columns]
  14. int board[3][3] = {
  15.     {0, 0, 0} ,//Initializers for row 0
  16.     {0, 0, 0} ,//Initializers for row 1
  17.     {0, 0, 0}//initializers for row 2
  18. };
  19.  
  20. int cell;
  21.  
  22. /*
  23. 0 = not filled yet
  24. 1 = O
  25. 2 = X
  26. */
  27.  
  28. /*Board will not be an array itself. array will just be used for saving.
  29. [O][X][O]
  30. [X][0][0]
  31. [O][X][X]
  32. */
  33.  
  34. //function declaration
  35. void display();
  36. void p1();
  37. void p2();
  38.  
  39. main(){
  40.     system("clear");
  41.  
  42.     display();
  43.  
  44.     p1();
  45.     for(u = 0; u <= 3; u++){
  46.         p2();
  47.         p1();
  48.     }
  49. }
  50.  
  51. void display(){
  52.     system("clear");
  53.  
  54.     for(i = 0; i <= 2; i++){
  55.         for(j = 0; j <= 2; j++){
  56.             cell = board[i][j];
  57.             switch(cell){
  58.                 case 0: printf("[_]");
  59.                     break;
  60.                 case 1: printf("[O]");
  61.                     break;
  62.                 case 2: printf("[X]");
  63.                     break;
  64.                 default:printf("[!]");
  65.             }
  66.         }
  67.         printf("\n");
  68.     }
  69.     printf("\n");
  70. }
  71.  
  72. void p1(){
  73.     printf("It's P1's turn[O].\n");
  74.     printf("Enter row to enter symbol in: ");
  75.     scanf("%d", &x);
  76.  
  77.     printf("\nEnter column to enter symbol in: ");
  78.     scanf("%d", &y);
  79.  
  80.     board[x][y] = 1;
  81.    
  82.     x, y = 0;
  83.  
  84.     display();
  85. }
  86.  
  87. void p2(){
  88.     printf("It's P2's turn[X].\n");
  89.     printf("Enter row to enter symbol in: ");
  90.     scanf("%d", &x);
  91.  
  92.     printf("\nEnter column to enter symbol in: ");
  93.     scanf("%d", &y);
  94.  
  95.     board[x][y] = 2;
  96.    
  97.     x, y = 0;
  98.  
  99.     display();
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement