У меня проблема с методами очистки панелей, и я не понимаю, почему.Я проверил весь код и не понимаю, почему он может очистить мой PlayerPanel
.
Из того, что я могу сказать, я нигде не звонил PlayerPanel.Controls.Clear()
или PlayerPanel.Controls.Refresh();
, кроме одной кнопки, котораяимеет это как событие щелчка.
Из моего тестирования я обнаружил, что, если комментарий if then else
в GameDecider()
, программа не очищает панель, но я не могу сказать, почему.
private void ConfirmButtonClick(object sender, EventArgs e)
{
if (currentPlayerDog == null)
{
}
else
{
if(currentPlayerDog.GetChosenValue()!= "")
{
DrawCardButton.Visible = false;SelectedChoiceLabel.Visible = true;ConfirmButton.Visible = false; NextRoundButton.Visible = true;
string pl1attk = currentPlayerDog.GetChosenValue();
string pl2attk = currentComputerDog.GetComputerAttkValue(currentPlayerDog.GetChosenAttk());
SelectedChoiceLabel.Text = "you attack with " + currentPlayerDog.GetChosenAttk() + " " + pl1attk + " | " + "Computer attacks with " + currentPlayerDog.GetChosenAttk() + " " + pl2attk;
currentComputerDog.SetTextVisible();
GameDecider();
RanOutOfCards();
currentPlayerDog.SetSelection = "";
}
else
{
//RanOutOfCards();
}
}
}
private void PlayerWon()
{
round = 0;
currentPlayerDog.SetTextVisible();
currentComputerDog.SetTextVisible();
playerCards.Add(currentComputerDog);
playerCards.Add(currentPlayerDog);
currentComputerDog.Left = 0;
currentComputerDog.Top = 0;
currentPlayerDog.Left = 0;
currentPlayerDog.Top = 0;
try
{
for (int count = 0; count < playerCards.Count; count++)
{
PlayerDeckPanel.Controls.Add(playerCards[count]);
}
}
catch
{
}
}
private void ComputerWon()
{
round = 1;
currentPlayerDog.SetTextHidden();
currentComputerDog.SetTextHidden();
computerCards.Add(currentComputerDog);
computerCards.Add(currentPlayerDog);
currentComputerDog.Left = 0;
currentComputerDog.Top = 0;
currentPlayerDog.Left = 0;
currentPlayerDog.Top = 0;
try
{
for (int count = 0; count < computerCards.Count; count++)
{
ComputerDeckPanel.Controls.Add(computerCards[count]);
}
}
catch
{
}
}
private void IsDrool(int a, int b)
{
if (a < b)
{
PlayerWon();
}
else
{
ComputerWon();
}
}
private void NotDrool(int a ,int b)
{
if (a > b)
{
PlayerWon();
}
else
{
ComputerWon();
}
}
private void GameDecider()
{
string pl1attk = currentPlayerDog.GetChosenValue();
string pl2attk = currentComputerDog.GetComputerAttkValue(currentPlayerDog.GetChosenAttk());
int pl1 = Convert.ToInt32(pl1attk);
int pl2 = Convert.ToInt32(pl2attk);
if (pl1 == pl2)
{
PlayerWon();
}
if (currentPlayerDog.GetChosenAttk() != "Drool")
{
NotDrool(pl1, pl2);
}
else
{
IsDrool(pl1, pl2);
}
}
}