我正在开发一款纸牌游戏,但我需要一个功能来停止该程序,直到玩家没有点击他的卡片的图片框来丢弃它。 我游戏的算法是这样的:等到点击事件被解雇C#
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(第一人工智能玩家),2(第二人工智能玩家)和3(第三人工智能玩家)的数值计算,则第一个弃牌的人是玩家,但是第二个是第一个丢弃的可能是2 AI玩家,而人类玩家必须等到所有在他之前丢弃一张牌的AI玩家(在这种情况下,这个回合将是2-3-0-1)。
如果AI玩家还没有丢弃卡,我该如何取消点击事件?
UPDATE
我并不总是需要等待的是所有 AI球员们drawed一张牌:如果曼斯的赢家是数字2,圆是2-3-0 -1:这意味着玩家必须等待AI玩家2和3的画面,然后玩家必须点击一个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
。
你有没有试过设置'布尔'标志来帮助你?例如:当人类玩过时,将一个标志设置为假,然后只有当另外3个有丢弃的卡时(也许使用计数器)才将其设置为真。然后确保当标志为真时,人只能丢弃他们的卡。我希望这有助于! – andeart
试过吗? https://msdn.microsoft.com/en-us/library/system.componentmodel.canceleventargs.cancel(v=vs.110).aspx – Zuzlx
我认为“returnToLoop”是不需要的,因为事件没有终止循环,所以返回到循环是自动的,因为事件并没有带你离开线程。 – gridtrak