mercredi 9 août 2017

C# else if statement not working

    bool down;
    bool pause;
    public int c1 = 0;
    public int c2 = 0;
    public int c3 = 0;

    int sel_count = 0;
    bool s1_pic = false;
    bool s2_pic = false;
    bool s3_pic = false;

    public Form1()
    {
        InitializeComponent();  
        cardChose()
    }    

    public void cardChose()
    {
        if (c1 == 1)
        {
            select_empty(card1);
        }
        else if (c2 == 1)
        {
            select_empty(card2);
        }
        else if (c3 == 1)
        {
            select_empty(card3);
        }
    }

    public void card1_Click(object sender, EventArgs e)
    {
        c1++;
        cardChose();
    }

    public void card2_Click(object sender, EventArgs e)
    {
        c2++;
        cardChose();
    }

    private void card3_Click(object sender, EventArgs e)
    {
        c3++;
        cardChose();
    }


    public void select_empty(PictureBox a)
    {
        if (s1_pic == false)
        {
            s1.Image = a.Image;
            s1_pic = true;
        }
        else if (s2_pic == false)
        {
            s2.Image = a.Image;
            s2_pic = true;
        }
        else if (s3_pic == false)
        {
            s3.Image = a.Image;
            s2_pic = true;
        }
    }

I have pictureboxes for a mini card game. I can only select three cards from my cards. When I click on my card(which is a picturebox) I want its image to be copied to one of the three selected cards. But when I click on the image of the other cards the same image of the first card appears in all of them.

Aucun commentaire:

Enregistrer un commentaire