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;
- };
- typedef struct personagens per;
- int main(){
- int n = 0, m = 0, x = 0, y = 0, z = 0;
- char **matriz;
- 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 vá estudar álgebra, cálculo, 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+1);
- //alocando dinamicamente a nossa matrizinha
- matriz = (char **) malloc((m-1)*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*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);
- }
- }
- //os 4 seguintes for's é para o preenchimento da bordas
- for(y = 0; y < m-1; y++)
- matriz[0][y] = '*';
- for(y = 0; y < m; y++)
- matriz[y][0] = '*';
- for(y = 0; y < m; y++)
- matriz[m-1][y] = '*';
- for(y = 0; y < m; y++)
- matriz[y][m-1] = '*';
- //o serumaninho digita aqui os astericos e tal
- for(x = 1; x < m; x++)
- for(y = 1; y < m; y++)
- scanf("%c", &matriz[x][y]);
- //colocando dentro da .txt nossa matriz que o serumaninho digitou
- for(x = 0; x < m; x++)
- for(y = 0; y < m; y++)
- fprintf(rpg, "%c", matriz[x][y]);
- //liberando memória alocada
- for(x = 0; x < (4+5*n+1); 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
- monstro[0].y = (2+n-1);
- monstro[0].x = (2+n-1);
- monstro[1].y = (2+n-1);
- monstro[1].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(" %s", 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(char), 11, rpg);
- fwrite(&heroi, sizeof(int), 24, rpg);
- fwrite(&monstro, sizeof(char), 11, rpg);
- fwrite(&monstro, sizeof(int), 24, rpg);
- free(heroi);
- free(monstro);
- free(rpg);
- fclose(rpg);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement