【发布时间】:2020-11-16 22:42:28
【问题描述】:
我正在尝试在终端中构建一个简单的俄罗斯方块游戏。当玩家按下箭头键时,我需要移动棋子。我听说过 getch() 方法,但它似乎不适用于箭头键(它们都是用相同的 int 代码检测到的:27)。我该怎么办?
这是我当前的代码:
initscr();
int inputCode;
do
{
inputCode = getch();
// here I would put my code to move the pieces if the code is right
} while (inputCode != 113); // q to exit
endwin();
真诚地, 托马斯
【问题讨论】:
-
你可以随时使用 wasd
-
getch()在按下时应该返回KEY_UP、KEY_DOWN、KEY_LEFT或KEY_RIGHT。尝试在循环之前添加对raw(); keypad(stdscr, TRUE); noecho();的调用。