Advertisement
MikecIT

29-3

Jun 16th, 2014
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.08 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <Windows.h>
  4.  
  5. #define STARTX1 5 //pocetak 1. zida - x kordinata
  6. #define STARTY1 5 //pocetak 1. zida - y kordinata
  7. #define STARTX2 45 //pocetak 2. zida - x kordinata
  8. #define STARTY2 12 //pocetak 2. zida - x kordinata
  9.  
  10. int main()
  11. {
  12.     int i,j,xu,yu,xo=0,yo=0;
  13.     randomize();
  14.     do{
  15.     xu=random(80);
  16.     }while(xu==0||xu==1||((yu==STARTY1&&xu>=STARTX1&&xu<=STARTX1+24)||(yu==STARTY2&&xu>=STARTX2&&xu<=STARTX2+24)));
  17.     do{
  18.     yu=random(24);
  19.     }while(yu==0||yu==1||((yu==STARTY1&&xu>=STARTX1&&xu<=STARTX1+24)||(yu==STARTY2&&xu>=STARTX2&&xu<=STARTX2+24)));
  20.     printf("%c",201);
  21.     for(i=1;i<=78;i++)printf("%c",205);
  22.     printf("%c",187);
  23.     for(j=1;j<=22;j++)
  24.         {
  25.             printf("%c",186);
  26.             for(i=1;i<=78;i++)printf(" ");
  27.             printf("%c",186);
  28.         }
  29.     printf("%c",200);
  30.     for(i=1;i<=78;i++)printf("%c",205);
  31.     printf("%c",188);
  32.     gotoxy(68,25);
  33.     printf("Autor: Mikec"); // ;)
  34.     gotoxy(STARTX1,STARTY1);
  35.     for(i=1;i<=25;i++)printf("%c",196);
  36.     gotoxy(STARTX2,STARTY2);
  37.     for(i=1;i<=25;i++)printf("%c",196);
  38.     while(1){
  39.     gotoxy(xu,yu);
  40.     printf("%c",254);
  41.  
  42.             gotoxy(xu,yu);
  43.             printf(" ");
  44.             gotoxy(xu+xo,yu+yo);
  45.             xu=wherex();
  46.             yu=wherey();
  47.             printf("%c",254);
  48.             Sleep(70); // BRZINA kretanja
  49.             if(kbhit())
  50.                     switch(getch())
  51.         {
  52.             case 'a': xo=-1; yo=0; break;
  53.             case 'd': xo=1; yo=0; break;
  54.             case 'w': xo=0; yo=-1; break;
  55.             case 's': xo=0; yo=1; break;
  56.             default: gotoxy(xu,yu);
  57.         }
  58.     if((yu==STARTY1&&xu>=STARTX1&&xu<=STARTX1+24)||(yu==STARTY2&&xu>=STARTX2&&xu<=STARTX2+24)){clrscr(); printf("\n   Udarili ste u horizontalni zid!\n\n"); return 0;}
  59.     if(xu==79&&xo==1)gotoxy(xu,yu),printf(" "),xu=2;
  60.     if(xu==2&&xo==-1)gotoxy(xu,yu),printf(" "),xu=79;
  61.     if(yu==2&&yo==-1)gotoxy(xu,yu),printf(" "),yu=23;
  62.     if(yu==23&&yo==1)gotoxy(xu,yu),printf(" "),yu=2;
  63.  
  64.     }
  65.     return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement