I'm trying to code the game of Simon(try to mimic the computers choice of four buttons) for a project. I'm kind of stuck because the computer generates a random choice, but I need to completely halt and wait for the user to enter his choice.(Done with the aswd keys; either up, down, left, or right) How can I do this? I'm trying to use _kbhit but it's not working as intended.

Any help would be greatly appreciated.

Recommended Answers

All 6 Replies

Maybe because kbhit() doesn't read keys, it only tells you whether there is a key available.

To actually read it, use getch() or something like it (since you seem to be in DOS land).

To actually read it, use getch()

Oh... oh!. You are going to hear about this one. :)

Oh... oh!. You are going to hear about this one. :)

I don't get it. The only other alternative is to use some curses library.

I'm trying to code the game of Simon(try to mimic the computers choice of four buttons) for a project. I'm kind of stuck because the computer generates a random choice, but I need to completely halt and wait for the user to enter his choice.(Done with the aswd keys; either up, down, left, or right) How can I do this? I'm trying to use _kbhit but it's not working as intended.

Any help would be greatly appreciated.

Based strictly on this description, just read a line from the user. When he hits ENTER check the characters.

getchar(); the line just before return 0; works for me.

Dick

>getchar(); the line just before return 0; works for me.
Except we aren't talking about pausing the console after the execution is finished...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.