-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
96 lines (88 loc) · 1.53 KB
/
main.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
86
87
88
89
90
91
92
93
94
95
#ifdef _WIN32
#include <windows.h>
#include <conio.h>
#endif
#include <stdio.h>
#define MAX 10
char laby[MAX][MAX] = {
"-------------",
"| - |",
"| -- -- -- |",
"| |",
"| ---- - - |",
"| - |",
"| -- --- |",
"| ------- |",
"| |",
"|------- - |"
};
int MyGetch()
{
#ifdef _WIN32
return getch();
#endif
// trouver alternative hors Windows.
}
void Locate(int x,int y)
{
#ifdef _WIN32
HANDLE H=GetStdHandle(STD_OUTPUT_HANDLE);
COORD C;
C.X=(SHORT)x;
C.Y=(SHORT)y;
SetConsoleCursorPosition(H,C);
#endif
// trouver alternative hors Windows.
}
void Afficher(int x,int y)
{
int i,j;
Locate(0,0);
for(i=0;i<MAX;i++)
{
for(j=0;j<MAX;j++)
{
if (i==x && j==y)
printf("p");
else
printf("%c",laby[i][j]);
}
printf("\n");
}
}
void TryMove(int* x,int* y,int vx,int vy)
{
if (laby[*x+vx][*y+vy]=='-')
return;
(*x)+=vx;
(*y)+=vy;
}
int main()
{
int x,y; // position joueur
int touche;
x = y = 1;
touche = 0;
while(touche!=27) // ECHAP
{
Afficher(x,y);
touche = MyGetch();
switch(touche)
{
case 'q':
TryMove(&x,&y,0,-1);
break;
case 'd':
TryMove(&x,&y,0,1);
break;
case 'z':
TryMove(&x,&y,-1,0);
break;
case 's':
TryMove(&x,&y,1,0);
default:
break;
}
}
return 0;
}