Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Roguelike v0.2
- Autor: Rafael Gibim
- Limitações: 1º semestre de APC; não há uso de funções.
- Changelog:
- 0.1: Personagem se move sem "entrar" nas paredes
- 0.2: Mapa 15x40 com câmera expandível (mas não é móvel)
- Definições:
- @ : personagem
- . : Espaço vazio
- # : parede
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h> //necessária para melhorar a aleatoriedade
- #include <conio.h> //necessária para a função getch
- /* Quantidade de fileiras e colunas */
- #define FILE 17
- #define COLU 42
- /* Valores ASCII das setas e da tecla ESC */
- #define SETA_CIMA 72
- #define SETA_BAIXO 80
- #define SETA_ESQUERDA 75
- #define SETA_DIREITA 77
- #define ESC 27
- void main(){
- int camera_x = 6, camera_y = 11;
- int aux = 0; //Variável puramente auxiliar
- int i, j; //meros contadores
- int i_atual, j_atual; //guarda a posição do jogador
- char ch=0; //variável para reconhecer as setas
- char tabuleiro[FILE][COLU];
- srand(time(NULL));
- /* Preenchendo o tabuleiro */
- for(i=0;i<FILE;i++){
- for(j=0;j<COLU;j++){
- tabuleiro[i][j] = '.';
- if(i==0 || j == 0 || i==FILE-1 || j==COLU-1) tabuleiro[i][j] = '#';
- }
- }
- /* Definindo posição do jogador*/
- i_atual = 1;
- j_atual = 1;
- tabuleiro[i_atual][j_atual] = '@';
- do{
- system("cls");
- /* Imprimindo o tabuleiro. */
- for(j=0; j<camera_y+2; j++) printf("?");
- printf("\n");
- for(i=0; i<camera_x; i++){
- printf("?");
- for(j=0;j<camera_y;j++) printf("%c", tabuleiro[i][j]);
- printf("?");
- printf("\n");
- }
- for(j=0; j<camera_y+2; j++) printf("?");
- printf("\n");
- printf("\n\nUtilize as setas para movimentar seu personagem\n");
- printf("Aperte ESC para sair\n");
- /* Reconhecimento de tecla. */
- ch = getch();
- switch(ch){
- case SETA_CIMA:
- if(tabuleiro[i_atual-1][j_atual] != '#'){
- aux = tabuleiro[i_atual][j_atual];
- tabuleiro[i_atual][j_atual] = tabuleiro[i_atual-1][j_atual];
- tabuleiro[i_atual-1][j_atual] = aux;
- i_atual--;
- if(i_atual<12) camera_x--;
- }
- break;
- case SETA_BAIXO:
- if(tabuleiro[i_atual+1][j_atual] != '#'){
- aux = tabuleiro[i_atual][j_atual];
- tabuleiro[i_atual][j_atual] = tabuleiro[i_atual+1][j_atual];
- tabuleiro[i_atual+1][j_atual] = aux;
- i_atual++;
- if(i_atual<13) camera_x++;
- }
- break;
- case SETA_DIREITA:
- if(tabuleiro[i_atual][j_atual+1] != '#'){
- aux = tabuleiro[i_atual][j_atual];
- tabuleiro[i_atual][j_atual] = tabuleiro[i_atual][j_atual+1];
- tabuleiro[i_atual][j_atual+1] = aux;
- j_atual++;
- if(j_atual<33) camera_y++;
- }
- break;
- case SETA_ESQUERDA:
- if(tabuleiro[i_atual][j_atual-1] != '#'){
- aux = tabuleiro[i_atual][j_atual];
- tabuleiro[i_atual][j_atual] = tabuleiro[i_atual][j_atual-1];
- tabuleiro[i_atual][j_atual-1] = aux;
- j_atual--;
- if(j_atual<32) camera_y--;
- }
- break;
- }
- }while(ch!= ESC);
- printf(" %d ", j_atual);
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment