//i write program of snake mania game but it has one problem
//i have no idea how snake is finish behind head like tail is remain same place //please help me
//my program is there
if (kbhit ()){
ch = getch (); //detect cheracter from keyboard
switch (ch){
case 'd':
{if (ch!='a')
ch='d';
break;}
case 'w':
{if (ch!='s')
ch='w';
break;}
case 'a':
{if (ch!='d')
ch='a';
break;}
case 's':
{if (ch!='w')
ch='s';
break;}}
}
if (ch=='d'){dx+=1;snakeprogress (dy,dx);}
else if (ch=='w'){dy-=1;snakeprogress (dy,dx);}
else if (ch=='a'){dx-=1;snakeprogress (dy,dx);}
else if (ch=='s'){dy+=1;snakeprogress (dy,dx);}
detectcollision (dy,dx);
bountary();
counter+=1;
Sleep (200);
system ("cls");
}
displayscoreboard ();
system ("pause");
}
void drawfood ()
{ do {yf = rand() % (40 - 2) +1 ; // Generate random x and y values within the map
xf = rand() % (20 - 2) + 1;
}while (map [xf][yf] != 32); // If location is not free try again
map[xf][yf]='@'; }
void snakeprogress (int y,int x)
{if (map [dy][dx]==42)
{life=0;running=false;} //end game when colliode snake with itself
//if (counter /3==1)
// {map [18][4]= 32;}
map [y][x] = 42;
//if (counter==0)
// {x1=x;y1=y;}
}
int detectcollision (int dy,int dx)
{
if (dx==0||dy==0||dx==38||dy==19) //collision with walls
{life =0;running = false;}
if (xf==dy&&yf==dx) //collision with food
{score +=20;drawfood ();}