Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.c
- // snakew
- //
- // Created by Rodrigo Furuta on 11/9/11.
- // Copyright 2011 __MyCompanyName__. All rights reserved.
- //
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <windows.h>
- #include <conio.h>
- void gotoxy(int x, int y)
- {
- COORD c;
- c.X = x - 1;
- c.Y = y - 1;
- SetConsoleCursorPosition (GetStdHandle(STD_OUTPUT_HANDLE), c);
- }
- struct andar
- {
- int x;
- int y;
- };
- int main (void)
- {
- struct andar a1,a2,a3,a4,a5,a6;
- char b;
- int a[25][80],x,k,i,c,j,r;
- a1.x=20; a1.y=15;
- a2.x=21; a2.y=15;
- a3.x=22; a3.y=15;
- a4.x=23; a4.y=15;
- a5.x=24; a5.y=15;
- a6.x=25; a6.y=15;
- for(i=0;i<25;i++)
- for(j=0;j<80;j++)
- a[i][j]=32;
- a[2][2]=0;
- a[22][2]=0;
- a[2][77]=0;
- a[22][77]=0;
- for(i=0;i<80;i++)
- a[1][i]=42;
- for(i=0;i<80;i++)
- a[24][i]=42;
- for(i=0;i<24;i++)
- a[i][0]=42;
- for(i=0;i<24;i++)
- a[i][79]=42;
- do{
- system("cls");
- 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);
- gotoxy(1,2);
- printf("%c %c",186,186);
- gotoxy(1,3);
- printf("%c %c",186,186);
- gotoxy(1,4);
- printf("%c %c",186,186);
- gotoxy(1,5);
- printf("%c %c",186,186);
- gotoxy(1,6);
- printf("%c %c",186,186);
- gotoxy(1,7);
- printf("%c %c",186,186);
- gotoxy(1,8);
- printf("%c %c",186,186);
- gotoxy(1,9);
- printf("%c %c",186,186);
- gotoxy(1,10);
- printf("%c %c",186,186);
- gotoxy(1,11);
- printf("%c %c",186,186);
- gotoxy(1,12);
- printf("%c %c",186,186);
- gotoxy(1,13);
- printf("%c %c",186,186);
- gotoxy(1,14);
- printf("%c %c",186,186);
- gotoxy(1,15);
- printf("%c %c",186,186);
- gotoxy(1,16);
- printf("%c %c",186,186);
- gotoxy(1,17);
- printf("%c %c",186,186);
- gotoxy(1,18);
- printf("%c %c",186,186);
- gotoxy(1,19);
- printf("%c %c",186,186);
- gotoxy(1,20);
- printf("%c %c",186,186);
- gotoxy(1,21);
- printf("%c %c",186,186);
- gotoxy(1,22);
- printf("%c %c",186,186);
- gotoxy(1,23);
- printf("%c %c",186,186);
- gotoxy(1,24);
- printf("%c %c",186,186);
- gotoxy(1,25);
- 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);
- gotoxy(20,12);
- printf("INSIRA A VELOCIDADE DA COBRA:");
- gotoxy(2,20);
- printf("VELOCIDADES: 1,2,3,4,5,6,7,8,9,10");
- gotoxy(2,21);
- printf("VELOCIDADE RECOMENDADA: 5");
- gotoxy(9,13);
- printf("VELOCIDADE:");
- fflush(stdin);scanf("%d",&k);fflush(stdin);
- if(k>10 || k<1)
- {
- system("cls");
- gotoxy(20,12);
- printf("VELOCIDADE DIGITADA NAO CADASTRADA.");
- gotoxy(20,13);
- printf("FAVOR INSERIR UM VALOR ENTRE 1 E 10.");
- gotoxy(20,14);
- printf("PRECIONE ENTER PARA CONTINUAR.");
- getchar();
- }
- else
- {
- switch (k)
- {
- case 1:x=10;break;
- case 2:x=20;break;
- case 3:x=30;break;
- case 4:x=40;break;
- case 5:x=50;break;
- case 6:x=60;break;
- case 7:x=70;break;
- case 8:x=80;break;
- case 9:x=90;break;
- case 10:x=100;break;
- }
- system("cls");
- for(i=0;i<25;i++)
- for(j=0;j<80;j++)
- printf("%c",a[i][j]);
- do
- {
- if(a[a1.x][a1.y]==32)
- {
- gotoxy(a1.x,a1.y);
- printf("%c",178);
- gotoxy(a2.x,a2.y);
- printf("%c",178);
- gotoxy(a3.x,a3.y);
- printf("%c",177);
- gotoxy(a4.x,a4.y);
- printf("%c",177);
- gotoxy(a5.x,a5.y);
- printf("%c",176);
- gotoxy(a6.x,a6.y);
- printf(" ");
- a6=a5;
- a5=a4;
- a4=a3;
- a3=a2;
- a2=a1;
- }
- r=rand() %20;
- switch (r)
- {
- case 0:c++;break;
- case 19:c--;break;
- }
- if(c==-1) c=3;
- if(c==4) c=0;
- switch (c)
- {
- case 0:a1.y--;break; //cima
- case 1:a1.x++;break; //direita
- case 2:a1.y++;break; //baixo
- case 3:a1.x--;break; //esquerda
- }
- _sleep(x);
- }while(!kbhit==0);
- }
- }while(1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment