Snake programado em C
Autor: Marco Antônio | Publicado: 2014-11-18T12:35:00-08:00

//Snake - Jogo implementado com funcionalidades em C

//VERSÃO TESTES PARA SER EXECUTADA NO CONSOLE
//Jogo Snake

#include #include "stdlib.h." //Define o valor da constante RAND_MAX -&gt; rand() produz um valor entre 0 e RAND_MAX#include #include //______________________________________________________________________________//DECLARAÇÃO DAS VARIÁVEIS GLOBAISunsigned int matriz[8][8]; //tabuleirounsigned int *zeros[64],*snake[64],*cresce[64]; //vetores de ponteiros que indicará as casas vaziasunsigned int i,j,k,score,cont,contazeros,lugar,size,headline,headcol; //variáveis de operação da matriz//______________________________________________________________________________//DECLARAÇÃO DE FUNÇÕES//ENCONTRA ESPAÇO VAZIO E GERA NOVO PONTOvoid gerafruta(void) //Procura espaços vazios na matriz{&nbsp;&nbsp;&nbsp; contazeros=0;&nbsp;&nbsp;&nbsp; for (i=0;i<8 br="" i="">&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(j=0;j<8 br="" j="">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (matriz[i][j]==0) //Encontra os espaços vazios na matriz&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; zeros[contazeros] = &amp;matriz[i][j];&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; contazeros++;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (contazeros&gt;0)&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lugar = rand()%contazeros; //gera um valor aleatório (0 a contazeros-1)&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *zeros[lugar] = 2; //zeros[lugar] = endereço da matriz onde foi criada a nova fruta&nbsp;&nbsp;&nbsp; }/*Na funçao acima, foi criado um vetor de ponteiros.No vetor zeros[] são armazenados os endereços de memoria dos zeros da matrizA função rand() gera um número entre zero e RAND_MAX (definido na biblioteca stdlib.h,com o valor de 0x3fffffff no caso desse programa) e o operador % devolve o resto da divisão (para um valor x temos x%3 = 0, 1 ou 2)A variável lugar gera um número aleatorio dentre as posiçoes do vetor de zerosPor fim o LED correspondente ao espaço da matriz é ligado*/}//FUNÇAO IMPRIME MATRIZvoid imprime(void){&nbsp; system("cls"); //Limpa a tela&nbsp; for (i=0;i<8 br="" i="">&nbsp; {&nbsp; &nbsp;&nbsp;&nbsp; for(j=0;j<8 br="" j="">&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf(" %d ",matriz[i][j]);&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; printf("\n\n");&nbsp; }}//FUNÇÃO UPvoid up(void){&nbsp;&nbsp;&nbsp; if (headline==0) {} //se a cobra estiver na borda superior dá gameover - a condição de baixo nao entrou junto no if pois se a headline ja fosse zero ficaria matriz[-1] e daria erro&nbsp;&nbsp;&nbsp; else if (matriz[headline-1][headcol]==1 &amp;&amp; snake[0]!=&amp;matriz[headline-1][headcol]) {} //se o proximo destino colidir com corpo (menos a cauda) da cobra -&gt; gameover&nbsp;&nbsp;&nbsp; else if (matriz[headline-1][headcol]==1 &amp;&amp; snake[0]==&amp;matriz[headline-1][headcol] &amp;&amp; snake[0]==cresce[0] &amp;&amp; cont&gt;0) {}&nbsp; //caso particular em que a cobra irá crescer, assim ocorre colisao com a cauda -&gt; gameover&nbsp;&nbsp;&nbsp; else if (snake[size-2]==&amp;matriz[headline-1][headcol]) {} //se a cobra tentar retornar sobre si mesmo a jogada será invalida - Se (proximo local = pescoço da cobra) -&gt; jogada invalida&nbsp;&nbsp;&nbsp; else&nbsp;&nbsp;&nbsp; {&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; headline--; //desloca uma linha para cima&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (snake[0]==cresce[0] &amp;&amp; cont&gt;0) //QUANDO A COBRA DEVE CRESCER - quando a fruta engolida estiver no ultimo segmento da cobra e o contador de frutas engolidas for maior que 0 (caso contrario cresceria passando novamente pelo mesmo local mesmo que sem fruta)&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; size++;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cont--;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (i=0;i&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cresce[i]=cresce[i+1]; //desloca para a esquerda o vetor de crescimento - para o caso de mais de uma fruta engolida e nao digerida&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else //QUANDO A COBRA NAO PRECISA CRESCER&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *snake[0] = 0; //apaga o ultimo ponto da cobra&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (i=0;i&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; snake[i] = snake[i+1]; //movimenta a cobra&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *snake[i] = 1;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; snake[size-1] = &amp;matriz[headline][headcol]; //snake[size-1] recebe o novo endereço da cabeça da cobra&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *snake[size-1] = 1; //escreve 1 no endereço&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (snake[size-1]==zeros[lugar]) //SE A COBRA ENGOLIR UMA NOVA FRUTA - se o endereço da fruta e da cabeça da cobra forem o mesmo&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; score++;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cresce[cont]=zeros[lugar]; //vetor cresce recebe o endereço da fruta engolida&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cont++; //novo espaço para guardar mais um endereço de fruta engolida&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; gerafruta();&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; imprime();&nbsp;&nbsp;&nbsp; }}//FUNÇÃO DOWNvoid down(void){&nbsp;&nbsp;&nbsp; if (headline==7) {} //se a cobra estiver na borda inferior dá gameover&nbsp;&nbsp;&nbsp; else if (matriz[headline+1][headcol]==1 &amp;&amp; snake[0]!=&amp;matriz[headline+1][headcol]) {} //se o proximo destino colidir com corpo (menos a cauda) da cobra -&gt; gameover&nbsp;&nbsp;&nbsp; else if (matriz[headline+1][headcol]==1 &amp;&amp; snake[0]==&amp;matriz[headline+1][headcol] &amp;&amp; snake[0]==cresce[0] &amp;&amp; cont&gt;0) {} //caso particular em que a cobra irá crescer, assim ocorre colisao com a cauda -&gt; gameover&nbsp;&nbsp;&nbsp; else if (snake[size-2]==&amp;matriz[headline+1][headcol]) {} //se a cobra tentar retornar sobre si mesmo a jogada será invalida - Se (proximo local = pescoço da cobra) -&gt; jogada invalida&nbsp;&nbsp;&nbsp; else&nbsp;&nbsp;&nbsp; {&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; headline++; //desloca uma linha para baixo&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (snake[0]==cresce[0] &amp;&amp; cont&gt;0) //QUANDO A COBRA DEVE CRESCER - quando a fruta engolida estiver no ultimo segmento da cobra&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; size++;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cont--;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (i=0;i&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cresce[i]=cresce[i+1]; //desloca para a esquerda o vetor de crescimento - para o caso de mais de uma fruta engolida e nao digerida&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else //QUANDO A COBRA NAO PRECISA CRESCER&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *snake[0] = 0; //apaga o ultimo ponto da cobra&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (i=0;i&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; snake[i] = snake[i+1]; //movimenta a cobra&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *snake[i] = 1;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; snake[size-1] = &amp;matriz[headline][headcol]; //snake[size-1] recebe o novo endereço da cabeça da cobra&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *snake[size-1] = 1; //escreve 1 no endereço&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (snake[size-1]==zeros[lugar]) //SE A COBRA ENGOLIR UMA NOVA FRUTA - se o endereço da fruta e da cabeça da cobra forem o mesmo&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; score++;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cresce[cont]=zeros[lugar]; //vetor cresce recebe o endereço da fruta engolida&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cont++; //novo espaço para guardar mais um endereço de fruta engolida&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; gerafruta();&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; imprime();&nbsp;&nbsp;&nbsp; }}//FUNÇÃO LEFTvoid left(void){&nbsp;&nbsp;&nbsp; if (headcol==0) {} //se a cobra estiver na borda inferior -&gt; gameover&nbsp;&nbsp;&nbsp; else if (matriz[headline][headcol-1]==1 &amp;&amp; snake[0]!=&amp;matriz[headline][headcol-1]) {} //se o proximo destino colidir com corpo (menos a cauda) da cobra -&gt; gameover&nbsp;&nbsp;&nbsp; else if (matriz[headline][headcol-1]==1 &amp;&amp; snake[0]==&amp;matriz[headline][headcol-1] &amp;&amp; snake[0]==cresce[0] &amp;&amp; cont&gt;0) {} //caso particular em que a cobra irá crescer, assim ocorre colisao com a cauda -&gt; gameover&nbsp;&nbsp;&nbsp; else if (snake[size-2]==&amp;matriz[headline][headcol-1]) {} //se a cobra tentar retornar sobre si mesmo a jogada será invalida - Se (proximo local = pescoço da cobra) -&gt; jogada invalida&nbsp;&nbsp;&nbsp; else&nbsp;&nbsp;&nbsp; {&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; headcol--; //desloca uma coluna para esquerda&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (snake[0]==cresce[0] &amp;&amp; cont&gt;0) //QUANDO A COBRA DEVE CRESCER - quando a fruta engolida estiver no ultimo segmento da cobra&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; size++;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cont--;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (i=0;i&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cresce[i]=cresce[i+1]; //desloca para a esquerda o vetor de crescimento - para o caso de mais de uma fruta engolida e nao digerida&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else //QUANDO A COBRA NAO PRECISA CRESCER&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *snake[0] = 0; //apaga o ultimo ponto da cobra&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (i=0;i&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; snake[i] = snake[i+1]; //movimenta a cobra&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *snake[i] = 1;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; snake[size-1] = &amp;matriz[headline][headcol]; //snake[size-1] recebe o novo endereço da cabeça da cobra&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *snake[size-1] = 1; //escreve 1 no endereço&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (snake[size-1]==zeros[lugar]) //SE A COBRA ENGOLIR UMA NOVA FRUTA - se o endereço da fruta e da cabeça da cobra forem o mesmo&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; score++;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cresce[cont]=zeros[lugar]; //vetor cresce recebe o endereço da fruta engolida&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cont++; //novo espaço para guardar mais um endereço de fruta engolida&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; gerafruta();&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; imprime();&nbsp;&nbsp;&nbsp; }}//FUNÇÃO RIGHTvoid right(void){&nbsp;&nbsp;&nbsp; if (headcol==7) {} //se a cobra estiver na borda inferior dá gameover&nbsp;&nbsp;&nbsp; else if (matriz[headline][headcol+1]==1 &amp;&amp; snake[0]!=&amp;matriz[headline][headcol+1]) {} //se o proximo destino colidir com corpo (menos a cauda) da cobra -&gt; gameover&nbsp;&nbsp;&nbsp; else if (matriz[headline][headcol+1]==1 &amp;&amp; snake[0]==&amp;matriz[headline][headcol+1] &amp;&amp; snake[0]==cresce[0] &amp;&amp; cont&gt;0) {} //caso particular em que a cobra irá crescer, assim ocorre colisao com a cauda -&gt; gameover&nbsp;&nbsp;&nbsp; else if (snake[size-2]==&amp;matriz[headline][headcol+1]) {} //se a cobra tentar retornar sobre si mesmo a jogada será invalida - Se (proximo local = pescoço da cobra) -&gt; jogada invalida&nbsp;&nbsp;&nbsp; else&nbsp;&nbsp;&nbsp; {&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; headcol++; //desloca uma coluna para direita&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (snake[0]==cresce[0] &amp;&amp; cont&gt;0) //QUANDO A COBRA DEVE CRESCER - quando a fruta engolida estiver no ultimo segmento da cobra&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; size++;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cont--;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (i=0;i&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cresce[i]=cresce[i+1]; //desloca para a esquerda o vetor de crescimento - para o caso de mais de uma fruta engolida e nao digerida&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else //QUANDO A COBRA NAO PRECISA CRESCER&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *snake[0] = 0; //apaga o ultimo ponto da cobra&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (i=0;i&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; snake[i] = snake[i+1]; //movimenta a cobra&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *snake[i] = 1;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; snake[size-1] = &amp;matriz[headline][headcol]; //snake[size-1] recebe o novo endereço da cabeça da cobra&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *snake[size-1] = 1; //escreve 1 no endereço&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (snake[size-1]==zeros[lugar]) //SE A COBRA ENGOLIR UMA NOVA FRUTA - se o endereço da fruta e da cabeça da cobra forem o mesmo&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; score++;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cresce[cont]=zeros[lugar]; //vetor cresce recebe o endereço da fruta engolida&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cont++; //novo espaço para guardar mais um endereço de fruta engolida&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; gerafruta();&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; imprime();&nbsp;&nbsp;&nbsp; }}int main () //Programa{&nbsp; //INICIALIZA MATRIZ VETORES E VARIAVEIS&nbsp; i=0;j=0;k=0;score=0;cont=0;contazeros=0;lugar=0;size=0;headline=0;headcol=0;&nbsp; for (i=0;i<8 br="" i="">&nbsp; {&nbsp;&nbsp;&nbsp; for (j=0;j<8 br="" j="">&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; matriz[i][j]=0;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; zeros[k]=0;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; snake[k]=0;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cresce[k]=0;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; k++;&nbsp;&nbsp;&nbsp; }&nbsp; }&nbsp; &nbsp;&nbsp;&nbsp; //É POSSIVEL USAR OS COMANDOS ABAIXO NO LUGAR DE time(NULL)&nbsp;&nbsp;&nbsp; //time_t t;&nbsp;&nbsp;&nbsp; //srand((unsigned) time(&amp;t)); &nbsp; srand( (unsigned)time(NULL) );&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* srand(time(NULL)) alimenta a função rand com uma semente de tempo&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; A função time(NULL) é calculado corresponde ao total de segundos&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; passados desde 1 de janeiro de 1970 até a data atual.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Desta forma, a cada execução o valor da "semente" será diferente.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; */&nbsp; printf("\nBem vindo ao jogo Snake - UNIVERSIDADE FEDERAL DO PARANA - RIBAS");&nbsp; printf("\n\nManda ver ae nas tecla A S D W (nao aperta em outras que o jogo buga, valeu!)\n\n");&nbsp; &nbsp; printf("\n\n---------NAO EH PARA USAR AS SETAS------------------ A S D W!!!!!)\n\n");&nbsp; &nbsp; printf("\n\nSE ESTIVER NO CAPSLOCK NAO FUNCIONA)\n\n");&nbsp; printf("\n\nPRESSIONE UMA TECLA PARA INICIAR");&nbsp; matriz[5][1] = 1;&nbsp; snake[0] = &amp;matriz[5][1];&nbsp; matriz[5][2] = 1;&nbsp; snake[1] = &amp;matriz[5][2];&nbsp; matriz[5][3] = 1;&nbsp; snake[2] = &amp;matriz[5][3];&nbsp; headline=5;&nbsp; headcol=3;&nbsp; size=3;&nbsp; getch();&nbsp; system("cls");&nbsp; printf("\n\n");&nbsp; gerafruta();&nbsp; imprime();&nbsp; do&nbsp; {&nbsp;&nbsp;&nbsp; //RECEBE OS COMANDOS DO TECLADO E EXECUTA AS FUNÇÕES&nbsp;&nbsp;&nbsp; switch(getch())&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 'w':&nbsp;&nbsp;&nbsp; // key up&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; up();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 's':&nbsp;&nbsp;&nbsp; // key down&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; down();&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 'd':&nbsp;&nbsp;&nbsp; // key right&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; right();&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 'a':&nbsp;&nbsp;&nbsp; // key left&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; left();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf("\n Score -&gt; %d ",score);&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf("\n tamanho da cobra -&gt; %d ",size);&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf("\n cabeça da cobra - &gt; %d ",snake[size-1]);&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf("\n rabo da cobra - &gt; %d ",snake[0]);&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf("\n Endereço da última fruta criada -&gt; %d ",zeros[lugar]);&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf("\n Contador de frutas engolidas e nao digeridas -&gt; %d ",cont);&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf("\n endereço da ultima fruta engolida -&gt; %d ",cresce[0]);} while (size<30 br="">&nbsp;&nbsp;&nbsp; printf("\n\nGAME OVER! THANKS FOR PLAYING");&nbsp;&nbsp;&nbsp; getch();&nbsp;&nbsp;&nbsp; getch();&nbsp;&nbsp;&nbsp; getch();}<!--30--><!--8--><!--8--><!--30--><!--8--><!--8--><!--30--><!--8--><!--8--><!--30--><!--8--><!--8--><!--8--><!--8--><!--8--><!--8--><!--8--><!--8--><!--8--><!--8--><!--8--><!--8--><!--8--><!--8--><!--8--><!--8--><!--8--><!--8-->