我目前正在用 C++ 创建一个 Tic-Tac-Toe 游戏。在放置瓷砖的功能中,我使用了一个无穷无尽的 while 循环来检查 getch(),然后移动光标或放置瓷砖。然而,当我按其他东西然后输入或箭头时,它会在黑板上写下那个字符。但我不想要那个。你能告诉我怎么做吗?
bool moveCursor ( void )
{
int c;
int tmpX = m_Xpos;
int tmpY = m_Ypos;
while (1){
c = getch();
if(c == KEY_LEFT) tmpX--;
if(c == KEY_RIGHT) tmpX++;
if(c == KEY_UP) tmpY--;
if(c == KEY_DOWN) tmpY++;
if (tmpY > m_len ) tmpY--;
if (tmpX > m_len ) tmpX--;
if (tmpY < 1 ) tmpY++;
if (tmpX < 1 ) tmpX++;
if(c == 'q') return false;
if(c == '\n')
{
m_Ypos = tmpY;
m_Xpos = tmpX;
if (checkValidMove(tmpY,tmpX))
{
break;
}
}
if ( c != KEY_LEFT && c != KEY_RIGHT && c != KEY_UP && c != KEY_DOWN && c != 'q' && c != '\n' ) continue;//my try to fix it, but didn't work
move(tmpY,tmpX);
refresh();
}
return true;
}
最佳答案
所以是的,我有点傻——我只需要使用 noecho() 选项
关于c++ - 如何阻止 C++ NCurses 显示按下的键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30622835/