0

I'm trying to make a snake in the command line when the snake itself is created with O's and the apples are dots "."'s. Now... I know hot to get arrow keys and I know the algorithm but the snake needs to move (using Sleep and animations) and also have getch() on all the time. How do I do that ? Isn't that multithreading ? I just need the thread with the getch() and to operate it with other functions.

user3220493
  • 267
  • 2
  • 4
  • 8

1 Answers1

0

You can use kbhit (or _getch and _kbhit) to peek and see if there are some keys pressed. And only if there are some, get it with getch. Also see this question and answer for an example.

Community
  • 1
  • 1
Gassa
  • 8,546
  • 3
  • 29
  • 49
  • Aren't those only for Windows? I think the OP is talking about `getch()` from `curses.h`. [This](http://www.flipcode.com/archives/_kbhit_for_Linux.shtml) article explains how to get `_kbhit` functionality under `curses`. – pat Mar 20 '14 at 07:40
  • Can you determine which key was pressed using kbhit? – user3220493 Mar 20 '14 at 08:17