Advertisement
Drowze

Jogo: Olho da Tempesatade

Jun 6th, 2014
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.57 KB | None | 0 0
  1. /*
  2. Jogo: Olho da Tempestade
  3. Versao: 1.0
  4. Por: Rafael Gibim
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <time.h>
  10. #define MAX 9
  11.  
  12. #define CIMA 24
  13. #define BAIXO 25
  14. #define DIREITA 26
  15. #define ESQUERDA 27
  16.  
  17. #define TENTATIVAS 10
  18.  
  19. int main()
  20. {
  21.     int win = 0; // 0: não definido, 1: vitória, 2: derrota
  22.     int tentativas = TENTATIVAS;
  23.     int random1;
  24.     int i, j;
  25.     int diferenca_i, diferenca_j;
  26.     char mtz[MAX][MAX], mtz_nula[MAX][MAX]; //mtz = matriz solução, mtz_nula = matriz impressa para o usuário final
  27.     char codigo;
  28.     srand(time(NULL));
  29.  
  30.  
  31.  
  32.     //Escolhendo a resposta
  33.     int i_resposta = rand()%MAX;
  34.     int j_resposta = rand()%MAX;
  35.     mtz[i_resposta][j_resposta] = '@';
  36.     //Escolhendo resposta
  37.  
  38.     //Preenchendo a matriz nula
  39.     for(i=0;i<MAX;i++)
  40.         for(j=0;j<MAX;j++) mtz_nula[i][j] = 178;
  41.     //Fim do preenchimento da matriz nula
  42.  
  43.     //Preenchendo a matriz-solução
  44.     for(i=0;i<MAX;i++){
  45.         for(j=0;j<MAX;j++){
  46.             if(i>i_resposta) diferenca_i = i-i_resposta;
  47.             else diferenca_i = i_resposta - i;
  48.             if(j>j_resposta) diferenca_j = j-j_resposta;
  49.             else diferenca_j = j_resposta - j;
  50.  
  51.             //BLOCO DOS IFS MALIGNOS
  52.             if( (rand()%10+1) > 5    &&    (i != i_resposta || j != j_resposta) ){ //CHANCE DE SAIR UMA DICA: 50%
  53.  
  54.                 if(i > i_resposta && j == j_resposta) mtz[i][j] = CIMA; // resposta logo abaixo
  55.                 else if(i < i_resposta && j == j_resposta) mtz[i][j] = BAIXO; //resposta logo acima
  56.                 else if(i == i_resposta && j < j_resposta) mtz[i][j] = DIREITA; //resposta logo a direita
  57.                 else if(i == i_resposta && j > j_resposta) mtz[i][j] = ESQUERDA; //resposta logo a esquerda
  58.  
  59.                 else if(diferenca_i < diferenca_j && i < i_resposta) mtz[i][j] = BAIXO; //resposta abaixo
  60.                 else if(diferenca_i < diferenca_j && i > i_resposta) mtz[i][j] = CIMA; //resposta acima
  61.                 else if(diferenca_i > diferenca_j && j < j_resposta) mtz[i][j] = DIREITA; //resposta à esquerda
  62.                 else if(diferenca_i > diferenca_j && j > j_resposta) mtz[i][j] = ESQUERDA; //resposta à direita
  63.                
  64.                 else{ //Pra caso dê a MERDA de ser na diagonal...
  65.  
  66.                     if(i < i_resposta && j < j_resposta )
  67.                         if(rand()%2==0) mtz[i][j] = BAIXO;
  68.                         else mtz[i][j] = DIREITA;
  69.                     else if(i < i_resposta && j > j_resposta )
  70.                         if(rand()%2==0) mtz[i][j] = BAIXO;
  71.                         else mtz[i][j] = ESQUERDA;
  72.                     else if(i > i_resposta && j < j_resposta )
  73.                         if(rand()%2==0) mtz[i][j] = CIMA;
  74.                         else mtz[i][j] = DIREITA;
  75.                     else if(i > i_resposta && j > j_resposta )
  76.                         if(rand()%2==0) mtz[i][j] = CIMA;
  77.                         else mtz[i][j] = ESQUERDA;
  78.                 }
  79.             }
  80.             else if(i != i_resposta || j != j_resposta) mtz[i][j] = '0';
  81.             //FIM DO BLOCO DOS IFS MALIGNOS
  82.         }
  83.     }
  84.     //Fim do preenchimento da matriz-solução.
  85.  
  86.     //Apresentacao do jogo
  87.     system("color 37");
  88.  
  89.     printf("OLHO DA TEMPESTADE! v1.0\n\n");
  90.    
  91.     printf("Essa nao! A tempestade esta destruindo tudo por onde passa!\n");
  92.     printf("Para parar a tempestade, voce devera encontrar a sua origem,\n");
  93.     printf("Entao, o unico jeito de parar a tempestade eh encontrando o OLHO DA TEMPESTADE!\n\n\n\n");
  94.  
  95.  
  96.  
  97.     printf("Boa sorte!\n");
  98.    
  99.     scanf("%c",&codigo);
  100.     if(codigo=='*'){
  101.         printf("Resposta: mtz[%d][%d]\n\n",i_resposta+1,j_resposta+1);
  102.         system("Pause");
  103.     }
  104.  
  105.     system("cls");
  106.     system("color 07");
  107.     i=0;j=0; //resetando os valores dos contadores
  108.  
  109.     ////////////////////////////////
  110.  
  111.     do{
  112.         fflush(stdin);
  113.         //mtz_usuario
  114.         printf("  ");
  115.         for(j=0;j<MAX;j++) printf("%d ",j+1); //numerando colunas
  116.         for(i=0;i<MAX;i++){
  117.             printf("\n");
  118.             printf("%d ",i+1); //numerando linhas
  119.             for(j=0;j<MAX;j++){
  120.                 printf("%c ",mtz_nula[i][j]);
  121.             }
  122.         }
  123.         //fim da mtz_usuario
  124.  
  125.  
  126.         printf("\n\nDigite seu palpite:\n");
  127.         printf("Linha: ");
  128.         scanf("%d",&i);
  129.         printf("Coluna: ");
  130.         scanf("%d",&j);
  131.        
  132.             /*nao consegui substituir esse if.
  133.         tentei  if(mtz_nula[i-1][j-1] == 178), mas nao deu certo);*/
  134.         if(mtz_nula[i-1][j-1] != CIMA && mtz_nula[i-1][j-1] != BAIXO && mtz_nula[i-1][j-1] != ESQUERDA && mtz_nula[i-1][j-1] != DIREITA && mtz_nula[i-1][j-1] != '0')
  135.         {
  136.             mtz_nula[i-1][j-1] = mtz[i-1][j-1];
  137.             if(mtz[i-1][j-1] == BAIXO) printf("Que tal tentar um pouco pra baixo?\n");
  138.             else if(mtz[i-1][j-1] == CIMA) printf("Que tal tentar um pouco mais pra cima?\n");
  139.             else if(mtz[i-1][j-1] == DIREITA) printf("Que tal tentar um pouco mais pra direita?\n");
  140.             else if(mtz[i-1][j-1] == ESQUERDA) printf("Que tal tentar um pouco mais pra esquerda?\n");
  141.             else if(mtz[i-1][j-1] == '0') printf("Droga! Daqui nao tem como saber pra onde ir! \n");
  142.             else if(mtz[i-1][j-1] == '@'){
  143.                 win = 1;
  144.                 printf("Parabens, voce ganhou!\n");
  145.             }
  146.  
  147.             if(win==0){
  148.                 tentativas = tentativas-1;
  149.                 if(tentativas == 0){
  150.                     win = 2;
  151.                     printf("Que pena! Voce nao tem mais tentativas!\n");
  152.                 }
  153.                 else printf("\n%d tentativa(s) restante(s)!",tentativas);
  154.             }
  155.         }
  156.         else printf("Tem certeza que voce ja nao tentou ai?");
  157.        
  158.         system("Pause");
  159.         system("cls");
  160.     }while(win==0);
  161.  
  162.     if(win == 1){
  163.         system("Color 37");
  164.         printf("Parabens! Voce foi capaz de encontrar o Olho da Tempestade!\n");
  165.         printf("Gracas aos seus esforcos, essa tempesatade nao voltara a perturba-lo!\n\n\n\n\n");
  166.         printf("//////////////////////////\n");
  167.         printf("//Thank you for playing //\n");
  168.         printf("//Jogo por: Rafael Gibim//\n");
  169.         printf("//////////////////////////\n");
  170.     }
  171.  
  172.     else{
  173.         system("Color 47");
  174.         printf("Essa nao, voce perdeu!\n");
  175.         printf("A tempestade continua a destruir tudo ao seu redor! \n");
  176.         printf("\n\n\n\n\n......O olho da tempestade moveu-se de local.\n");
  177.         printf("Tente novamente! Por favor, nao desista!\n");
  178.     }
  179.  
  180.  
  181.  
  182.     system("Pause");
  183. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement