Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "main.h"
- #include "menu_inicial.h"
- #include "le_mapa.h"
- #include "gera_tela.h"
- #include "imprime_tela.h"
- int main()
- {
- setlocale(LC_ALL, "Portuguese_Brazil");
- FILE *arq;
- char opcao;
- char mapa[LINHAS][COLUNAS];
- char tela[LINHAS][COLUNAS_TELA];
- int flag_repetir_menu = 0;
- int coluna_atual = 0;
- arq = fopen(FILE_MAPA, "r");
- if(!arq)
- {
- printf("Erro ao abrir o arquivo do mapa.");
- return 0;
- }
- do
- {
- opcao = menu_inicial();
- switch(opcao)
- {
- case '1':
- printf("Você escolheu a opção 'Novo Jogo'.\n");
- le_mapa(arq, mapa);
- gera_tela(mapa, tela, coluna_atual);
- imprime_tela(tela);
- break;
- case '2':
- printf("Você escolheu a opção 'Carregar Jogo'.");
- break;
- case '3':
- printf("Você escolheu a opção 'Sair'.");
- break;
- default:
- printf("Opção inválida.");
- flag_repetir_menu = 1;
- break;
- }
- } while (flag_repetir_menu);
- return 0;
- }
- #ifndef MENU_INICIAL_H
- #define MENU_INICIAL_H
- #include "main.h"
- char menu_inicial();
- #endif
- #ifndef MAIN_H
- #define MAIN_H
- #include <stdio.h>
- #include <conio2.h>
- #include <locale.h>
- #include <windows.h>
- #define LINHAS 35
- #define COLUNAS 415
- #define COLUNAS_TELA 105
- #define FILE_MAPA "mapa.txt"
- typedef struct
- {
- int linha;
- int coluna;
- } COORDENADA;
- #endif
- #ifndef MAIN_H
- #define MAIN_H
- #include <stdio.h>
- #include <conio2.h>
- #include <locale.h>
- #include <windows.h>
- #define LINHAS 35
- #define COLUNAS 415
- #define COLUNAS_TELA 105
- #define FILE_MAPA "mapa.txt"
- typedef struct
- {
- int linha;
- int coluna;
- } COORDENADA;
- #endif
- #ifndef GERA_TELA_H
- #define GERA_TELA_H
- #include "main.h"
- void gera_tela(char mapa[LINHAS][COLUNAS], char tela[LINHAS][COLUNAS_TELA], int coluna_atual);
- #endif // GERA_TELA_H
- #include "gera_tela.h"
- void gera_tela(char mapa[LINHAS][COLUNAS], char tela[LINHAS][COLUNAS_TELA], int coluna_atual)
- {
- int i, j;
- for(i = 0; i < LINHAS; i++)
- for(j = 0; j < COLUNAS_TELA; j++)
- if((j + coluna_atual) >= COLUNAS)
- tela[i][j] = mapa[i][(j + coluna_atual) - COLUNAS];
- else
- tela[i][j] = mapa[i][j + coluna_atual];
- }
- #include "menu_inicial.h"
- char menu_inicial()
- {
- char opcao;
- gotoxy(30, 9);
- printf("DEFENDER\n");
- gotoxy(30, 11);
- printf("Por Henrique Bernardes e Marthyna Weber");
- Sleep(1000);
- gotoxy(30, 18);
- printf("SELECIONE UMA OPÇÃO:\n");
- gotoxy(30, 19);
- printf("1 - Novo Jogo\n");
- gotoxy(30, 20);
- printf("2 - Continuar Jogando\n");
- gotoxy(30, 21);
- printf("3 - Sair\n");
- gotoxy(30, 22);
- opcao = getch();
- clrscr();
- return opcao;
- }
- #include "le_mapa.h"
- void le_mapa(FILE *arq, char mapa[LINHAS][COLUNAS])
- {
- int i, j;
- char c;
- for(i = 0; i < LINHAS; i++)
- {
- for(j = 0; j < COLUNAS; j++)
- {
- c = fgetc(arq);
- mapa[i][j] = c;
- // completa a nave do jogador
- if(c == '@')
- {
- mapa[i-1][j] = c;
- mapa[i][j+1] = c;
- mapa[i][j+2] = c;
- mapa[i][j+3] = c;
- j += 3;
- }
- // completa as naves dos inimigos
- if(c == 'X')
- {
- mapa[i-1][j] = c;
- mapa[i-1][j+1] = c;
- mapa[i][j+1] = c;
- j += 1;
- }
- }
- // captura o \n no fim de cada linha
- c = fgetc(arq);
- }
- }
- #include "imprime_tela.h"
- void imprime_tela(char tela[LINHAS][COLUNAS_TELA])
- {
- int i, j;
- for(i = 0; i < LINHAS; i++)
- {
- for(j = 0; j < COLUNAS_TELA; j++)
- {
- printf("%c", tela[i][j]);
- }
- printf("\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement