C# を使用してブラックジャック ゲームを作成しようとしています。私はカジノクラスと、カジノのオブジェクトであるプレーヤー、カード、およびデッキクラスを持っています。カジノは次の機能を持つプレーヤーにランダムなカードを配ります。
public void giveRandomCardTo(Player P)
{
P.takeCard(this.deck.getRandomCard());
}
これはうまく機能しますが、タイマーを使用して、閉じたカードの画像がプレーヤーのカードのピクチャ ボックスに移動するようなアニメーションを追加したいと考えました。そこで、この部分を関数に追加しました:
public void giveRandomCardTo(Player P)
{
while (_timerRunning) {/*wait*/ }
this.currentDealingID = P.id;
if (this.currentDealingID >= 0 && this.currentDealingID < this.NumberOfPlayers && this.currentDealingID!=10)
{//Checking the current player is not the dealer.
this.MovingCard.Show(); //Moving card is a picture box with a closed card
_timerRunning=true;
T.Start();
}
P.takeCard(this.deck.getRandomCard());
}
Timer T の Timer.Tick イベントハンドラは次のとおりです。
public void TimerTick(object sender, EventArgs e)
{
movingcardvelocity = getVelocityFromTo(MovingCard.Location, this.Players[this.currentDealingID].CardPBS[0].Location);
double divide=5;
movingcardvelocity = new Point((int)(movingcardvelocity.X / divide), (int)(movingcardvelocity.Y / divide));
this.MovingCard.Location = new Point(this.MovingCard.Location.X + movingcardvelocity.X, this.MovingCard.Location.Y + movingcardvelocity.Y);
//Stop if arrived:
double epsilon = 20;
if (Distance(this.MovingCard.Location, this.Players[this.currentDealingID].CardPBS[0].Location) < epsilon)
{
_timerRunning=false;
this.MovingCard.Hide();
T.Stop();
}
}
タイマーもうまく機能します。しかし、次々とカードを配っていくと、最初のアニメーションが終わるまで待たなければなりません。そして、行はプログラムを無限ループwhile(_timerRunning){/*wait*/}
に陥らせます。void giveRandomCardTo
まで待つにはどうすればよいbool _timerRunning = false
ですか?
助けてくれてありがとう。