I am a beginner at C++ and trying to code a C++ console based snake game. I was stuck when I cannot move the snake without continuously pressing a key. Now I can do by just pressing the key once but I still do not understand the function of _kbhit() which has helped me do it.
void snake_movement(){
if(_kbhit())
switch (getch())
{
case 'w':
y_cordinate--;
break;
case 'a':
x_cordinate--;
break;
case 's':
y_cordinate++;
break;
case 'd':
x_cordinate++;
break;
default:
break;
}
}