ramontricolor12

LISTA 05 - Exercício 15

Jul 8th, 2013
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.40 KB | None | 0 0
  1. /* CABEÇALHO
  2.    Arquivo: LISTA 05 - Exercicio 15.c
  3.    Objetivo: Validação de um jogo da velha.
  4.    Autor(a): Ramon Borges
  5.  */
  6.  
  7. #include <stdio.h>
  8. int main()
  9. {
  10.     char JogoDaVelha[3][3], vencedor;
  11.     int i, j, contX = 0, contY = 0;
  12.  
  13.     printf("***PREENCHA O JOGO DA VELHA***\n");
  14.     for(i = 0; i < 3; i++)
  15.         for(j = 0; j < 3; j++)
  16.         {
  17.             printf("\nMarque X ou O: ");
  18.             scanf(" %c", &JogoDaVelha[i][j]);
  19.         }
  20.     //LINHAS
  21.     for(i = 0; i < 3; i++)
  22.     {
  23.         for(j = 0; j < 3; j++)
  24.         {
  25.             if(JogoDaVelha[i][j] == 'X')
  26.                 contX++;
  27.             else if(JogoDaVelha[i][j] == 'O')
  28.                 contY++;
  29.             else
  30.                 break;
  31.         }
  32.         if(contX == 3)
  33.         {
  34.             printf("\nJogador X venceu!!!");
  35.             return 0;
  36.         }
  37.         else if(contY == 3)
  38.         {
  39.             printf("\nJogador Y venceu!!!");
  40.             return 0;
  41.         }
  42.         contX = contY = 0;
  43.     }
  44.     //COLUNAS
  45.     for(i = 0; i < 3; i++)
  46.     {
  47.         for(j = 0; j < 3; j++)
  48.         {
  49.             if(JogoDaVelha[j][i] == 'X')
  50.                 contX++;
  51.             else if(JogoDaVelha[j][i] == 'O')
  52.                 contY++;
  53.             else
  54.                 break;
  55.         }
  56.         if(contX == 3)
  57.         {
  58.             printf("\nJogador X venceu!!!");
  59.             return 0;
  60.         }
  61.         else if(contY == 3)
  62.         {
  63.             printf("\nJogador Y venceu!!!");
  64.             return 0;
  65.         }
  66.         contX = contY = 0;
  67.     }
  68.  
  69.     //DIAGONAL1
  70.     i = j = 0;
  71.     while(j < 4)
  72.     {
  73.         if(JogoDaVelha[i][j] == 'X')
  74.             contX++;
  75.         else if(JogoDaVelha[i][j] == 'O')
  76.             contY++;
  77.         i++;
  78.         j++;
  79.     }
  80.     if(contX == 3)
  81.     {
  82.         printf("\nJogador X venceu!!!");
  83.         return 0;
  84.     }
  85.     else if(contY == 3)
  86.     {
  87.         printf("\nJogador Y venceu!!!");
  88.         return 0;
  89.     }
  90.     contX = contY = 0;
  91.     //DIAGONAL2
  92.     i = 0;
  93.     j = 2;
  94.     while(j >= 0)
  95.     {
  96.         if(JogoDaVelha[i][j] == 'X')
  97.             contX++;
  98.         else if(JogoDaVelha[i][j] == 'O')
  99.             contY++;
  100.         i++;
  101.         j--;
  102.     }
  103.     if(contX == 3)
  104.     {
  105.         printf("\nJogador X venceu!!!");
  106.         return 0;
  107.     }
  108.     else if(contY == 3)
  109.     {
  110.         printf("\nJogador O venceu!!!");
  111.         return 0;
  112.     }
  113.  
  114.     return 99;
  115. }
Advertisement
Add Comment
Please, Sign In to add comment