nato ci mam ist na urad prace som sa nepytal tak tu nespamuj a pis k veci
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Zobrazi� pr�spevky Menu
#include <string.h>
#include <stdio.h>
#include <windows.h>
#define MAX_HEIGHT 20
#define MAX_WIDTH 20
#define WALL -1
#define EMPTY 0
#define DELAY 500
static int world [MAX_HEIGHT] [MAX_WIDTH];
static int height;
static int width;
static int x,y;
DIRECTION direction;
static void draw();
static int drawKarel();
typedef enum
{
EAST=0,
NORTH=90,
WEST=180,
SOUTH=270
};
static void draw()
{
int i,j;
system("cmd/c cls");
for(i=height-1; i>=0; i--)
{
for(j=0;j<width;j++)
{
if (x==j&&y==i)
putchar(drawKarel());
else if (world[i][j]==WALL)
putchar('#');
else
printf("%d",world[i][j]);
putchar('\n');
}
}
sleep(DELAY);
}
static int drawKarel()
{
switch(direction){
case EAST: return '>';
case NORTH: return'^';
case WEST: return'<';
case SOUTH: return 'v';
}
return '?';
}
void turnOn()
{
char*map="########|#--#---#|#---*--#|#--#**-#|##-#---#|#---*#-#|#----->#|########";
int i=0,j=0,k;
for(k=0;k<strlen(map);k++)
{
switch(map[k])
{
case'#':
world[i][j]=WALL;
break;
case'-':
world[i][j]=EMPTY;
break;
case'$':
world[i][j]=1;
break;
case '>':
x=j;
y=i;
direction=EAST;
break;
case '^':
x=j;
y=i;
direction=NORTH;
break;
case'<':
x=j;
y=i;
direction=WEST;
break;
case 'v':
x=j;
y=i;
direction=SOUTH;
break;
case'|':
i++;
j=-1;
break;
}
j++;
}
height=i+1;
width=j;
draw();
}
void turnLeft()
{
direction+=90;
if(direction>270)
direction=EAST;
draw();
}