Here is the program.
void main( )
{
int h, v;
h = 1; v = 10;
while ( !kbhit( ) || h <= 80 )
{
gotoxy( h, v );
printf( "<--->" );
delay( 200 );
clrscr( );
h = h + 1;
}
getch( );
}
I am making a program in C, in which I have used kbhit()
to run a loop until a key is pressed.
so here the arrow "<--->"
will keep on moving forward until a key is pressed or until it reaches the last pixel of the screen.
What I want is that the program should increment h by 1 everytime 'd'
is pressed and decrement by 1 everytime 'a'
is pressed. i.e h++;
and h--;
and run another loop until a character is pressed.
The idea is more like the Snake game, in which the snake keeps on moving in a certain direction until a key is pressed. Help please!