DEV/DEV1.1/CM1/exo5.c

77 lines
1.3 KiB
C
Raw Permalink Normal View History

2024-10-22 15:14:54 +02:00
#include <stdio.h>
#include <stdlib.h>
int main(void) {
int tab[10][10]{{'x','x','x','x','x','x','x','x','x','x' },
{'x','x','x','x','x','x','x','x','x','x'},
{'x','x','x','x','x','x','x','x','x','x'},
{' ',' ',' ',' ',' ',' ',' ','x','x','x'},
{' ','x','x','x','x','x','x','x','x','x'},
{' ','x','x','x','x','x','x','x','x','x'},
{' ','x','x','x','x','x','x','x','x','x'},
{' ','x','x','x','x','x','x','x','x','x'},
{' ','x','x','x','x','x','x','x','x','x'},
{' ','x','x','x','x','x','x','x','x','x'} };
int x =7;
int y =4;
char direction;
int ysortie;
int xsortie;
int i;
for (i = 0; i<= i; i++){
printf("vers ou ? ");
scanf("%c", direction);
if(y == ysortie && x=xsortie){
return EXIT_SUCCESS;
}else if(direction == 'N'){
y+=1;
if (tab[y][x]=' '){
printf("ok");
}else{
printf("bloquer");
y-=1;
}
}else if(direction == 'S'){
y-=1;
if (tab[y][x]=' '){
printf("ok");
}else{
printf("bloquer");
y+=1;
}
}else if(direction == 'E'){
x+=1;
if (tab[y][x]=' '){
printf("ok");
}else{
printf("bloquer");
x-=1;
}
}else if(direction == 'O'){
x-=1;
if (tab[y][x]=' '){
printf("ok");
}
}else{
printf("bloquer");
x+=1;
}
}
}
}
}