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.
Asked
Active
Viewed 325 times
0
-
Don't make `snakes`. Make `snacks` instead. – devnull Mar 20 '14 at 07:07
-
@ajay I'm wondering how to make animation (using sleep) while preparing for getch(); – user3220493 Mar 20 '14 at 08:06
1 Answers
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.
-
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
-