我们正在OpenGL中制作一个Maze类程序,我们允许用户使用箭头键在屏幕上移动目的地。当用户使用箭头键到达目的地时,我想禁止用户再次使用键盘。有没有办法可以做某种glutSpecialFunc.disable?这是我想在这个if语句中放置禁用的地方:
void myKeyboard(int keys, int x, int y){
switch(keys){ ...
}
if(location == G.source){
cout<<"\nYou have completed the game";
drawShortestPath();
/* Enter disable code here */
}
}
答案 0 :(得分:1)
您可以在玩家到达目标/目的地时简单地切换布尔值,并在myKeyboard()
函数中检查该布尔值。
bool game_done = false;
void myKeyboard(int keys, int x, int y) {
if (!game_done) {
switch(keys) {
// ... the rest of your code ...
}
}
}
然后当玩家到达目标/目的地时,只需说出game_done = true;
而不是调用布尔值game_done
,你可以改为称之为lock_keyboard
,这可能会更有意义。
然后,如果您想再次“激活”键盘,只需再次切换布尔值(将其设置为false)