Advertisement
Avdluna

Cobra

Aug 28th, 2015
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.78 KB | None | 0 0
  1. #include<windows.h>
  2. #include<stdio.h>
  3. #include<conio.h>
  4. #include<time.h>
  5. //#include<stdlib.h>
  6. #include<iostream>
  7. void mgotoxy(int x,int y)
  8. {   COORD p={x,y};
  9.     SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),p);
  10. }
  11. main()
  12. {   int x,d=2,cx[300]={1,2},cy[300]={7,7},t=1,mx,my;
  13.     char tecla='a';
  14.     //system("MODE con cols=27 lines=20");
  15.     for(x=0;x<18;x++)
  16.     {   mgotoxy(0,x);
  17.         printf("%c",219);
  18.     }
  19.     for(x=0;x<26;x++)
  20.     {   mgotoxy(x,0);
  21.         printf("%c",219);
  22.     }
  23.     for(x=0;x<18;x++)
  24.     {   mgotoxy(26,x);
  25.         printf("%c",219);
  26.     }
  27.     for(x=0;x<27;x++)
  28.     {   mgotoxy(x,18);
  29.         printf("%c",219);
  30.     }
  31.     srand(time(NULL));
  32.     mx=(rand()%25)+1;
  33.     my=(rand()%17)+1;
  34.     while(tecla!='s')
  35.     {   while(tecla!='s'&&!(tecla=kbhit()))
  36.         {   for(x=t;x>0;x--)
  37.             {   cx[x]=cx[x-1];
  38.                 cy[x]=cy[x-1];
  39.             }
  40.             if(d==0)cx[0]--;
  41.             if(d==1)cy[0]--;
  42.             if(d==2)cx[0]++;
  43.             if(d==3)cy[0]++;
  44.             mgotoxy(cx[t],cy[t]);
  45.             printf(" ");
  46.             if(mx==cx[0]&&my==cy[0])
  47.             {   t++;
  48.                 mx=(rand()%25)+1;
  49.                 my=(rand()%17)+1;
  50.             }
  51.             mgotoxy(cx[0],cy[0]);
  52.             printf("%c",219);
  53.             mgotoxy(mx,my);
  54.             printf("%c",1);
  55.             Sleep(500);
  56.             for(x=1;x<t;x++)
  57.             {   if(cx[0]==cx[x]&&cy[0]==cy[x])tecla='s';
  58.             }
  59.             if(cy[0]==0||cy[0]==18||cx[0]==0||cx[0]==26)tecla='s';
  60.         }
  61.         if(tecla!='s')tecla=getch();
  62.         if(tecla=='K')d=0;
  63.         if(tecla=='H')d=1;
  64.         if(tecla=='M')d=2;
  65.         if(tecla=='P')d=3;
  66.         if(cy[0]==0||cy[0]==18||cx[0]==0||cx[0]==26)tecla='s';
  67.     }
  68.     getch();
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement