View difference between Paste ID: QduzWW5W and 4Qraqrfy
SHOW: | | - or go back to the newest paste.
1-
/*
1+
 /*
2-
Roguelike v0.1
2+
Roguelike v0.2
3
Autor: Rafael Gibim
4
Limitações: 1º semestre de APC; não há uso de funções.
5
6
Changelog:
7
0.1: Personagem se move sem "entrar" nas paredes
8
0.2: Mapa 15x40 com câmera expandível (mas não é móvel)
9
10
Definições:
11
@ : personagem
12
. : Espaço vazio
13
# : parede
14
*/
15
16
#include <stdio.h>
17
#include <stdlib.h>
18
#include <time.h> //necessária para melhorar a aleatoriedade
19
#include <conio.h> //necessária para a função getch
20-
/* Quantidade de fileiras e colunas */
20+
21-
#define FILE 10
21+
 /* Quantidade de fileiras e colunas */
22-
#define COLU 20
22+
#define FILE 17
23
#define COLU 42
24-
/* Valores ASCII das setas e da tecla ESC */
24+
25
 /* Valores ASCII das setas e da tecla ESC */
26
#define SETA_CIMA 72
27
#define SETA_BAIXO 80
28
#define SETA_ESQUERDA 75
29
#define SETA_DIREITA 77
30
#define ESC 27
31
32
void main(){
33
	int camera_x = 6, camera_y = 11;
34
	int aux = 0; //Variável puramente auxiliar
35
	int i, j; //meros contadores
36
	int i_atual, j_atual; //guarda a posição do jogador
37
	char ch=0; //variável para reconhecer as setas
38
	char tabuleiro[FILE][COLU];
39
	srand(time(NULL));
40
41
	/* Preenchendo o tabuleiro */
42
	for(i=0;i<FILE;i++){
43
		for(j=0;j<COLU;j++){
44
			tabuleiro[i][j] = '.';
45
			if(i==0 || j == 0 || i==FILE-1 || j==COLU-1) tabuleiro[i][j] = '#';
46
		}
47
	}
48-
	/* Definindo posição do jogador de forma aleatória,
48+
49-
	com cuidado para não cair nas paredes */
49+
50-
	i_atual = rand()%(FILE-2) + 1;
50+
	/* Definindo posição do jogador*/
51-
	j_atual = rand()%(COLU-2) + 1;
51+
	i_atual = 1;
52
	j_atual = 1;
53
	tabuleiro[i_atual][j_atual] = '@';
54
55
56
	do{
57
		system("cls");
58-
		for(i=0;i<FILE;i++){
58+
59-
			for(j=0;j<COLU;j++) printf("%c", tabuleiro[i][j]);
59+
60
61
		for(j=0; j<camera_y+2; j++) printf("?");
62
		printf("\n");
63
		for(i=0; i<camera_x; i++){
64
			printf("?");
65
			for(j=0;j<camera_y;j++) printf("%c", tabuleiro[i][j]);
66
			printf("?");
67
			printf("\n");
68
		}
69
		for(j=0; j<camera_y+2; j++) printf("?");
70
		printf("\n");
71
72
		printf("\n\nUtilize as setas para movimentar seu personagem\n");
73
		printf("Aperte ESC para sair\n");
74
		
75
76
		/* Reconhecimento de tecla. */
77
		ch = getch();
78
79
80
		switch(ch){
81
		case SETA_CIMA: 
82
			if(tabuleiro[i_atual-1][j_atual] != '#'){
83
				aux = tabuleiro[i_atual][j_atual];
84
				tabuleiro[i_atual][j_atual] = tabuleiro[i_atual-1][j_atual];
85
				tabuleiro[i_atual-1][j_atual] = aux;
86
				i_atual--;
87
				if(i_atual<12) camera_x--;
88
			}
89
			break;
90
		case SETA_BAIXO:
91
			if(tabuleiro[i_atual+1][j_atual] != '#'){
92
				aux = tabuleiro[i_atual][j_atual];
93
				tabuleiro[i_atual][j_atual] = tabuleiro[i_atual+1][j_atual];
94
				tabuleiro[i_atual+1][j_atual] = aux;
95
				i_atual++;
96
				if(i_atual<13) camera_x++;
97
			}
98
			break;
99
		case SETA_DIREITA:
100
			if(tabuleiro[i_atual][j_atual+1] != '#'){
101
				aux = tabuleiro[i_atual][j_atual];
102
				tabuleiro[i_atual][j_atual] = tabuleiro[i_atual][j_atual+1];
103
				tabuleiro[i_atual][j_atual+1] = aux;
104
				j_atual++;
105
				if(j_atual<33) camera_y++;
106
			}
107
			break;
108
		case SETA_ESQUERDA: 
109
			if(tabuleiro[i_atual][j_atual-1] != '#'){
110
				aux = tabuleiro[i_atual][j_atual];
111
				tabuleiro[i_atual][j_atual] = tabuleiro[i_atual][j_atual-1];
112
				tabuleiro[i_atual][j_atual-1] = aux;
113
				j_atual--;
114
				if(j_atual<32) camera_y--;
115
			}
116
			break;
117
		}
118
119
	}while(ch!= ESC);
120
	printf(" %d ", j_atual);
121
122
	system("pause");
123
}