rendered paste body#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <string.h>
int segments[2520];
struct segment {int dir, x, y;}
segment segments[2520];
void main (void)
{
int gdriver = DETECT, gmode, errorcode;
initgraph (&gdriver, &gmode, "C:\\BC\\BGI");
//graph checking
errorcode = graphresult();
if (errorcode != grOk)
{
clrscr ();
printf ("Graphics error: %s\n", grapherrormsg (errorcode));
printf ("Press any key to halt");
getch ();
exit (1);
}
//variables defination
int i, j, x, y, x1, y1, k = 0, l, m, r, t;
randomize();
rectangle (13, 13, 627, 397);
l = random (62);
m = random (39);
if (l == 0) l+10;
if (l == 62) l-10;
if (m == 0) m+10;
if (m == 39) m-10;
x1 = l*10;
y1 = m*10;
i = 31;
j = 19;
circle (i*10, j*10,5);
int key, g,n = 0, h;
segments[1291].x = 310;
segments[1291].y = 200;
circle (segments[1291].x, segments[1291].y, 10);
do
{
/*setcolor (7);
circle (x1, y1, 5);
setfillstyle (1, 7);
floodfill (x1, y1, 7);
r = i;
t = j;
int z;
if (kbhit()) key = getch();
if (key == 80) {j++, r=i, t=j-(n+1);}
if (key == 72) {j--, r=i, t=j+(n+1);}
if (key == 77) {i++, r=i-(n+1), t=j;}
if (key == 75) {i--, r=i+(n+1), t=j;}
delay (150);
setcolor (1);
circle (r*10, t*10, 5);
setcolor (7);
circle (i*10, j*10, 5);*/
if (getpixel(i*10 + 3, j*10) == 15 | getpixel (i*10 - 3, j*10) == 15 |
getpixel ( i*10, j*10 + 3) == 15 | getpixel ( i*10, j*10 - 3) == 15)
{
outtextxy ( 240, 430, "Snake has left the border");
getch ();
closegraph ();
}
if (i*10 == x1 && j*10 == y1)
{
n++;
circle(x1, y1, 5);
setfillstyle(1, 0);
floodfill(x1, y1, 0);
l = random(62);
m = random(39);
if (l==0) l+10;
if (l==62) l-10;
if (m==0) m+10;
if (m==39) m-10;
x1 = l*10;
y1 = l*10;
circle(x1, y1, 5);
setfillstyle(1, 7);
floodfill(x1, y1, 7);
}
}
while(key!=27);
getch();
closegraph();
}