Skip to content

Instantly share code, notes, and snippets.

@rkTinelli
Last active November 17, 2024 17:41
Show Gist options
  • Select an option

  • Save rkTinelli/be533edabf44e13e6366549081d10897 to your computer and use it in GitHub Desktop.

Select an option

Save rkTinelli/be533edabf44e13e6366549081d10897 to your computer and use it in GitHub Desktop.
Jogo FogeFoge (Pacman) Funcional feito em linguagem C
void libera_mapa();
void le_mapa();
void aloca_mapa();
void imprime_mapa();
int acabou();
#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;
}
5 10
|--------|
|...|..-.|
|.._|.@..|
|......_.|
|--------|
@rkTinelli
Copy link
Author

Pac-man game.
Working !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment