Last active
November 17, 2024 17:41
-
-
Save rkTinelli/be533edabf44e13e6366549081d10897 to your computer and use it in GitHub Desktop.
Jogo FogeFoge (Pacman) Funcional feito em linguagem C
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 characters
| 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 characters
| #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){ | |
| if (comando!= 'a' && | |
| comando!= 'w' && | |
| comando!= 's' && | |
| comando!= 'd') | |
| return; | |
| 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 characters
| #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 characters
| 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); |
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 characters
| 5 10 | |
| |--------| | |
| |...|..-.| | |
| |.._|.@..| | |
| |......_.| | |
| |--------| |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Pac-man game.
Working !