0

我一直在尝试pong使用. 我已经成功地为两个玩家创建了两个酒吧。问题是,当两个玩家按下相应的键时,只有一个在移动。ncursesterminal

所以,我在网上搜索,发现我们可以使用窗口,我们可以拥有logical curser每个窗口,从而并行执行来自玩家的命令。我的程序的代码片段如下所示:

pthread_t player_1, player_2;
pthread_create(&player_1, NULL, (void*)&player_1_move, (void*)pl_window);
pthread_create(&player_2, NULL, (void*)&player_2_move, (void*)p2_window);

while(1)
{
    char c=getch();
    if(key is from p1)
         //signal player_1 thread to refresh the bar position

    if(key is from p2)
         //refresh it for player_2 by signaling 2nd thread..

}
//here player_1_move and player_2_move are the functions for changing the bar position         for each of the players..I have created two windows in which i draw these bars, which i haven't shown in my code..

问题是虽然我使用了 pthreads,但当两个玩家同时按下时,我仍然看不到两者同时移动。

任何建议请...

4

1 回答 1

0

正如克雷格所说......当同时按下两个键时,终端无法处理。它会选择其中任何一个。这正是问题所在。即使我们使用 . 也无法解决pthreads

于 2013-02-05T06:19:12.953 回答