Last active
November 17, 2024 17:41
-
-
Save rkTinelli/be533edabf44e13e6366549081d10897 to your computer and use it in GitHub Desktop.
Revisions
-
rkTinelli revised this gist
Oct 24, 2017 . No changes.There are no files selected for viewing
-
rkTinelli revised this gist
Oct 17, 2017 . 6 changed files with 104 additions and 16 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,6 @@ #ifndef _FOGEFOGE_H_ #define _FOGEFOGE_H_ #define CIMA 'w' #define BAIXO 's' #define DIREITA 'd' @@ -12,3 +15,5 @@ int paraondefantasmavai (int xatual, int yatual, void explodepilula(); void explodepilula2 (int x, int y, int somax, int somay, int qtd); int acabou(); #endif This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,14 +3,19 @@ #include <time.h> #include "foge.h" #include "mapa.h" #include "ui.h" MAPA m; POSICAO heroi; int tempilula = 0; int acabou(){ POSICAO pos; int perdeu = !encontra_no_mapa(&m,&pos,HEROI); int ganhou = !encontra_no_mapa(&m,&pos,FANTASMA); return ganhou || perdeu; } int ehdirecao (char comando){ @@ -140,19 +145,16 @@ int main(){ do{ printf("Pilula: %s\n", (tempilula ? "SIM" : "NAO")); imprime_mapa(&m); printf("Qual seu comando? (a/w/s/d)\n"); char comando; scanf(" %c",&comando); //espaço em branco para ENTER ser ignorado if (ehdirecao(comando)) move_pers(comando); if (comando == BOMBA) explodepilula(); fantasma(); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -55,14 +55,6 @@ void libera_mapa(MAPA* m){ free(m->mapa); } int ehvalida (MAPA* m, int x, int y){ if (x>=m->linhas || y>=m->colunas) return 0; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,6 @@ #ifndef _MAPA_H_ #define _MAPA_H_ #define HEROI '@' #define FANTASMA 'F' #define PILULA 'P' @@ -33,4 +36,6 @@ int ehpersonagem(MAPA* m,char personagem,int x,int y); int pode_andar(MAPA* m, char personagem , int x, int y); void andanomapa (MAPA* m, int xorigem, int yorigem, int xdestino, int ydestino); void copiamapa (MAPA* destino, MAPA* origem); #endif This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,75 @@ #include <stdio.h> #include "mapa.h" char desenhoparede[4][7] = { {"......" }, {"......" }, {"......" }, {"......" } }; char desenhofantasma[4][7] = { {" .-. " }, {"| OO| " }, {"| | " }, {"'^^^' " } }; char desenhoheroi[4][7] = { {" .--. " }, {"/ _.-'" }, {"\\ '-." }, {" '--' " } }; char desenhopilula[4][7] = { {" "}, {" .-. "}, {" '-' "}, {" "} }; char desenhovazio[4][7] = { {" "}, {" "}, {" "}, {" "} }; void imprimeparte(char desenho[4][7], int parte) { printf("%s", desenho[parte]); } void imprime_mapa(MAPA* m) { int i; for( i = 0; i < m->linhas; i++) { int parte; for( parte = 0; parte < 4; parte++) { int j; for( j = 0; j < m->colunas; j++) { switch(m->mapa[i][j]) { case FANTASMA: imprimeparte(desenhofantasma, parte); break; case HEROI: imprimeparte(desenhoheroi, parte); break; case PILULA: imprimeparte(desenhopilula, parte); break; case PAREDE_VERTICAL: case PAREDE_HORIZONTAL: imprimeparte(desenhoparede, parte); break; case VAZIO: imprimeparte(desenhovazio, parte); break; } } printf("\n"); } } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ #ifndef _UI_H_ #define _UI_H_ #include "mapa.h" void imprimeparte(char desenho[4][7], int parte); void imprime_mapa(MAPA* m); #endif -
rkTinelli revised this gist
Oct 17, 2017 . 3 changed files with 27 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,5 +9,6 @@ int ehdirecao (char comando); void fantasma(); int paraondefantasmavai (int xatual, int yatual, int* xdestino, int*ydestino); void explodepilula(); void explodepilula2 (int x, int y, int somax, int somay, int qtd); int acabou(); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -48,7 +48,7 @@ void move_pers(char comando){ return; if (ehpersonagem(&m, PILULA, prox_x, prox_y)) tempilula=1; andanomapa(&m, heroi.x, heroi.y, prox_x, prox_y); @@ -108,8 +108,29 @@ int paraondefantasmavai (int xatual, int yatual, } void explodepilula (){ if (!tempilula) return; explodepilula2(heroi.x, heroi.y, 0,1,3); explodepilula2(heroi.x, heroi.y, 0,-1,3); explodepilula2(heroi.x, heroi.y, 1,0,3); explodepilula2(heroi.x, heroi.y, -1,0,3); tempilula=0; } void explodepilula2 (int x, int y, int somax, int somay, int qtd){ if (qtd == 0) return; int novox = x + somax; int novoy = y + somay; if (!ehvalida(&m, novox, novoy)) return; if (ehparede(&m, novox, novoy)) return; m.mapa[novox][novoy] = VAZIO; explodepilula2(novox, novoy, somax, somay, qtd - 1); } int main(){ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -112,4 +112,3 @@ void copiamapa (MAPA* destino, MAPA* origem){ strcpy(destino->mapa[i], origem->mapa[i]); } } -
rkTinelli revised this gist
Oct 10, 2017 . 5 changed files with 24 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,10 +2,12 @@ #define BAIXO 's' #define DIREITA 'd' #define ESQUERDA 'a' #define BOMBA 'b' void move_pers(char comando); int ehdirecao (char comando); void fantasma(); int paraondefantasmavai (int xatual, int yatual, int* xdestino, int*ydestino); void explodepilula (); int acabou(); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,6 +6,7 @@ MAPA m; POSICAO heroi; int tempilula = 0; int acabou(){ POSICAO pos; @@ -46,6 +47,9 @@ void move_pers(char comando){ if (!pode_andar(&m, HEROI, prox_x, prox_y)) return; if (ehpersonagem(&m, PILULA, prox_x, prox_y)) tempilula++; andanomapa(&m, heroi.x, heroi.y, prox_x, prox_y); heroi.x = prox_x; @@ -103,23 +107,36 @@ int paraondefantasmavai (int xatual, int yatual, return 0; } void explodepilula (){ printf("Uma bomba foi explodida ! \n"); tempilula--; } int main(){ le_mapa(&m); encontra_no_mapa(&m, &heroi, HEROI); do{ if (tempilula>0){ printf("Voce possui %d pilulas de poder!\n", tempilula); } imprime_mapa(&m); printf("Qual seu comando? (a/w/s/d)\n"); char comando; scanf(" %c",&comando); //espaço em branco para ENTER ser ignorado move_pers(comando); if (comando == BOMBA) explodepilula(); fantasma(); } while (!acabou()); libera_mapa(&m); return 0; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -112,3 +112,4 @@ void copiamapa (MAPA* destino, MAPA* origem){ strcpy(destino->mapa[i], origem->mapa[i]); } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,6 @@ #define HEROI '@' #define FANTASMA 'F' #define PILULA 'P' #define VAZIO '.' #define PAREDE_VERTICAL '|' #define PAREDE_HORIZONTAL '-' This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ 5 10 |--------| |.F.|..-.| |.._|.@P.| |..F...-.| |--------| -
rkTinelli revised this gist
Oct 10, 2017 . 5 changed files with 71 additions and 17 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,4 +6,6 @@ void move_pers(char comando); int ehdirecao (char comando); void fantasma(); int paraondefantasmavai (int xatual, int yatual, int* xdestino, int*ydestino); int acabou(); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,13 +1,15 @@ #include <stdio.h> #include <stdlib.h> #include <time.h> #include "foge.h" #include "mapa.h" MAPA m; POSICAO heroi; int acabou(){ POSICAO pos; return !encontra_no_mapa(&m, &pos, HEROI); } int ehdirecao (char comando){ @@ -41,9 +43,7 @@ void move_pers(char comando){ break; } if (!pode_andar(&m, HEROI, prox_x, prox_y)) return; andanomapa(&m, heroi.x, heroi.y, prox_x, prox_y); @@ -57,27 +57,56 @@ void fantasma(){ MAPA copia; copiamapa(&copia, &m); int i; int j; for (i=0 ; i< copia.linhas; i++){ for (j=0; j< copia.colunas; j++){ if (copia.mapa[i][j] == FANTASMA){ int xdestino; int ydestino; int encontrou = paraondefantasmavai(i, j, &xdestino, &ydestino); if (encontrou){ andanomapa(&m, i, j, xdestino, ydestino); } } } } libera_mapa(&copia); } int paraondefantasmavai (int xatual, int yatual, int* xdestino, int*ydestino){ int opcoes[4][2] = { {xatual, yatual+1}, {xatual+1, yatual}, {xatual, yatual-1}, {xatual-1, yatual} }; srand(time(0)); int i; for (i=0; i<10 ; i++){ int escolha = rand() % 4; if (pode_andar(&m, FANTASMA, opcoes[escolha][0],opcoes[escolha][1])){ *xdestino = opcoes[escolha][0]; *ydestino = opcoes[escolha][1]; return 1; } } return 0; } int main(){ le_mapa(&m); encontra_no_mapa(&m, &heroi, HEROI); do{ imprime_mapa(&m); @@ -86,10 +115,11 @@ int main(){ char comando; scanf(" %c",&comando); //espaço em branco para ENTER ser ignorado move_pers(comando); fantasma(); } while (!acabou()); libera_mapa(&m); return 0; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -23,18 +23,19 @@ void le_mapa(MAPA* m){ fclose(f); } int encontra_no_mapa(MAPA* m, POSICAO* p, char c){ int i; int j; for (i=0;i<m->linhas;i++){ for (j=0;j<m->colunas;j++){ if (m->mapa[i][j]== c ){ p->x=i; p->y=j; return 1; } } } return 0; } void aloca_mapa(MAPA* m){ @@ -73,6 +74,24 @@ int ehvazio (MAPA* m, int x, int y){ return m->mapa[x][y] == VAZIO; } int ehparede (MAPA* m, int x, int y){ return m->mapa[x][y] == PAREDE_HORIZONTAL || m->mapa[x][y] == PAREDE_VERTICAL; } int ehpersonagem(MAPA* m,char personagem,int x,int y){ return m->mapa[x][y] == personagem; } int pode_andar(MAPA* m, char personagem , int x, int y){ return ehvalida(m,x,y) && !ehparede(m,x,y)&& !ehpersonagem(m,personagem,x,y); } void andanomapa (MAPA* m, int xorigem, int yorigem, int xdestino, int ydestino){ @@ -88,8 +107,8 @@ void copiamapa (MAPA* destino, MAPA* origem){ aloca_mapa(destino); int i; for ( i=0 ; i < origem->linhas ; i++){ strcpy(destino->mapa[i], origem->mapa[i]); } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -24,9 +24,12 @@ void libera_mapa(MAPA* m); void le_mapa(MAPA* m); void aloca_mapa(MAPA* m); void imprime_mapa(MAPA* m); int encontra_no_mapa(MAPA* m, POSICAO* p, char c); int ehvalida (MAPA* m, int x, int y); int ehvazio (MAPA* m, int x, int y); int ehparede (MAPA* m, int x, int y); int ehpersonagem(MAPA* m,char personagem,int x,int y); int pode_andar(MAPA* m, char personagem , int x, int y); void andanomapa (MAPA* m, int xorigem, int yorigem, int xdestino, int ydestino); void copiamapa (MAPA* destino, MAPA* origem); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,5 +2,5 @@ |--------| |.F.|..-.| |.._|.@..| |..F...-.| |--------| -
rkTinelli revised this gist
Oct 10, 2017 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -57,8 +57,8 @@ void fantasma(){ MAPA copia; copiamapa(&copia, &m); printf("COPIA !!\n"); //debug imprime_mapa(&copia); //debug int i; int j; -
rkTinelli revised this gist
Oct 10, 2017 . 5 changed files with 45 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,4 +5,5 @@ void move_pers(char comando); int ehdirecao (char comando); void fantasma(); int acabou(); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -52,6 +52,28 @@ void move_pers(char comando){ heroi.y = prox_y; } void fantasma(){ MAPA copia; copiamapa(&copia, &m); printf("COPIA !!\n"); imprime_mapa(&m); int i; int j; for (i=0 ; i< copia.linhas; i++){ for (j=0; j< copia.colunas; j++){ if (copia.mapa[i][j] == FANTASMA){ if (ehvalida(&m, i,j+1) && ehvazio(&m,i,j+1)){ andanomapa(&m, i, j, i, j+1); } } } } libera_mapa(&copia); } int main(){ le_mapa(&m); @@ -64,6 +86,7 @@ int main(){ char comando; scanf(" %c",&comando); //espaço em branco para ENTER ser ignorado move_pers(comando); //fantasma(); } while (!acabou()); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,6 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> #include "mapa.h" void le_mapa(MAPA* m){ @@ -75,6 +76,20 @@ int ehvazio (MAPA* m, int x, int y){ void andanomapa (MAPA* m, int xorigem, int yorigem, int xdestino, int ydestino){ char personagem = m->mapa[xorigem][yorigem]; m->mapa[xdestino][ydestino] = personagem; m->mapa[xorigem][yorigem] = VAZIO; } void copiamapa (MAPA* destino, MAPA* origem){ destino->linhas = origem->linhas; destino->colunas = origem->colunas; aloca_mapa(destino); int i; for (i=0; i<= origem->linhas; i++){ strcpy(destino->mapa[i], origem->mapa[i]); } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,5 @@ #define HEROI '@' #define FANTASMA 'F' #define VAZIO '.' #define PAREDE_VERTICAL '|' #define PAREDE_HORIZONTAL '-' @@ -23,7 +24,9 @@ void libera_mapa(MAPA* m); void le_mapa(MAPA* m); void aloca_mapa(MAPA* m); void imprime_mapa(MAPA* m); void encontraheroi(MAPA* m, POSICAO* p, char c); int ehvalida (MAPA* m, int x, int y); int ehvazio (MAPA* m, int x, int y); void andanomapa (MAPA* m, int xorigem, int yorigem, int xdestino, int ydestino); void copiamapa (MAPA* destino, MAPA* origem); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ 5 10 |--------| |.F.|..-.| |.._|.@..| |..F..._.| |--------| -
rkTinelli revised this gist
Oct 10, 2017 . 4 changed files with 52 additions and 15 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,2 +1,8 @@ #define CIMA 'w' #define BAIXO 's' #define DIREITA 'd' #define ESQUERDA 'a' void move_pers(char comando); int ehdirecao (char comando); int acabou(); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,48 +10,52 @@ int acabou(){ return 0; } int ehdirecao (char comando){ return comando == ESQUERDA || comando == CIMA || comando == BAIXO || comando == DIREITA; } void move_pers(char comando){ if (!ehdirecao(comando)) return; int prox_x = heroi.x; int prox_y = heroi.y; switch (comando){ case ESQUERDA: prox_y--; break; case CIMA: prox_x--; break; case BAIXO: prox_x++; break; case DIREITA: prox_y++; break; } if (!ehvalida(&m, prox_x, prox_y)) return; if (!ehvazio(&m, prox_x, prox_y)) return; andanomapa(&m, heroi.x, heroi.y, prox_x, prox_y); heroi.x = prox_x; heroi.y = prox_y; } int main(){ le_mapa(&m); encontraheroi(&m, &heroi, HEROI); do{ imprime_mapa(&m); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -60,3 +60,21 @@ void imprime_mapa(MAPA* m){ printf("%s\n",m->mapa[i]); } } int ehvalida (MAPA* m, int x, int y){ if (x>=m->linhas || y>=m->colunas) return 0; return 1; } int ehvazio (MAPA* m, int x, int y){ return m->mapa[x][y] == VAZIO; } void andanomapa (MAPA* m, int xorigem, int yorigem, int xdestino, int ydestino){ m->mapa[xdestino][ydestino] = HEROI; m->mapa[xorigem][yorigem] = VAZIO; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,8 @@ #define HEROI '@' #define VAZIO '.' #define PAREDE_VERTICAL '|' #define PAREDE_HORIZONTAL '-' struct matriz{ char** mapa; //[5][10+1]; //10+1 para que seja identificado o \0 no final de cada linha int linhas; @@ -18,3 +23,7 @@ void libera_mapa(MAPA* m); void le_mapa(MAPA* m); void aloca_mapa(MAPA* m); void imprime_mapa(MAPA* m); int ehvalida (MAPA* m, int x, int y); int ehvazio (MAPA* m, int x, int y); void andanomapa (MAPA* m, int xorigem, int yorigem, int xdestino, int ydestino); -
rkTinelli revised this gist
Oct 6, 2017 . 1 changed file with 18 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -18,26 +18,34 @@ void move_pers(char comando){ comando!= 'd') return; int prox_x = heroi.x; int prox_y = heroi.y; switch (comando){ case 'a': prox_y--; break; case 'w': prox_x--; break; case 's': prox_x++; break; case 'd': prox_y++; break; } if (prox_x>m.linhas) return; if (prox_y>m.colunas) return; if (m.mapa[prox_x][prox_y]!= '.') return; m.mapa[prox_x][prox_y] = '@'; m.mapa[heroi.x][heroi.y] = '.'; heroi.x = prox_x; heroi.y = prox_y; } int main(){ @@ -50,7 +58,7 @@ int main(){ printf("Qual seu comando? (a/w/s/d)\n"); char comando; scanf(" %c",&comando); //espaço em branco para ENTER ser ignorado move_pers(comando); } while (!acabou()); -
rkTinelli revised this gist
Oct 6, 2017 . 1 changed file with 7 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,6 +12,12 @@ int acabou(){ void move_pers(char comando){ if (comando!= 'a' && comando!= 'w' && comando!= 's' && comando!= 'd') return; m.mapa[heroi.x][heroi.y] = '.'; switch (comando){ @@ -44,7 +50,7 @@ int main(){ printf("Qual seu comando? (a/w/s/d)\n"); char comando; scanf(" %c",&comando); //espa�o em branco para ENTER ser ignorado move_pers(comando); } while (!acabou()); -
rkTinelli revised this gist
Oct 6, 2017 . 4 changed files with 120 additions and 53 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,2 @@ void move_pers(char comando); int acabou(); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,66 +1,54 @@ #include <stdio.h> #include <stdlib.h> #include "foge.h" #include "mapa.h" MAPA m; POSICAO heroi; int acabou(){ return 0; } void move_pers(char comando){ m.mapa[heroi.x][heroi.y] = '.'; switch (comando){ case 'a': m.mapa[heroi.x][heroi.y-1]= '@'; heroi.y--; break; case 'w': m.mapa[heroi.x-1][heroi.y]= '@'; heroi.x--; break; case 's': m.mapa[heroi.x+1][heroi.y]= '@'; heroi.x++; break; case 'd': m.mapa[heroi.x][heroi.y+1]= '@'; heroi.y++; break; } } int main(){ le_mapa(&m); encontraheroi(&m, &heroi, '@'); do{ imprime_mapa(&m); printf("Qual seu comando? (a/w/s/d)\n"); char comando; scanf(" %c",&comando); //espaço em branco para ENTER ser ignorado move_pers(comando); } while (!acabou()); libera_mapa(&m); return 0; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,62 @@ #include <stdio.h> #include <stdlib.h> #include "mapa.h" void le_mapa(MAPA* m){ FILE* f; f = fopen("mapa.txt","r"); if (f==0){ //tratamentto de erro printf("Erro de leitura do arquivo do m->mapa! \n"); exit(1); } fscanf(f,"%d %d",&m->linhas,&m->colunas); aloca_mapa(m); int i; for (i = 0; i<5; i++){ fscanf(f,"%s",m->mapa[i]); } fclose(f); } void encontraheroi(MAPA* m, POSICAO* p, char c){ int i; int j; for (i=0;i<m->linhas;i++){ for (j=0;j<m->colunas;j++){ if (m->mapa[i][j]== c ){ p->x=i; p->y=j; break; } } } } void aloca_mapa(MAPA* m){ m->mapa = malloc(sizeof(char*)*m->linhas); int j; for (j=0;j<m->linhas;j++){ m->mapa[j] = malloc(sizeof(char*)*(m->colunas+1)); } } void libera_mapa(MAPA* m){ int i; for (i=0;i<m->linhas;i++){ free(m->mapa[i]); } free(m->mapa); } void imprime_mapa(MAPA* m){ int i; for (i = 0; i<m->linhas; i++){ printf("%s\n",m->mapa[i]); } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ struct matriz{ char** mapa; //[5][10+1]; //10+1 para que seja identificado o \0 no final de cada linha int linhas; int colunas; }; typedef struct matriz MAPA; struct posicao{ int x; int y; }; typedef struct posicao POSICAO; //Assinatura das funções void libera_mapa(MAPA* m); void le_mapa(MAPA* m); void aloca_mapa(MAPA* m); void imprime_mapa(MAPA* m); -
rkTinelli created this gist
Oct 6, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ void libera_mapa(); void le_mapa(); void aloca_mapa(); void imprime_mapa(); int acabou(); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,66 @@ #include <stdio.h> #include <stdlib.h> #include "foge.h" char** mapa; //[5][10+1]; //10+1 para que seja identificado o \0 no final de cada linha int linhas; int colunas; void le_mapa(){ FILE* f; f = fopen("mapa.txt","r"); if (f==0){ //tratamentto de erro printf("Erro de leitura do arquivo do mapa! \n"); } fscanf(f,"%d %d",&linhas,&colunas); aloca_mapa(); int i; for (i = 0; i<5; i++){ fscanf(f,"%s",mapa[i]); } fclose(f); } void aloca_mapa(){ mapa = malloc(sizeof(char*)*linhas); int j; for (j=0;j<linhas;j++){ mapa[j] = malloc(sizeof(char*)*(colunas+1)); } } void libera_mapa(){ int i; for (i=0;i<linhas;i++){ free(mapa[i]); } free(mapa); } void imprime_mapa(){ int i; for (i = 0; i<5; i++){ printf("%s\n",mapa[i]); } } int acabou(){ return 0; } int main(){ le_mapa(); imprime_mapa(); libera_mapa(); return 0; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ 5 10 |--------| |...|..-.| |.._|.@..| |......_.| |--------|