私はschoolproject用のメモリゲームを作成しています。プレーヤーがゲームに勝ったときにメッセージボックスを表示するという問題があります。 "誰にも解決策がありますか?コードのC#すべてのpictureboxに値があると警告を発する方法
一方の部分:
private void Card1_Click(object sender, EventArgs e)
{
Card1.Image = Properties.Resources.car1;
if(usedCard1 == null)
{
usedCard1 = Card1;
}
else if(usedCard1 != null && usedCard2 == null)
{
usedCard2 = Card1;
}
if(usedCard1 != null && usedCard2 != null)
{
if(usedCard1.Tag == usedCard2.Tag)
{
usedCard1 = null;
usedCard2 = null;
Card1.Enabled = false;
Dupcard1.Enabled = false;
points = Convert.ToInt32(ScoreCounter.Text);
points = points + 10;
ScoreCounter.Text = Convert.ToString(points);
}
else
{
points = Convert.ToInt32(ScoreCounter.Text);
points = points - 10;
ScoreCounter.Text = Convert.ToString(points);
timer4.Start();
}
}
}
private void Dupcard1_Click(object sender, EventArgs e)
{
Dupcard1.Image = Properties.Resources.car1;
if (usedCard1 == null)
{
usedCard1 = Dupcard1;
}
else if (usedCard1 != null && usedCard2 == null)
{
usedCard2 = Dupcard1;
}
if (usedCard1 != null && usedCard2 != null)
{
if (usedCard1.Tag == usedCard2.Tag)
{
usedCard1 = null;
usedCard2 = null;
Card1.Enabled = false;
Dupcard1.Enabled = false;
points = Convert.ToInt32(ScoreCounter.Text);
points = points + 10;
ScoreCounter.Text = Convert.ToString(points);
}
else
{
points = Convert.ToInt32(ScoreCounter.Text);
points = points - 10;
ScoreCounter.Text = Convert.ToString(points);
timer4.Start();
}
}
}
private void Win()
{
foreach(PictureBox picture in cardsHolder.Controls)
{
if(picture != null)
{
}
}
MessageBox.Show("You've matched all cards", "Congratulations");
Close();
}
PS:cardsHolderパネルの名前であり、勝利プレイヤーがゲームに勝利した場合、メッセージをトリガする方法です。
どのカードが一致したかをどのように把握していますか? – Jens
@Robinあなたが必要とするものをよりよく理解できるように、ゲームのルールを投稿できますか? –