Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- //estrutura para salvar as informações dos personagens u.u
- struct personagens
- {
- char nome[11];
- int ataque;
- int defesa;
- int hp;
- int x, y;
- int status;
- };
- typedef struct personagens per;
- int main(){
- int n = 0, m = 0, x = 0, y = 0, z = 0;
- char **matriz, enter;
- per *heroi = (per *) malloc(sizeof(per));
- per *monstro = (per *) malloc(sizeof(per)*4);
- FILE *rpg;
- //abrindo o arquivo txt.
- rpg = fopen("mapa.txt", "w");
- if(rpg == NULL){
- printf("Pare de jogar e va estudar algebra, calculo, e discreta.(e programar, claro :d)");
- }
- printf("Digite n para as dimensoes do mapa segundo a expressao (5+4n)x(5+4n):\n");
- scanf("%d", &n);
- //o +1 é pra fazer a borda
- m = (5+4*n);
- a //alocando dinamicamente a nossa matrizinha
- matriz = (char **) malloc((m)*sizeof(char*));
- if(matriz == NULL){
- printf("Tem memoria nao. Pare de jogar e a estudar, pois o fim do periodo ta ai.");
- exit(1);
- }
- //alocando memória para as colunas
- for(x = 0; x < m; x++){
- matriz[x] = (char *) malloc((m+1)*sizeof(char));
- if(matriz[x] == NULL){
- printf("Tem memoria nao. Pare de jogar e va estudar, pois o fim do periodo ta ai.");
- exit(1);
- }
- }
- printf("Digite o mapa:\n");
- //o ser humaninho digita aqui os astericos e tal
- for(x = 0; x < m; x++){
- scanf(" %[^\n]", matriz[x]);
- }
- //////////////////////////////
- //colocando dentro do arquivo .txt a nossa matriz que o ser humaninho digitou
- fprintf(rpg, "%d\n", n);
- for(x = 0; x < m; x++)
- fprintf(rpg, "%s\n", matriz[x]);
- //liberando memória alocada
- for(x = 0; x < m; x++){
- free(matriz[x]);
- }
- free(matriz);
- fclose(rpg);
- //abrindo agora o arquivo .bin para colocar nele as informações fornecidas sobre os personagens
- rpg = fopen("personagens.bin", "ab");
- //colocando monstros nos quadrantes
- heroi[0].status=1;
- monstro[0].status=1;
- monstro[1].status=1;
- monstro[2].status=1;
- monstro[3].status=1;
- monstro[1].y = (2+n-1);
- monstro[1].x = (2+n-1);
- monstro[0].y = (2+n-1);
- monstro[0].x = (4+3*n-1);
- monstro[2].y = (4+3*n-1);
- monstro[2].x = (2+n-1);
- monstro[3].x = (4+3*n-1);
- monstro[3].y = (4+3*n-1);
- heroi[0].x = (3+2*n-1);
- heroi[0].y = (3+2*n-1);
- for(x = 0; x < 1; x++){
- printf("Digite o nome do heroi\n");
- scanf(" %s", heroi[x].nome);
- printf("Digite o atk, def e hp respectivamente\n");
- scanf("%d %d %d", &heroi[x].ataque, &heroi[x].defesa, &heroi[x].hp);
- }
- //fornecendo nome e atributos aos monstros.
- for(x = 0; x < 4; x++){
- printf("Digite o nome do monstro %d\n", x+1);
- scanf(" %10s", monstro[x].nome);
- printf("Digite o atk , def e hp respectivamente\n");
- scanf("%d %d %d", &monstro[x].ataque, &monstro[x].defesa, &monstro[x].hp);
- }
- //escrevendo as informações fornecidas para o herói dentro do arquivo pensonagens.bin
- fwrite(heroi, sizeof(*heroi), 1, rpg);
- for(x=0; x<4; x++){
- fwrite(&monstro[x], sizeof(monstro[x]), 1, rpg);
- }
- free(heroi);
- free(monstro);
- free(rpg);
- fclose(rpg);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement