我正在开发一款卡牌游戏,但需要一个功能来使程序停止,直到玩家点击他的手牌PictureBox将其弃置。我的游戏算法如下:
问题在于当一轮游戏结束时,首先弃牌的人会发生变化。如果玩家编号为0(人类玩家),1(第一个AI玩家),2(第二个AI玩家)和3(第三个AI玩家),在第一轮游戏中,首先弃牌的是人类玩家,但在第二轮游戏中,首先弃牌的可能是2号AI玩家,人类玩家必须等待他前面所有的AI玩家弃牌(在这种情况下,回合将变成2-3-0-1)。
如果AI玩家还没有弃牌,我该如何取消单击事件?
更新:
我不总是需要等待所有 AI 玩家都抽完一张牌:如果本轮游戏的获胜者是编号为2的玩家,则回合将变为2-3-0-1:这意味着玩家必须等待2号和3号AI玩家抽完牌,然后玩家必须点击一个PictureBox,循环将返回到AI玩家,然后允许AI玩家1弃牌。
更新2:
我想到了以下解决方案:
int nextDrawer = 0; // the players which will discard a card are determinated in counterclockwise starting from the human player
for (int i = 0; i < players; i++) // untill all the players hasn't drawed a card
{
if (i == 0) .... // the human player has to click on a picture box to discard a card
else .... // an AI player will discard a card which is selected randomly from the 3 cards which AI has got in its hand
}
问题在于当一轮游戏结束时,首先弃牌的人会发生变化。如果玩家编号为0(人类玩家),1(第一个AI玩家),2(第二个AI玩家)和3(第三个AI玩家),在第一轮游戏中,首先弃牌的是人类玩家,但在第二轮游戏中,首先弃牌的可能是2号AI玩家,人类玩家必须等待他前面所有的AI玩家弃牌(在这种情况下,回合将变成2-3-0-1)。
如果AI玩家还没有弃牌,我该如何取消单击事件?
更新:
我不总是需要等待所有 AI 玩家都抽完一张牌:如果本轮游戏的获胜者是编号为2的玩家,则回合将变为2-3-0-1:这意味着玩家必须等待2号和3号AI玩家抽完牌,然后玩家必须点击一个PictureBox,循环将返回到AI玩家,然后允许AI玩家1弃牌。
更新2:
我想到了以下解决方案:
int leader = 0; // who is going to discard first
int nextDiscarder = leader; // next player who's going to discard
for (int i = 0; i < nPlayers; i++) // until all the players hasn't discarded
{
if (nextDiscarder == 0) // the human has to discard
{
enablePictureBoxClickEvent;
// now before the loop continue the program has to wait the event click on a picture box
}
else
{
AI[nextDiscarder].discard(); // the ai player will discard
}
if (nextDiscarder == players - 1) // if nextDiscarder has reached the end of the table
nextDiscarder = 0; // return to the begin until all player has discarded a card
else
++nextDiscarder; // continue to discard with the next player
}
在我的点击事件中,我会这样做:
private myEventClick(object sender, EventArgs e)
{
.... // do the instructions needed to discard a card
disableMyEventClick;
returnToLoop;
}
但主要问题是我不知道如何用代码编写我的指令returnToLoop
。
while(true) {//检查标志变化并退出循环}
。当然,这会中断线程,因此该线程上的任何其他操作也将暂停。另一个选项是递归checkFlag(flag) { if(flag==false) checkFlag(); else //something}
。 - Ashwin Gupta