Advertisement
Guest User

Untitled

a guest
May 19th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.71 KB | None | 0 0
  1. #include <conio.h>
  2. main() {
  3.     int pole [81][51];
  4.    int i,j;
  5.  
  6.    for(i=1;i<81;i++)
  7.     for(j=1;j<51;j++)
  8.         pole[i][j]=0;
  9.  
  10.    for(i=1;i<81;i++){              //stena
  11.             pole[i][1]=1;
  12.             pole[i][49]=1;
  13.    }
  14.  
  15.    for(j=1;j<50;j++){                 //stena
  16.             pole[1][j]=1;
  17.             pole[80][j]=1;
  18.    }
  19.  
  20.     for (i=1;i<39;i++)
  21.         for (j=16;j<32;j++)
  22.                  pole[i][j]=1;
  23.  
  24.         for (i=52;i<70;i++)
  25.         for (j=1;j<18;j++)
  26.             pole[i][j]=1;
  27.  
  28.       for (i=48;i<80;i++)              //stena
  29.         for (j=42;j<46;j++)
  30.             pole[i][j]=1;
  31.  
  32.  
  33.    textmode(C4350);
  34.    textbackground(BLUE);
  35.    textcolor(LIGHTGREEN);
  36.    clrscr();
  37.    _setcursortype(_NOCURSOR);
  38.  
  39.  
  40.    for(i=1;i<81;i++)                   // za steni
  41.         for(j=1;j<50;j++)
  42.             if(pole[i][j]==1){
  43.                 gotoxy (i,j);
  44.                 cprintf("%c",219);
  45.             }
  46.  
  47.    int x=5,y=5,pos=1;
  48.  
  49.    while (1) {
  50.     if (pos==1) {x++;y++;}
  51.       if (pos==2) {x++;y--;}
  52.       if (pos==3) {x--;y--;}
  53.       if (pos==4) {x--;y++;}
  54.  
  55.       if (pole[x][y+1]==1 && pos==1) pos=2;    //posoka pri stena
  56.       if (pole[x+1][y]==1 && pos==2) pos=3;
  57.       if (pole[x][y-1]==1 && pos==3) pos=4;
  58.       if (pole[x][y+1]==1 && pos==4) pos=3;
  59.       if (pole[x-1][y]==1 && pos==3) pos=2;
  60.       if (pole[x][y-1]==1 && pos==2) pos=1;
  61.       if (pole[x-1][y]==1 && pos==4) pos=1;
  62.       if (pole[x+1][y]==1 && pos==1) pos=4;
  63.  
  64.       if (pole[x-1][y+1]==1 && pos==4) pos=2;   //posoka pri agal
  65.       if (pole[x+1][y+1]==1 && pos==1) pos=3;
  66.       if (pole[x+1][y-1]==1 && pos==2) pos=4;
  67.       if (pole[x-1][y-1]==1 && pos==3) pos=1;
  68.  
  69.       gotoxy(x,y);
  70.       cprintf ("*");
  71.       for (double z=-4000000;z<4000000;z++);
  72.       gotoxy (x,y);
  73.       cprintf (" ");
  74.    } //KRAQ NA WHILE
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement