私のプログラミングクラスでは、メモリマッチゲームを作成する必要があります。プレーヤーがパネルをクリックすると、画像が表示されます。プレーヤーは2つのパネルをクリックします。画像が一致する場合は削除され、異なる場合は裏向きになります。
これに伴う問題は、同じコード行を使用して両方のパネルの画像を表示し、Thread.Sleepを使用して2番目のタイルの後でプログラムを一時停止しているにもかかわらず、最初のパネルの画像のみが表示されることです。選ばれました。なぜこれが起こっているのかわかりません。助けていただければ幸いです。
private void tile_Click(object sender, EventArgs e)
{
string tileName = (sender as Panel).Name;
tileNum = Convert.ToInt16(tileName.Substring(5)) - 1;
//figure out if tile is locked
if (panelArray[tileNum].isLocked == false)
{
pickNum++;
//although the following line of code is used to display the picture that is stored in the tile array
//what is happening is that it will only display the picture of the first tile that has been picked.
//when a second tile is picked my program seems to ignore this line completely, any ideas?
panelArray[tileNum].thisPanel.BackgroundImage = tiles[tileNum].tileImage;
if (pickNum == 1)
{
pick1 = tileNum;
panelArray[tileNum].isLocked = true;
}
else
{
pick2 = tileNum;
UpdateGameState();
}
}
}
private void UpdateGameState()
{
Thread.Sleep(1500);
if (tiles[pick1].tag == tiles[pick2].tag)//compares tags to see if they match.
{
RemoveTiles();
}
else
{
ResetTiles();
}
pickNum = 0;
guess += 1;
guessDisplay.Text = Convert.ToString(guess);
if (correct == 8)
{
CalculateScore();
}
}