Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 20.72 KB | None | 0 0
  1. /*
  2.     TRABALHO DE FUNDAMENTOS DE PROGRAMAÇÃO
  3.     ALUNO: CLERISTON CLEBER ROA
  4.     cleristoncr@live.com
  5. */
  6.  
  7. /*******************    CHAMADA DAS BIBLIOTECAS USADAS      *******************/
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <time.h>
  12. /*******************        DECLARAÇÃO DE CONSTANTES    ***********************/
  13. #define SIZE 15
  14. #define nome 25
  15. #define POSICAO 48
  16. /******************* DECLARAÇÃO DAS FUNÇÕES E PROCEDIMENTOS *******************/
  17.  
  18. void boot_and_sortie(char player[nome]);
  19. void Nome(char player[nome]);
  20. void display(char player[nome],
  21.              int Array_player[SIZE][SIZE],
  22.              int Array_computer[SIZE][SIZE],
  23.              int Array_display[SIZE][SIZE],
  24.              int Array_mascara[SIZE][SIZE]);
  25.  
  26. void boot_array(int array[SIZE][SIZE],int zerar);
  27. void sortie_boats(int Array[SIZE][SIZE],int x);
  28. void Maiuscula(char player[nome]);
  29. void play(int Array_display[SIZE][SIZE],int Array_computer[SIZE][SIZE],int *i,int *j,int *pontoP);
  30. void play_pc(int Array_mascara[SIZE][SIZE],int Array_player[SIZE][SIZE],int *i,int *j,int *pontoPC);
  31. void esperar(int segundos);
  32. void sortie_hydro(int Array[SIZE][SIZE],int i,int j);
  33. void sortie_submarine(int Array[SIZE][SIZE],int i,int j);
  34. void sortie_cruiser(int Array[SIZE][SIZE],int i,int j);
  35. void sortie_battleships(int Array[SIZE][SIZE],int i,int j);
  36. void port_plane(int Array[SIZE][SIZE],int i,int j);
  37. int points(int mask[SIZE][SIZE],int template[SIZE][SIZE],int i,int j,int *pontoP);
  38. int shots(int mask[SIZE][SIZE]);
  39. int error(int mask[SIZE][SIZE]);
  40. int wrecks(int pontos,int pontAnteri);
  41. void tip(int array[SIZE][SIZE],int i,int j);
  42. void tipPC(int array[SIZE][SIZE],int i,int j);
  43.  
  44. /*******************        IMPLEMENTAÇÃO DO PROGRAMA       *******************/
  45.  
  46. //FUNÇÃO PRINCIPAL
  47. void main(){
  48.     //DECLARAÇÃO DO NOME DO JOGADOR
  49.     char player[nome];
  50.  
  51.     //FUNÇÃO QUE CAPTURA O NOME DO JOGADOR
  52.     Nome(player);
  53.  
  54.     //FUNÇÃO QUE LEVA O USUARIO AO MENU DE OPÇÕES DO JOGO
  55.     boot_and_sortie(player);
  56.  
  57. }
  58.  
  59. void boot_and_sortie(char player[nome]){
  60.  
  61.     int op,j,i;
  62.     //DECLARAÇÃO DAS MATRIZES USADOS PARA O JOGO
  63.     int Array_player[SIZE][SIZE],//MATRIZ DOS BARCOS DO JOGADOR
  64.         Array_pc[SIZE][SIZE],//MATRIZ DOS BARCOS DO COMPUTADOR
  65.         Array_display[SIZE][SIZE],//MATRIZ QUE FICA AMOSTRA SOBRE A MATRIZ DO COMPUTADOR
  66.         Array_mascara[SIZE][SIZE];//MATRIZ QUE FICA AMOSTRA SOBRE A MATRIZ DO JOGADOR
  67.  
  68.     //FUNÇÃO QUE ZERA A MATRIZ JOGADOR
  69.     boot_array(Array_player,POSICAO);//O 48 INFORMA O COD NA TAB ASCII QUE SERÁ UTILIZADO PARA ZERAR A MATRIZ
  70.     //FUNÇÃO PARA O SORTEIO DOS BARCOS NA MATRIZ JOGADOR
  71.     sortie_boats(Array_player,25);
  72.  
  73.     //FUNÇÃO QUE ZERA A MATRIZ DO COMPUTADOR
  74.     boot_array(Array_pc,POSICAO);//O 48 INFORMA O COD NA TAB ASCII QUE SERÁ UTILIZADO PARA ZERAR A MATRIZ
  75.     //FUNÇÃO PARA O SORTEIO DOS BARCOS NA MATRIZ DO COMPUTADOR
  76.     sortie_boats(Array_pc,50);
  77.  
  78.     //FUNÇÃO PARA ZERAR AS MATRIZES DE MASCARAS, COM OS CARACTERES 219 E 126 RESPECTIVAMENTE
  79.     boot_array(Array_mascara,219);
  80.     boot_array(Array_display,126);
  81.  
  82.     for( i = 0 ; i < SIZE ; i++ ){
  83.         for( j = 0 ; j < SIZE ; j++ ){
  84.  
  85.             if( Array_player[i][j] == POSICAO )
  86.                 Array_mascara[i][j] = 126;
  87.         }
  88.     }
  89.  
  90.     display(player,Array_player,Array_pc,Array_display,Array_mascara);
  91.     fflush(stdin);
  92.  
  93.  
  94. }
  95. void Nome(char player[nome]){//ok
  96.  
  97.     printf("\n\n\n\n");
  98.     printf("\n\t################################################################");
  99.     printf("\n\t################################################################");
  100.     printf("\n\t#####              BEM VINDO AO BATALHA NAVAL              #####");
  101.     printf("\n\t################################################################");
  102.     printf("\n\t################################################################");
  103.     printf("\n\n\t       !!!INFORME O SEU NOME PARA INICIAR O JOGO!!!");
  104.     printf("\n\n\tNOME:--> ");
  105.     gets(player);
  106.     Maiuscula(player);
  107. }
  108. void display(char player[nome],
  109.              int Array_player[SIZE][SIZE],
  110.              int Array_computer[SIZE][SIZE],
  111.              int Array_display[SIZE][SIZE],
  112.              int Array_mascara[SIZE][SIZE]){
  113.  
  114.     int i=0,j=0,move=0,lin=0,col=0,
  115.         pontosPC=0,pontosPlayer=0,pontoAnteriorP=0,pontoAnteriorPC=0,
  116.         disparosPC=0,disparosUSER=0,wreckP=0,wreckPC=0;
  117.     char op='\0';
  118.  
  119.  
  120.     do{
  121.         system("cls");
  122.         printf("\n\t\tTABULEIRO JOGADOR\t\tTABULEIRO COMPUTADOR\n\n\n\n\t");
  123.  
  124.         printf("   ");
  125.         for( i = 0 ; i < SIZE ; i++ ){
  126.             printf(" %c",i+65);
  127.         }
  128.         printf(" | ");
  129.         for( i = 0 ; i < SIZE ; i++ ){
  130.             printf(" %c",i+65);
  131.         }
  132.  
  133.         printf("\n\n\t");
  134.         i=0;
  135.  
  136.         while( i < SIZE ){
  137.             if( i < 9 ){
  138.                 printf(" %d ",i+1);
  139.             }else
  140.                 printf("%d ",i+1);
  141.  
  142.             for( j = 0 ; j < SIZE ; j++ ){
  143.  
  144.                 printf(" %c",Array_mascara[i][j]);
  145.  
  146.             }
  147.             printf(" | ");
  148.             for( j = 0 ; j < SIZE ; j++ ){
  149.  
  150.                 printf(" %c",Array_display[i][j]);
  151.             }
  152.             printf("  %d",i+1);
  153.             printf("\n\t");
  154.             i++;
  155.         }
  156.         printf("\n");
  157.  
  158.         srand(time(NULL));
  159.         printf("\n\tPLAYER: %s\t\t\t\t\tCOMPUTADOR",player);
  160.         printf("\n\tPONTOS: %d\t\t\t\t\tPONTOS DO PC: %d",pontosPlayer,pontosPC);
  161.         printf("\n\tDISPAROS: %d\t\t\t\t\tDISPAROS: %d",disparosUSER,disparosPC);
  162.         printf("\n\tACERTOS: %d\t\t\t\t\tACERTOS: %d ",shots(Array_display),shots(Array_mascara));
  163.         printf("\n\tERROS: %d\t\t\t\t\tERROS: %d",error(Array_display),error(Array_mascara));
  164.  
  165.         if(wrecks(pontosPlayer,pontoAnteriorP)==1){
  166.             wreckP++;
  167.             pontoAnteriorP = pontosPlayer;
  168.         }
  169.         if(wrecks(pontosPC,pontoAnteriorPC)==1){
  170.             wreckPC++;
  171.             pontoAnteriorPC = pontosPC;
  172.         }
  173.         printf("\n\tAFUNDADOS: %d\t\t\t\t\tAFUNDADOS: %d",wreckP,wreckPC);
  174.         printf("\n\n\t\t\tULTIMA COORDENADA JOGADA: (  %d ; %d  )\n",lin, col);
  175.  
  176.         printf("");
  177.  
  178.         if( (move == 0) || (move == 1) || (move == 2) ){
  179.  
  180.             play(Array_display,Array_computer,&i,&j,&pontosPlayer);
  181.             disparosUSER = disparosUSER + 1;
  182.             tip(Array_computer,i,j);
  183.             printf("\n\tPRESSIONE ESC PARA SAIR OU ENTER PARA PROXIMA JOGADA");
  184.             fflush(stdin);
  185.             op = getch();
  186.  
  187.  
  188.         }else{
  189.                 play_pc(Array_mascara,Array_player,&i,&j,&pontosPC);
  190.                 disparosPC = disparosPC + 1;
  191.                 tipPC(Array_player,i,j);
  192.         }
  193.         lin = i+1;
  194.         col = j+1;
  195.  
  196.  
  197.         move += 1;
  198.  
  199.         if( move == 6 ){
  200.             move = 0;
  201.         }
  202.  
  203.  
  204.     }while(op!=27);
  205.  
  206.     if( pontosPlayer > pontosPC ){
  207.         system("cls");
  208.         printf("\n\n\n\n\t\t-----------PARABENS------------------");
  209.         printf("\n\n\n\n\n\n\t\t\tSEUS PONTOS SAO: %d \n\t\t\tVOCE VENCEU",pontosPlayer);
  210.         printf("\n\n\n\n\n");
  211.         exit(1);
  212.         }else {
  213.             system("cls");
  214.             printf("\n\n\n\n\t\t-----------MEUS PESAMES------------------");
  215.             printf("\n\n\n\n\n\n\t\t\tSEUS PONTOS SAO: %d \n\t\t\tVOCE PERDEU",pontosPlayer);
  216.             printf("\n\n\n\n\n");
  217.             exit(1);
  218.  
  219.         }
  220.  
  221.  
  222.  
  223. }
  224. void boot_array(int array[SIZE][SIZE],int zerar){//ok
  225.  
  226.     int i,j;
  227.  
  228.     for( i = 0 ; i < SIZE ; i++ ){
  229.         for( j = 0 ; j < SIZE ; j++ ){
  230.             array[i][j] = zerar;
  231.         }
  232.     }
  233. }
  234. void sortie_boats(int Array[SIZE][SIZE],int x){//ok
  235.  
  236.     int i=0,j=0;
  237.  
  238.     srand(time(NULL) + x);
  239.  
  240.     sortie_hydro(Array,i,j);
  241.     port_plane(Array,i,j);
  242.     sortie_battleships(Array,i,j);
  243.     sortie_cruiser(Array,i,j);
  244.     sortie_submarine(Array,i,j);
  245.  
  246. }
  247. void Maiuscula(char player[nome]){//ok
  248.  
  249.     int i;
  250.  
  251.     for(i=0;player[i]!='\0';i++){
  252.  
  253.         player[i]=toupper(player[i]);
  254.     }
  255. }
  256. void play(int Array_display[SIZE][SIZE],int Array_computer[SIZE][SIZE],int *i,int *j,int *pontoP){//ok
  257.  
  258.         int I,J;
  259.  
  260.         printf("\n\t\t\t!!!!! SUA VEZ !!!!!\n\t\t\t       JOGUE\n");
  261.         printf("\n\tSUA JOGADA ( LINHA ): --> ");
  262.         scanf("%d",&I);
  263.         I=I-1;
  264.  
  265.         printf("\n\tSUA JOGADA ( COLUNA ): --> ");
  266.         scanf("%d",&J);
  267.         J=J-1;
  268.  
  269.  
  270.         if ( Array_computer[I][J] != 48 ){
  271.             Array_display[I][J] = 178;
  272.         }else
  273.             Array_display[I][J] = 88;
  274.  
  275.  
  276.         *pontoP = points(Array_display,Array_computer,I,J,pontoP);
  277.         *i = I;
  278.         *j = J;
  279.  
  280.  
  281.  
  282. }
  283. void play_pc(int Array_mascara[SIZE][SIZE],int Array_player[SIZE][SIZE],int *i,int *j,int *pontoPC ){//ok
  284.  
  285.     int I,J;
  286.     printf("\n\t\t\t!!!!! WAIT !!!!!\n\t\t\tPLAYING COMPUTER");
  287.     esperar(1);
  288.     //ESTE LAÇO GARANTE QUE O COMPUTADOR NAO IRA JOGAR NUMA POSIÇÃO JAH MARCADA
  289.     do{
  290.             I = rand() % SIZE;
  291.             J = rand() % SIZE;
  292.             I -= 1;
  293.             J -= 1;
  294.  
  295.       }while( (Array_mascara[I][J] == 88) || (Array_mascara[I][J] == 0) );
  296.  
  297.     if ( Array_player[I][J] != 48 ){
  298.         Array_mascara[I][J] = 178;
  299.         }else
  300.             Array_mascara[I][J] = 88;
  301.     *pontoPC = points(Array_mascara,Array_player,I,J,pontoPC);
  302.     *i = I;
  303.     *j = J;
  304.  
  305.  
  306. }
  307. void esperar(int segundos){//ok
  308.  
  309.    clock_t cicloFinal;
  310.  
  311.    cicloFinal= clock() + segundos * CLOCKS_PER_SEC; /* Calcula o ciclo final de acordo com os segundos passados. */
  312.    while (clock() < cicloFinal); /* Para quando o ciclo final e atingido. */
  313. }
  314. void sortie_submarine( int Array[SIZE][SIZE],int i,int j){//ok
  315.  
  316.     int plot;
  317.     int aux;
  318.  
  319.     for( aux = 0 ; aux < 4 ; aux++ ){
  320.  
  321.         plot = 0;
  322.  
  323.         do{
  324.  
  325.             i = rand() % SIZE  ;
  326.             j = rand() % SIZE  ;
  327.  
  328.             //VERIFICA SE i E j ESTÃO DENTRO DOS LIMITES DO TABULEIRO
  329.             if( ( i + 1 <= SIZE ) &&
  330.                 ( i - 1 >= 0 )    &&
  331.                 ( j + 1 <= SIZE ) &&
  332.                 ( j - 1 >= 0 )       ){
  333.  
  334.             //A SEGUIR VERIFICAÇÕES PARA A INEXISTENCIA DE BARCOS PROXIMOS
  335.  
  336.                 //VERIFICA AS POSIÇÕES HORIZONTAIS E VERTICAIS
  337.                 if( (Array[i+1][j] == POSICAO) &&
  338.                     (Array[i-1][j] == POSICAO) &&
  339.                     (Array[i][j+1] == POSICAO) &&
  340.                     (Array[i][j-1] == POSICAO) ){
  341.  
  342.                     //VERIFICA AS POSIÇÕES NAS DIAGONAIS, PRIMARIA E SECUNDARIA
  343.                     if( (Array[i+1][j+1] == POSICAO) &&
  344.                         (Array[i-1][j-1] == POSICAO) &&
  345.                         (Array[i+1][j-1] == POSICAO) &&
  346.                         (Array[i-1][j+1] == POSICAO)){
  347.  
  348.                           Array[i][j] = 83;
  349.                           plot = 1;
  350.                     }
  351.                 }
  352.             }
  353.  
  354.  
  355.         }while( plot == 0);
  356.     }
  357.  
  358.  
  359. }
  360. void sortie_cruiser(int Array[SIZE][SIZE],int i,int j){//ok
  361.  
  362.     int plot;
  363.     int aux;
  364.  
  365.     for( aux = 0 ; aux < 3 ; aux++ ){
  366.      plot = 0;
  367.      do{
  368.  
  369.         i = rand() % SIZE ;
  370.         j = rand() % SIZE ;
  371.  
  372.  
  373.         if( ( i + 1 <= SIZE ) && ( i - 1 >= 0 ) && ( j + 1 <= SIZE ) && ( j - 1 >= 0 ) &&
  374.             ( j + 2 <= SIZE ) ){
  375.  
  376.             if( Array[i][j+2] == POSICAO  && Array[i][j-1] == POSICAO ){
  377.  
  378.                 if( Array[i+1][j] == POSICAO && Array[i+1][j-1] == POSICAO &&
  379.                     Array[i+1][j+1] == POSICAO && Array[i+1][j+2] == POSICAO ){
  380.  
  381.                     if( Array[i-1][j] == POSICAO && Array[i-1][j-1] == POSICAO &&
  382.                         Array[i-1][j+1] == POSICAO && Array[i-1][j+2] == POSICAO ){
  383.  
  384.                             Array[i][j] = 67;
  385.                             Array[i][j+1] = 67;
  386.                             plot = 1;
  387.  
  388.                         }
  389.                     }
  390.                 }
  391.             }
  392.  
  393.      }while( plot == 0);
  394.     }
  395. }
  396. void sortie_battleships(int Array[SIZE][SIZE],int i,int j){//ok
  397.  
  398.     int plot;
  399.     int aux;
  400.  
  401.     for( aux = 0 ; aux < 2 ; aux++ ){
  402.  
  403.         plot = 0;
  404.         do{
  405.  
  406.             i = rand() % SIZE;
  407.             j = rand() % SIZE;
  408.  
  409.             if( ( i + 1 <= SIZE ) && ( i - 1 >= 0 ) && ( j + 1 <= SIZE ) && ( j - 1 >= 0 ) &&
  410.                 ( j + 4 <= SIZE ) ){
  411.  
  412.                 if( Array[i][j-1] == POSICAO  && Array[i][j+3] == POSICAO ){
  413.  
  414.                     if( Array[i+1][j-1] == POSICAO && Array[i+1][j] == POSICAO &&
  415.                         Array[i+1][j+1] == POSICAO && Array[i+1][j+2] == POSICAO &&
  416.                         Array[i+1][j+3] == POSICAO ){
  417.  
  418.                         if( Array[i-1][j-1] == POSICAO && Array[i-1][j] == POSICAO &&
  419.                             Array[i-1][j+1] == POSICAO && Array[i-1][j+2] == POSICAO &&
  420.                             Array[i-1][j+3] == POSICAO ){
  421.  
  422.  
  423.  
  424.                                 Array[i][j] = 66;
  425.                                 Array[i][j+1] = 66;
  426.                                 Array[i][j+2] = 66;
  427.                                 Array[i][j+3] = 66;
  428.                                 plot = 1;
  429.  
  430.                         }
  431.                     }
  432.                 }
  433.             }
  434.         }while( plot == 0);
  435.     }
  436. }
  437. void sortie_hydro(int Array[SIZE][SIZE],int i,int j){//ok
  438.  
  439.     int plot;
  440.     int aux;
  441.     for( aux = 0 ; aux < 5 ; aux++ ){
  442.  
  443.         plot = 0;
  444.         do{
  445.  
  446.             i = rand() % SIZE ;
  447.             j = rand() % SIZE ;
  448.  
  449.             if( ( i + 1 < SIZE ) && ( i - 1 > 0 ) && ( j + 1 < SIZE ) && ( j - 1 > 0 ) &&
  450.             (( j + 2 < SIZE ) || (j - 2 > 0) )){
  451.  
  452.                if( (Array[i+1][j-2] == POSICAO) && (Array[i+1][j-1] == POSICAO) &&
  453.                    (Array[i+1][j] == POSICAO) && (Array[i+1][j+1] == POSICAO) &&
  454.                    (Array[i+1][j+2] == POSICAO) ){
  455.  
  456.                         if( (Array[i-1][j-2] == POSICAO) && (Array[i-1][j-1] == POSICAO) &&
  457.                             (Array[i-1][j+1] == POSICAO) && (Array[i-1][j+2] == POSICAO) ){
  458.  
  459.                                 if( (Array[i-2][j-2] == POSICAO) && (Array[i-2][j-1] == POSICAO) &&
  460.                                     (Array[i-2][j] == POSICAO) && (Array[i-2][j+1] == POSICAO) &&
  461.                                     (Array[i-2][j+2] == POSICAO) ){
  462.  
  463.                                         if( (Array[i][j-2] == POSICAO) && (Array[i][j+2] == POSICAO)){
  464.  
  465.                                             Array[i][j-1] = 72;
  466.                                             Array[i][j+1] = 72;
  467.                                             Array[i-1][j] = 72;
  468.                                             plot = 1;
  469.  
  470.                                             }
  471.                                     }
  472.                             }
  473.                     }
  474.             }
  475.  
  476.         }while( plot == 0 );
  477.     }
  478. }
  479. void port_plane(int Array[SIZE][SIZE],int i,int j){//ok
  480.  
  481.     int plot;
  482.     int aux;
  483.  
  484.     for( aux = 0 ; aux < 1 ; aux++ ){
  485.  
  486.          plot = 0;
  487.          do{
  488.  
  489.             i = rand() % SIZE;
  490.             j = rand() % SIZE;
  491.  
  492.             if( ( i + 1 <= SIZE ) && ( i - 1 >= 0 ) && ( j + 1 <= SIZE ) && ( j - 1 >= 0 ) &&
  493.                 ( j + 5 <= SIZE ) ){
  494.  
  495.                 if( Array[i][j-1] == POSICAO && Array[i][j+4] == POSICAO ){
  496.  
  497.                     if( Array[i+1][j-1] == POSICAO && Array[i+1][j] == POSICAO &&
  498.                         Array[i+1][j+1] == POSICAO && Array[i+1][j+2] == POSICAO &&
  499.                         Array[i+1][j+3] == POSICAO && Array[i+1][j+4] == POSICAO ){
  500.  
  501.                         if( Array[i-1][j-1] == POSICAO && Array[i-1][j] == POSICAO &&
  502.                             Array[i-1][j+1] == POSICAO && Array[i-1][j+2] == POSICAO &&
  503.                             Array[i-1][j+3] == POSICAO && Array[i-1][j+4] == POSICAO ){
  504.  
  505.  
  506.  
  507.                                 Array[i][j] = 80;
  508.                                 Array[i][j+1] = 80;
  509.                                 Array[i][j+2] = 80;
  510.                                 Array[i][j+3] = 80;
  511.                                 Array[i][j+4] = 80;
  512.                                 plot = 1;
  513.  
  514.                         }
  515.                     }
  516.                 }
  517.             }
  518.  
  519.         }while( plot == 0);
  520.     }
  521. }
  522. int points(int mask[SIZE][SIZE],int template[SIZE][SIZE],int i,int j,int *pontoP){//ok
  523.  
  524.         int B=0,
  525.             C=0,
  526.             P=0,
  527.             S=0,
  528.             H=0;
  529.  
  530.         if ( (template[i][j] == 83) ){
  531.  
  532.                 S = S + 2;
  533.             }
  534.  
  535.         if ( (template[i][j] == 67) && ( (mask[i][j-1] == 178) || ( mask[i][j+1] == 178 ) ) ) {
  536.  
  537.                 C = C + 5;
  538.             }
  539.  
  540.         if ( (template[i][j] == 66) && ( (mask[i][j-1] == 178) || (mask[i][j+1] == 178) ) &&
  541.                                        ( (mask[i][j-2] == 178) || (mask[i][j+2] == 178) ) &&
  542.                                        ( (mask[i][j-3] == 178) || (mask[i][j+3] == 178) ) ){
  543.  
  544.                 B = B + 10;
  545.             }
  546.  
  547.         if ( (template[i][j] == 80) && ( (mask[i][j-1] == 178) || (mask[i][j+1] == 178) ) &&
  548.                                        ( (mask[i][j-2] == 178) || (mask[i][j+2] == 178) ) &&
  549.                                        ( (mask[i][j-3] == 178) || (mask[i][j+3] == 178) ) &&
  550.                                        ( (mask[i][j-4] == 178) || (mask[i][j+4] == 178) ) ){
  551.  
  552.                 P = P + 20;
  553.             }
  554.         if ( (template[i][j] == 72) && ( ( (mask[i][j-2] == 178) || (mask[i][j+2] == 178) ) &&
  555.                                        ( (mask[i-1][j-1] == 178) || (mask[i-1][j+1] == 178) ) ) &&
  556.                                                 ( (mask[i+1][j-1] == 178) || (mask[i+1][j+1] == 178) ) ){
  557.                 H = H + 1;
  558.  
  559.             }
  560.         *pontoP = *pontoP + S + B + C + P + H;
  561.  
  562.         return *pontoP;
  563.  
  564.  
  565. }
  566. int shots(int mask[SIZE][SIZE]){
  567.  
  568.     int i,j,cont=0;
  569.  
  570.     for( i = 0 ; i < SIZE ; i++ ){
  571.  
  572.         for( j = 0 ; j < SIZE ; j++ ){
  573.  
  574.             if( mask[i][j] == 178 ){
  575.  
  576.                 cont++;
  577.             }
  578.         }
  579.     }
  580.     return cont;
  581.  
  582. }
  583. int error(int mask[SIZE][SIZE]){
  584.     int i,j,cont=0;
  585.  
  586.     for(i=0;i<SIZE;i++){
  587.  
  588.         for(j=0;j<SIZE;j++){
  589.  
  590.             if( mask[i][j] == 88){
  591.  
  592.                 cont++;
  593.             }
  594.         }
  595.     }
  596.     return cont;
  597.  
  598. }
  599. int wrecks(int pontos,int pontAnteri){//ok
  600.  
  601.     if( pontos - pontAnteri == 2 )
  602.         return 1;
  603.         else if( pontos - pontAnteri == 5 )
  604.             return 1;
  605.             else if( pontos - pontAnteri == 10 )
  606.                 return 1;
  607.                 else if( pontos - pontAnteri == 20 )
  608.                     return 1;
  609.                     else if( pontos - pontAnteri == 1 )
  610.                         return 1;
  611.  
  612.     return 0;
  613.  
  614. }
  615. void tip(int array[SIZE][SIZE],int i,int j){
  616.  
  617.     if( array[i][j] == 83 ){
  618.         printf("\n\n\n");
  619.         printf("\a\a\a");
  620.         printf("\n\t\t\t!!! VOCE ACERTOU UM SUBMARINO !!!");
  621.         printf("\n\n\n");
  622.         esperar(2);
  623.     }else if( array[i][j] == 67 ){
  624.         printf("\n\n\n");
  625.         printf("\a\a\a");
  626.         printf("\n\t\t\t!!! VOCE ACERTOU UM CRUZADOR !!!");
  627.         printf("\n\n\n");
  628.         esperar(2);
  629.         }else if( array[i][j] == 66 ){
  630.             printf("\n\n\n");
  631.             printf("\a\a\a");
  632.             printf("\n\t\t\t!!! VOCE ACERTOU UM ENCOURRACADO !!!");
  633.             printf("\n\n\n");
  634.             esperar(2);
  635.             }else if( array[i][j] == 80 ){
  636.                 printf("\n\n\n");
  637.                 printf("\a\a\a");
  638.                 printf("\n\t\t\t!!! VOCE ACERTOU UM PORTA-AVIOES !!!");
  639.                 printf("\n\n\n");
  640.                 esperar(2);
  641.                 }else if( array[i][j] == 72 ){
  642.                     printf("\n\n\n");
  643.                     printf("\a\a\a");
  644.                     printf("\n\t\t\t!!! VOCE ACERTOU UM HIDRO-AVIAO !!!");
  645.                     printf("\n\n\n");
  646.                     esperar(2);
  647.                     }
  648.  
  649. }
  650. void tipPC(int array[SIZE][SIZE],int i,int j){
  651.  
  652.     if( array[i][j] == 83 ){
  653.         printf("\n\n\n");
  654.         printf("\a\a\a");
  655.         printf("\n\t\t\t!!! COMPUTADOR ACERTOU UM SUBMARINO !!!");
  656.         printf("\n\n\n");
  657.         esperar(2);
  658.     }else if( array[i][j] == 67 ){
  659.         printf("\n\n\n");
  660.         printf("\a\a\a");
  661.         printf("\n\t\t\t!!! COMPUTADOR ACERTOU UM CRUZADOR !!!");
  662.         printf("\n\n\n");
  663.         esperar(2);
  664.         }else if( array[i][j] == 66 ){
  665.             printf("\n\n\n");
  666.             printf("\a\a\a");
  667.             printf("\n\t\t\t!!! COMPUTADOR ACERTOU UM ENCOURRACADO !!!");
  668.             printf("\n\n\n");
  669.             esperar(2);
  670.             }else if( array[i][j] == 80 ){
  671.                 printf("\n\n\n");
  672.                 printf("\a\a\a");
  673.                 printf("\n\t\t\t!!! COMPUTADOR ACERTOU UM PORTA-AVIOES !!!");
  674.                 printf("\n\n\n");
  675.                 esperar(2);
  676.                 }else if( array[i][j] == 72 ){
  677.                     printf("\n\n\n");
  678.                     printf("\a\a\a");
  679.                     printf("\n\t\t\t!!! COMPUTADOR ACERTOU UM HIDRO-AVIAO !!!");
  680.                     printf("\n\n\n");
  681.                     esperar(2);
  682.                     }
  683.  
  684. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement