Hi. I am beginner and I am making a snake game in C... i am having trouble in moving the snake automatically. that is after every one move, the program stops for further directions. i have seen a lot of questions online regarding my problem but i am unable to understand the answers ppl have posted since I am only a beginner... in ur replies kindly also mention the technique u r using(for xample threads) so that if i havent studied it i can focus on that technique only....
here is my code
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <Windows.h>
#include <time.h>
void GotoXY( HANDLE StdOut, SHORT x, SHORT y )
{
COORD Cord;
Cord.X = x;
Cord.Y = y;
SetConsoleCursorPosition( StdOut, Cord );
}
int main ()
{
printf("You have 3 SECONDS to catch the *");
getch();
system("cls");
HANDLE hStdout = GetStdHandle( STD_OUTPUT_HANDLE );
int cursorx=5, cursory=5, temp;
int score=0;
while (1)
{
HANDLE dot=GetStdHandle( STD_OUTPUT_HANDLE );
srand( time( NULL ) );
int dotx = 10+rand() % 40;
int doty = 2+rand()%25;
int playagain= 0;
COORD Cord;
Cord.X = dotx;
Cord.Y = doty;
SetConsoleCursorPosition(dot, Cord );
printf("*");
time_t start=time(NULL);
while(!(dotx==cursorx && doty==cursory))
{
system("cls");
printf("Your score is: %d", score);
SetConsoleCursorPosition(dot, Cord );
printf("*");
GotoXY(hStdout,cursorx,cursory);
printf("O");
{
temp= getch();
if (temp=='d')
cursorx++;
if (temp=='a')
cursorx--;
if (temp=='w')
cursory--;
if (temp=='s')
cursory++;
}
time_t end=time(NULL);
if( (end - start) > 3)
{
system("cls");
printf("TIME IS UP\n\n");
printf("your score is : %d\n", score);
score=-1;
printf("press 1 and Enter to play again\n");
while(playagain!=1)
scanf("%d", &playagain);
break;
}
}
system("cls");
score++;
printf("\a\a");
}
}