Advertisement
auladecomputacao

genius_C

Oct 18th, 2018
985
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.29 KB | None | 0 0
  1. /*
  2. Genius.c
  3. Função: Jogo Genius
  4. Data: 18/10/2018
  5. Autor: Guilherme Bezerra Fernandes
  6. */
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <time.h>
  11. #include <string.h>
  12. #include <windows.h>
  13.  
  14. //variaveis globais
  15. int seq[6][6];
  16. int vel = 0;
  17. int fase = 0;
  18. int contador = 0;
  19. int tempo = 500;
  20. int usu[6];
  21. int cont = 0;
  22.  
  23. //protótipo das funções
  24. void inicia();
  25. void geranum();
  26. void menu();
  27. void liga();
  28. void muda(int i, int t, int habilita);
  29. int verifica();
  30. void mostraganhou();
  31. void mostraerrou();
  32. void tamanho_tela(int x, int y);
  33.  
  34. int main()
  35. {
  36.     int i;
  37.    
  38.     tamanho_tela(50,20);
  39.     inicia();
  40.     system("cls");
  41.     geranum();
  42.     menu();
  43.  
  44.     _beep(100,2000); //aguarda 2s
  45.    
  46.     liga();
  47.    
  48.     while(1)
  49.     {      
  50.         for(i = 0; i <= contador; i++)
  51.         {
  52.             printf("\nDigite a sequencia: \n");
  53.             printf(" Numero %d: ", i + 1);
  54.             scanf("%d", &usu[i]);
  55.             muda(usu[i],100,1);        
  56.         }
  57.        
  58.         if (verifica())
  59.         {
  60.             contador++;
  61.             if (contador %6 == 0 )
  62.             {
  63.                 printf("Preparando para a nova fase...");
  64.                 _beep(100,2000); //aguarda 2s
  65.                
  66.                 fase++;
  67.                 vel++;
  68.                 tempo-=100;
  69.                 if (tempo < 100)
  70.                 {
  71.                     tempo = 500;
  72.                     fase = 0;
  73.                 }
  74.                 contador = 0;
  75.             }
  76.             mostraganhou();
  77.             liga();
  78.             cont = 0;
  79.         }else
  80.         {
  81.             mostraerrou();
  82.             liga();
  83.             cont = 0;
  84.         }
  85.     }
  86.    
  87.     system("pause");
  88.     return 0;
  89. }
  90.  
  91. void inicia()
  92. {
  93.    int y = 400, c = 0;
  94.    char cmd_MSDOS[50]   ;
  95.    char barra[50];
  96.    
  97.    strcpy(barra, "");
  98.    
  99.    for(c = 0; c<= 15; c++)
  100.    {
  101.        system("cls");
  102.        //if(c<=15)
  103.         {
  104.             sprintf(cmd_MSDOS, "color %xF", c);
  105.             strcat(barra, ":");
  106.             printf("%s\n", barra);
  107.             printf(": JOGO GENIUS : \n");
  108.             printf("%s\n", barra);
  109.             _beep(y,100);
  110.            
  111.             if (c == 15)
  112.             system("color F0");
  113.             else
  114.             system(cmd_MSDOS);
  115.         }
  116.         y+=200;
  117.    }
  118. }
  119.  
  120. void geranum()
  121. {
  122.     int lin, col;
  123.     int num;
  124.    
  125.     srand(time(NULL));
  126.     for(lin = 0; lin <= 4; lin++){
  127.         for(col = 0; col<= 4; col++){
  128.             //para gerar numeros aleatorios de 0 a 3
  129.             num = (rand()%4);
  130.             //printf("%d", num);
  131.             while (num==seq[lin][col-1]){
  132.                 num = (rand()%4);
  133.             }
  134.             seq[lin][col] = num;
  135.         }
  136.     }
  137. }
  138.  
  139. void menu()
  140. {
  141.     printf("ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ\n");
  142.     printf("Û                 JOGO GENIUS                   Û\n");
  143.     printf("ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ\n");
  144.     printf(": VELOCIDADE %d - FASE %d \n", vel + 1, fase + 1);
  145.     printf("iniciando... \n");
  146. }
  147.  
  148. void liga( )
  149. {
  150.     int j;
  151.     for(j = 0; j <= contador; j++)
  152.     {
  153.         muda(seq[fase][j], tempo, 0);
  154.         menu();
  155.     }  
  156. }
  157.  
  158. void muda(int i, int t, int habilita)
  159. {
  160.     switch(i)
  161.     {
  162.         //cor azul
  163.       case 0:
  164.          system("color 1F");
  165.          printf("\n::: 0 ::::");
  166.          _beep(1000,t);
  167.       break;
  168.      
  169.         //cor vermelha
  170.       case 1:
  171.          system("color 4F");
  172.          printf("\n::: 1 ::::");
  173.          _beep(800,t);
  174.       break;
  175.      
  176.         //cor verde
  177.       case 2:
  178.          system("color 2F");
  179.          printf("\n::: 2 ::::");
  180.          _beep(600,t);
  181.       break;
  182.      
  183.         //cor amarela
  184.       case 3:
  185.          system("color E0");
  186.          printf("\n::: 3 ::::");
  187.          _beep(500,t);
  188.       break;
  189.     }
  190.     if (habilita == 0)
  191.     system("cls");
  192.    
  193.     system("color 0F");
  194. }
  195.  
  196. int verifica()
  197. {
  198.     int c, l;
  199.     l = fase;
  200.     for(c = 0; c<= contador; c++)
  201.     {
  202.         if (seq[l][c]!= usu[c])
  203.         {
  204.             return 0;
  205.             break;
  206.         }
  207.     }
  208.     return 1;
  209. }
  210.  
  211. void mostraganhou()
  212. {
  213.     printf("\n\n:::::::::::::::::::::: \n");
  214.     printf(":   Voce acertou!    : \n");
  215.     printf(":::::::::::::::::::::: \n");
  216.     printf(": VELOCIDADE %d - FASE %d \n", vel + 1, fase + 1);
  217.     system("color 5F");
  218.     _beep(400,1000);
  219.     system("cls");
  220.     menu();
  221. }
  222.  
  223. void mostraerrou()
  224. {
  225.     printf("\n\n:::::::::::::::::::::: \n");
  226.     printf(":     Voce errou!    : \n");
  227.     printf(":::::::::::::::::::::: \n");
  228.     printf(": VELOCIDADE %d - FASE %d \n", vel + 1, fase + 1);
  229.     system("color 4F");
  230.     _beep(900,2000);
  231.     system("cls");
  232.     menu();
  233. }
  234.  
  235. void tamanho_tela(int x, int y)
  236. {
  237.    HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);   
  238.    SMALL_RECT sr;
  239.    COORD consoleSize;
  240.    sr.Top=sr.Left=0;  
  241.    consoleSize.X = x; consoleSize.Y = y;
  242.    sr.Right=consoleSize.X-1; sr.Bottom=consoleSize.Y-1;  
  243.  
  244.    SetConsoleWindowInfo(console, TRUE, &sr);
  245.    SetConsoleScreenBufferSize(console, consoleSize);    
  246. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement