-
Notifications
You must be signed in to change notification settings - Fork 0
/
maze.c
85 lines (67 loc) · 2.35 KB
/
maze.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <time.h>
#include "maze.h"
/* generowanie labiryntu */
void init_maze( maze* m, int size ) {
m->m_size = size;
m->start = 0;
m->finish = 0;
for ( int y = 0; y < MAX_SIZE; ++y )
for ( int x = 0; x < MAX_SIZE; ++x ) {
m->m[y][x] = init_cell( y, x, size );
init_nears( &m->m[y][x],
y - 1 >= 0 ? &m->m[y - 1][x] : NULL,
x + 1 < size ? &m->m[y][x + 1] : NULL,
y + 1 < size ? &m->m[y + 1][x] : NULL,
x - 1 >= 0 ? &m->m[y][x - 1] : NULL );
}
}
/* ustawienie wygenerowanie już punktu wejścia i wyjścia labiryntu */
void set_maze_entries( maze* m, int start, int finish ) {
m->start = start;
m->finish = finish;
m->m[0][start].bounds[0] = 0;
m->m[m->m_size - 1][finish].bounds[2] = 0;
}
/* wypis labiryntu na konsoli */
void print_maze( maze* m ) {
int size = m->m_size;
/* --- GORNA BARIERKA ---- */
/* wyswietlanie gornych barierek komorek */
for ( int x = 0; x < size; ++ x) {
/* barierka nad lewa scianka przed komorka */
printf ("%s ", "#");
/* barierka nad komorka */
printf ("%s ", m->m[0][x].bounds[0] == 1 ? "#" : ( m->m[0][x].bounds[0] == 2 ? "o" : " " ) );
}
/* barierka od skrajnej prawej + odstep na nowy wiersz z komorkami */
printf("#\n");
/* ---- KOMORKI LABIRYNTU ---- */
for ( int y = 0; y < size; ++y ) {
for ( int x = 0; x < size; ++ x) {
if ( m->m[y][x].bounds[3] == 1 )
printf("# ");
else if ( m->m[y][x].bounds[3] == 2 )
printf("o ");
else
printf(" ");
printf("%c ", m->m[y][x].label);
if ( x == size - 1 )
printf("# ");
}
printf("\n");
/* --- DOLNE BARIERKI ---- */
/* wyswietlanie dolnych barierek komorek */
for ( int x = 0; x < size; ++ x) {
/* barierka pod lewa scianka przed komorka */
printf ("%s ", "#");
/* barierka pod komorka */
printf ("%s ", m->m[ y ][x].bounds[2] == 1 ? "#" : ( m->m[ y ][x].bounds[2] == 2 ? "o" : " " ));
}
/* barierka od skrajnej prawej + odstep na nowy wiersz z komorkami */
printf("#\n");
}
}