【发布时间】:2022-01-24 02:57:17
【问题描述】:
我一直在尝试使用 Qt 用 C++ 制作 GUI Blackjack 游戏。然而,我在路上遇到了路障。去年我用纯 C++ 制作了游戏和游戏逻辑(链接如下)。我正在尝试使用相同的代码来构建游戏的 GUI 版本Github/Blackjack。
这主要是为了让卡片出现,添加这些卡片的价值,经销商和玩家设置。
在 C++ 版本中,我制作了一个所有玩家的向量,并在其末尾添加了经销商,然后使用 for 循环,我将遍历玩家以让他们玩。
在 Qt 中,我为播放器控件创建了一个带有两个按钮“Hit”和“Stand”的小部件。 “Hit”按钮很简单,将按钮的点击事件与播放器的hit成员函数联系起来。
ctrl = new PlayerControl(nullptr, mainPlayer);
connect(ctrl->ui->hitButton, &QPushButton::clicked, [mainPlayer]{
mainPlayer->hit();
});
遍历向量的代码:
for (size_t i = 0; i < players.size(); i++)
{
if (i == playerPos - 1)
{
ctrl->setVisible(true);
//how to make the loop to pause here until the user presses the
//"Stand button", and then proceed with the rest of the loop?
}
else if (i == players.size() - 1)
dealerPlay();
else
computerPlay(players[i]);
}
我将非常感谢任何帮助。 :)
【问题讨论】: