我一直在尝试pong
使用. 我已经成功地为两个玩家创建了两个酒吧。问题是,当两个玩家按下相应的键时,只有一个在移动。ncurses
terminal
所以,我在网上搜索,发现我们可以使用窗口,我们可以拥有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,但当两个玩家同时按下时,我仍然看不到两者同时移动。
任何建议请...