Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.56 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <conio.h> // Biblioteca para adicionar cores
  4. #define L 10 // Numero de Linhas da matriz
  5. #define C 8 // Numero de Colunas da matriz
  6. #define TAM 4 // Tamanho do vetor vet que armazenará a senha gerada aleatoriamente
  7.  
  8.  
  9.             // Nomes: Abidiel e Vinícius W.
  10.  
  11. void sorteio(int vet[TAM]) // Funcao que sorteia os numeros aleatorios
  12. {
  13.     int x;
  14.     srand( (unsigned)time(NULL) );
  15.     for(x=0;x<TAM;x++)
  16.     {
  17.         vet[x]=1 + ( rand() % 6 );
  18.     }
  19.     printf("\n\t\t\t\t====== SENHA GERADA ======\n\n");
  20.     printf("\t\t\t\tBoa sorte Desafiado(a)!!\n\n");
  21.     printf("\t\t\t\t==========================\n");
  22.     printf("\n");
  23.     printf("===================== BEM VINDO AO JOGO DA SENHA NOBRE DESAFIADO(A) =====================\n");
  24.     printf("\n");
  25.     system("pause");
  26.     system("cls");
  27.  
  28.  
  29.     for(x=0;x<TAM;x++) // MOSTRANDO OS NUMERO SORTEADOS SO PRA TESTE
  30.     {
  31.         printf("Numero: %d \n", vet[x]);
  32.     }
  33.  
  34. }
  35.  
  36. void lerTentativas(int tentativa, int numTentativa, int vet[TAM], int matriz[L][C]) // Função para ler as tentativas do Desafiado
  37. {
  38.     int x, y, numLinha=1;
  39.     tentativa=1;
  40.     printf("\n");
  41.     printf("\t\t================ MENU ==================\n");
  42.     printf("\n\t\t\tDigite 1 para a cor verde\n");
  43.     printf("\t\t\tDigite 2 para a cor azul\n");
  44.     printf("\t\t\tDigite 3 para a cor amarelo\n");
  45.     printf("\t\t\tDigite 4 para a cor vermelho\n");
  46.     printf("\t\t\tDigite 5 para a cor roxo\n");
  47.     printf("\t\t\tDigite 6 para a cor marrom\n\n");
  48.     printf("\t\t================ MENU ==================\n");
  49.  
  50.         for(x=0;x<L;x++)
  51.         {
  52.             for(y=0;y<4;y++)
  53.             {
  54.                 printf("\n\nDigite o numero %d da sua %d tentativa:\t", numLinha, tentativa); // informa tentativa atual
  55.                 scanf("%d", &matriz[x][y]); //preenchendo matriz com tentativas do usuario
  56.                 while (matriz[x][y] > 6 || matriz[x][y] < 1) // valida se o numero digitado esta conforme o MENU
  57.                 {
  58.                     printf("\t\t=======================================================\n");
  59.                     printf("\t\tPor favor nobre desafiado(a), digite numeros de 1 ao 6.\n");
  60.                     printf("\t\t=======================================================\n");
  61.                     printf("\nDigite o numero %d da sua %d tentativa:\t", numLinha, tentativa); // informa tentativa atual
  62.                     scanf("%d", &matriz[x][y]); //preenchendo matriz com tentativas do usuario
  63.                 }
  64.                 numLinha++;
  65.                 mostrarMatriz(matriz); // Chama a funcao para mostrar a matriz atualizada a cada jogada.
  66.             }
  67.             computaTentativas(matriz, &vet[x]);
  68.             numLinha=1;
  69.             tentativa++;
  70.         }
  71.  
  72.  
  73.  
  74. }
  75.  
  76.  
  77. void computaTentativas(int matriz[L][C], int vet[TAM]) // Função para comparar e computar as tentativas do Desafiado
  78. {
  79.     int x, y, z=0;
  80.     for(x=0;x<L;x++)
  81.         {
  82.             for(y=0;y<4;y++)
  83.             {
  84.                 if (matriz[x][y]==vet[z])
  85.                 {
  86.                     printf("PINO PRETO!");
  87.  
  88.                 }
  89.                 else if (matriz[x][y]==vet[0] || matriz[x][y]==vet[1] || matriz[x][y]==vet[2] || matriz[x][y]==vet[3])
  90.                 {
  91.                     printf("PINO BRANCO!");
  92.                 }
  93.                 else
  94.                 {
  95.                     printf("Nem um numero foi encontrado em uma posicao da senha!");
  96.                 }
  97.                 z++;
  98.             }
  99.         }
  100.  
  101.  
  102. }
  103.  
  104.  
  105. void mostrarMatriz(int matriz[L][C])
  106. {
  107.     int x, y;
  108.     printf("\n\n");
  109.     printf("\t\t============== MATRIZ ATUALIZADA ==============");
  110.     for(x=0;x<L;x++)
  111.         {
  112.             printf("\n");
  113.             for(y=0;y<C;y++)
  114.             {
  115.                 printf("\t%4d", matriz[x][y]);
  116.             }
  117.         }
  118.         printf("\n");
  119.         printf("\t\t============== MATRIZ ATUALIZADA ==============\n\n");
  120.         system("pause");
  121.         system("cls");
  122. }
  123.  
  124. int main()
  125. {
  126.     int x, y, matriz[L][C] = {0}, senha, vet[TAM], tentativa=0, numTentativa;
  127.     printf("===================== BEM VINDO AO JOGO DA SENHA NOBRE DESAFIADO(A) =====================\n");
  128.     sorteio(&vet);
  129.     lerTentativas(tentativa, numTentativa, vet, &matriz);
  130.     system("cls");
  131.     printf("\n");
  132.     printf("\t\t\t============== FINAL DE JOGO ==============\n");
  133.     printf("\n\t\t\tTENTATIVAS ESGOTADAS, O DESAFIANTE VENCEU!\n\n\t");
  134.     printf("\t\t============== FINAL DE JOGO ==============\n\n");
  135.     system("pause");
  136.     return 0;
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement