dimanche 3 mars 2019

If statements clearing controls from panels by themsemselves

Hi everyone so I haven’t done any programming for a long time so decided to a little project to get back up to speed and I’m having an issue with the methods clearing my panels and I can’t see why, I have checked all over my code and can’t see why it would clear my "PlayerPanel". From what I can tell I haven't called "PlayerPanel.Controls.Clear()" or "PlayerPanel.Controls.Refresh();" anywhere except for one button that has it as a click event. From my testing I’ve found that if a comment out the if then else in "GameDecider()" the program doesn’t clear the panel but i cant tell why . Any help is appreciated .

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);
        }


    }
}

Aucun commentaire:

Enregistrer un commentaire