-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlabyrinthbash.c
More file actions
121 lines (114 loc) · 4.28 KB
/
labyrinthbash.c
File metadata and controls
121 lines (114 loc) · 4.28 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include <conio.h>
#include <dos.h>
#include <process.h>
#include <stdio.h>
#include <stdlib.h>
#include <direct.h>
#define LENGTH 20
#define KEY_UP 72
#define KEY_DOWN 80
#define KEY_LEFT 75
#define KEY_RIGHT 77
char labyrinthe[20][20] = {"####################",
"################# X",
"# # # ##",
"# ##### # #",
"# # # #######",
"# ###### ###",
"### #### ###",
"# # ######## #",
"# #### # #",
"# ######## ####",
"# ##### # #",
"# ######## #####",
"# ####### #",
"### ########### #",
"# # #",
"# ## # ##########",
"# # # #",
"## ## ########## #",
"#P #",
"####################",};
int posPlayer[2] = {18,1};
int posEnd[2] = {1,18};
int posDirection[2] = {0,0};
void matrice() {
for (int i = 0; i < LENGTH; i++) {
for (int j = 0; j < LENGTH; j++) {
printf("%c ", labyrinthe[i][j]);
}
printf("\n");
}
printf("\n");
}
void get_position() {
getch();
int key = getch();
if (key == KEY_DOWN) {
posDirection[0] = 1;
posDirection[1] = 0;
}
else if (key == KEY_UP) {
posDirection[0] = -1;
posDirection[1] = 0;
}
else if (key == KEY_LEFT) {
posDirection[0] = 0;
posDirection[1] = -1;
}
else if (key == KEY_RIGHT) {
posDirection[0] = 0;
posDirection[1] = 1;
}
}
int check_direction() {
if (labyrinthe[posPlayer[0]+posDirection[0]][posPlayer[1]+posDirection[1]] == ' ') {
return 1;
}
else return 0;
}
void move() {
labyrinthe[posPlayer[0]+posDirection[0]][posPlayer[1]+posDirection[1]] = 'P';
labyrinthe[posPlayer[0]][posPlayer[1]] = ' ';
posPlayer[0] += posDirection[0];
posPlayer[1] += posDirection[1];
}
int main() {
printf(" *****************************************************
* *
* LABYRINTHE *
* *
* *
* Objectif : Le joueur doit atteindre la fin du *
* labyrinthe en respectant les limites *
* du labyrinthe. *
* *
* *
* The player have to go to the end of *
* the parkour marked by the cross "X", *
* you are the player "P". *
* *
*****************************************************
:\n");
while (posPlayer[0] != posEnd[0] || posPlayer[1] != posEnd[1]) {
matrice();
get_position();
if (check_direction() == 1) move();
else printf("Veuillez respecter les délimitations du labyrinthe - Respect the limits !\n");
}
matrice();
printf("*****************************************************
* *
* VOUS AVEZ GAGNE !!! *
* *
* YOU WON ! ! *
* *
* *
* Félicitations ! *
* *
* Congrats ! *
* *
* *
*****************************************************");
return 0;
}