rod1231234

:p

Nov 9th, 2011
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 7.57 KB | None | 0 0
  1. //
  2. //  main.c
  3. //  snakew
  4. //
  5. //  Created by Rodrigo Furuta on 11/9/11.
  6. //  Copyright 2011 __MyCompanyName__. All rights reserved.
  7. //
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include <windows.h>
  13. #include <conio.h>
  14. void gotoxy(int x, int y)
  15. {
  16.     COORD c;
  17.     c.X = x - 1;
  18.     c.Y = y - 1;
  19.     SetConsoleCursorPosition (GetStdHandle(STD_OUTPUT_HANDLE), c);
  20. }
  21. struct andar
  22. {
  23.     int x;
  24.     int y;
  25. };
  26. int main (void)
  27. {
  28.     struct andar a1,a2,a3,a4,a5,a6;
  29.     char b;
  30.     int a[25][80],x,k,i,c,j,r;
  31.     a1.x=20; a1.y=15;
  32.     a2.x=21; a2.y=15;
  33.     a3.x=22; a3.y=15;
  34.     a4.x=23; a4.y=15;
  35.     a5.x=24; a5.y=15;
  36.     a6.x=25; a6.y=15;
  37.     for(i=0;i<25;i++)
  38.         for(j=0;j<80;j++)
  39.             a[i][j]=32;
  40.     a[2][2]=0;
  41.     a[22][2]=0;
  42.     a[2][77]=0;
  43.     a[22][77]=0;
  44.     for(i=0;i<80;i++)
  45.         a[1][i]=42;
  46.     for(i=0;i<80;i++)
  47.         a[24][i]=42;
  48.     for(i=0;i<24;i++)
  49.         a[i][0]=42;
  50.     for(i=0;i<24;i++)
  51.         a[i][79]=42;
  52.     do{
  53.         system("cls");
  54.         printf("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",201,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,187);
  55.         gotoxy(1,2);
  56.         printf("%c                                                                              %c",186,186);
  57.         gotoxy(1,3);
  58.         printf("%c                                                                              %c",186,186);
  59.         gotoxy(1,4);
  60.         printf("%c                                                                              %c",186,186);
  61.         gotoxy(1,5);
  62.         printf("%c                                                                              %c",186,186);
  63.         gotoxy(1,6);
  64.         printf("%c                                                                              %c",186,186);
  65.         gotoxy(1,7);
  66.         printf("%c                                                                              %c",186,186);
  67.         gotoxy(1,8);
  68.         printf("%c                                                                              %c",186,186);
  69.         gotoxy(1,9);
  70.         printf("%c                                                                              %c",186,186);
  71.         gotoxy(1,10);
  72.         printf("%c                                                                              %c",186,186);
  73.         gotoxy(1,11);
  74.         printf("%c                                                                              %c",186,186);
  75.         gotoxy(1,12);
  76.         printf("%c                                                                              %c",186,186);
  77.         gotoxy(1,13);
  78.         printf("%c                                                                              %c",186,186);
  79.         gotoxy(1,14);
  80.         printf("%c                                                                              %c",186,186);
  81.         gotoxy(1,15);
  82.         printf("%c                                                                              %c",186,186);
  83.         gotoxy(1,16);
  84.         printf("%c                                                                              %c",186,186);
  85.         gotoxy(1,17);
  86.         printf("%c                                                                              %c",186,186);
  87.         gotoxy(1,18);
  88.         printf("%c                                                                              %c",186,186);
  89.         gotoxy(1,19);
  90.         printf("%c                                                                              %c",186,186);
  91.         gotoxy(1,20);
  92.         printf("%c                                                                              %c",186,186);
  93.         gotoxy(1,21);
  94.         printf("%c                                                                              %c",186,186);
  95.         gotoxy(1,22);
  96.         printf("%c                                                                              %c",186,186);
  97.         gotoxy(1,23);
  98.         printf("%c                                                                              %c",186,186);
  99.         gotoxy(1,24);
  100.         printf("%c                                                                              %c",186,186);
  101.         gotoxy(1,25);
  102.         printf("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",200,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,205,188);
  103.         gotoxy(20,12);
  104.         printf("INSIRA A VELOCIDADE DA COBRA:");
  105.         gotoxy(2,20);
  106.         printf("VELOCIDADES: 1,2,3,4,5,6,7,8,9,10");
  107.         gotoxy(2,21);
  108.         printf("VELOCIDADE RECOMENDADA: 5");
  109.         gotoxy(9,13);
  110.         printf("VELOCIDADE:");
  111.         fflush(stdin);scanf("%d",&k);fflush(stdin);
  112.         if(k>10 || k<1)
  113.         {
  114.             system("cls");
  115.             gotoxy(20,12);
  116.             printf("VELOCIDADE DIGITADA NAO CADASTRADA.");
  117.             gotoxy(20,13);
  118.             printf("FAVOR INSERIR UM VALOR ENTRE 1 E 10.");
  119.             gotoxy(20,14);
  120.             printf("PRECIONE ENTER PARA CONTINUAR.");
  121.             getchar();
  122.         }
  123.         else
  124.         {
  125.             switch (k)
  126.             {
  127.                 case 1:x=10;break;
  128.                 case 2:x=20;break;
  129.                 case 3:x=30;break;
  130.                 case 4:x=40;break;
  131.                 case 5:x=50;break;
  132.                 case 6:x=60;break;
  133.                 case 7:x=70;break;
  134.                 case 8:x=80;break;
  135.                 case 9:x=90;break;
  136.                 case 10:x=100;break;
  137.             }
  138.             system("cls");
  139.             for(i=0;i<25;i++)
  140.                 for(j=0;j<80;j++)
  141.                     printf("%c",a[i][j]);
  142.             do
  143.             {
  144.                 if(a[a1.x][a1.y]==32)
  145.                 {
  146.                     gotoxy(a1.x,a1.y);
  147.                     printf("%c",178);
  148.                     gotoxy(a2.x,a2.y);
  149.                     printf("%c",178);
  150.                     gotoxy(a3.x,a3.y);
  151.                     printf("%c",177);
  152.                     gotoxy(a4.x,a4.y);
  153.                     printf("%c",177);
  154.                     gotoxy(a5.x,a5.y);
  155.                     printf("%c",176);
  156.                     gotoxy(a6.x,a6.y);
  157.                     printf(" ");
  158.                    
  159.                     a6=a5;
  160.                     a5=a4;
  161.                     a4=a3;
  162.                     a3=a2;
  163.                     a2=a1;
  164.                 }
  165.                 r=rand() %20;
  166.                 switch (r)
  167.                 {
  168.                     case 0:c++;break;
  169.                     case 19:c--;break;
  170.                 }
  171.                 if(c==-1) c=3;
  172.                 if(c==4) c=0;
  173.                 switch (c)
  174.                 {
  175.                     case 0:a1.y--;break; //cima
  176.                     case 1:a1.x++;break; //direita
  177.                     case 2:a1.y++;break; //baixo
  178.                     case 3:a1.x--;break; //esquerda
  179.                 }
  180.                 _sleep(x);
  181.             }while(!kbhit==0);
  182.         }
  183.     }while(1);
  184.     return 0;
  185. }
  186.  
  187.  
  188.  
Advertisement
Add Comment
Please, Sign In to add comment