hups... ja som to asi 2x menil tak som si to nevšimol.
Ale keď to dám takto tak mi to aj tak nejde
btw y - je horizontálne

btw y - je horizontálne
Code [Select]
#define MAX_HEIGHT 20
#define MAX_WIDTH 20
#define WALL -1
#define EMPTY 0
int width,height;
int world[MAX_HEIGHT][MAX_WIDTH];
int karel_x;
int karel_y;
int karel_direction;
int karel_beepers = 20;
void turnOn(){
int i,j;
karel_x = 4;
karel_y = 3;
width=6;
height=5;
int newWorld[5][6]={
{ 0, -1, -1, 0, 0, 0 },
{ 0, -1, -1, 0, 0, 0 },
{ 0, -1, -1, 0, 0, 0 },
{ 0, -1, -1, 0, 0, 0 },
{ 0, -1, -1, -1, -1, 0 }
};
karel_direction = 90;
for(i=0;i<height;i++){
for(j=0;j<width;j++)
world[i][j]=newWorld[i][j];
}
}
void draw()
{
system("cls");
printf("pozicia: %d %d \n",karel_x, karel_y);
printf("orientacia: karel je gay: ");
if (karel_direction == 0) printf("juh\n");
if (karel_direction == 180) printf("sever\n");
if (karel_direction == 270) printf("zapad\n");
if (karel_direction == 90) printf("vychod\n");
printf("pocet beeprov v batohu: %d\n", karel_beepers);
printf("tu je %d beeprov", world[karel_y][karel_x]);
printf(" \norientacia %d \nclear? %c\nblocked? %c \n", karel_direction, frontIsClear(), frontIsBlocked());
printf("\n");
int i,j;
for(i=0;i<height;i++){
for(j=0;j<width;j++){
if(karel_y==i && karel_x==j)
{
if (karel_direction==0) printf("v");
else if(karel_direction==90) printf(">");
else if(karel_direction==180) printf("^");
else if(karel_direction==270) printf("<");
}
else
{
if (world[i][j] == WALL) printf("#");
if (world[i][j] == EMPTY) printf(".");
if (world[i][j] > 0) printf("*");
}
}
printf("\n");
}
sleep(1000);
}
void turnLeft()
{
karel_direction += 90;
karel_direction = karel_direction % 360;
draw();
}
frontIsBlocked()
{
int x = karel_x;
int y = karel_y;
if(karel_direction==0) x++ ; //v <-y->
if(karel_direction==180) x--; //^ x
if(karel_direction==90) y++; //> |
if(karel_direction==270) y--; //< v
if (world[x][y] != EMPTY) return 'a';
else return 'n';
}
frontIsClear()
{
int x = karel_x;
int y = karel_y;
if(karel_direction==0) x++; // v
else if(karel_direction==180) x--; // ^
else if(karel_direction==90) y++; // >
else if(karel_direction==270) y--; // <
if (world[x][y] != WALL) return 'a';
else return 'n';
}
void movek()
{
int x,y;
if (frontIsClear() == 'a')
{
if(karel_direction==0) karel_x++; //v <-y->
if(karel_direction==180) karel_x--; //^ x
if(karel_direction==90) karel_y++; //> |
if(karel_direction==270) karel_y--; //< v
draw();
}
else printf("\nchyba, je tu stena\n\n");
}
beepersInBag()
{
if (karel_beepers >= 1) return 'a';
else return 'n';
}
noBeepersInBag()
{
return !beepersInBag();
}
beepersPresent()
{
if (world[karel_y][karel_x] > 0) return 'a';
else return 'n';
}
putBeeper()
{
if (world[karel_y][karel_x] >= 0)
{
world [karel_y][karel_x] += 1;
karel_beepers--;
}
else printf("nie su tu beepre\n");
draw();
}
pickBeeper()
{
if (world[karel_y][karel_x] >0)
{
world [karel_y][karel_x] -= 1;
karel_beepers++;
}
else printf("tu nie ju beper");
draw();
}
void testSensors()
{
// printf("suradnice: x:%d y:%d \norientacia %d \nclear? %c\nblocked? %c \n", karel_x, karel_y, karel_direction, frontIsClear(), frontIsBlocked());
printf("\nma beepre? %c\npocet beeprov v batohu: %d \nje tu beeper? %c\n", beepersInBag(), karel_beepers, beepersPresent());
printf("tu je %d beeprov\n", world[karel_y][karel_x]);
}