예제 #1
0
        public EndForm(MainForm mainForm, CardInfoForm infoForm)
        {
            _mainForm = mainForm;
            _infoForm = infoForm;

            InitializeComponent();

            _endForm = this;
        }
예제 #2
0
        private void PictureClick(object sender, MouseEventArgs e, Card card, PictureBox pictureBox)
        {
            if (((e.Button & MouseButtons.Left) != 0) && _cards.Count != 0)
            {
                if (_firstCard.clicked && _secondCard.clicked)
                {
                    return;
                }

                // Open a new form display the card information
                CardInformation(card);

                pictureBox.LoadAsync(card.card_images[0].image_url);

                // First card is not clicked at the start or when we get a card match
                if (!_firstCard.clicked)
                {
                    pictureBox.Enabled = false;

                    _firstCard         = card;
                    _firstCard.clicked = true;
                    return;
                }

                // With the previous check if statement, we are sure that this will be the second card
                _secondCard         = card;
                _secondCard.clicked = true;

                if (_firstCard.id == _secondCard.id)
                {
                    // Remove card from the hashset
                    _cards.Remove(_firstCard.id);

                    if (_cards.Count == 0)
                    {
                        _endForm?.Close();
                        _endForm = new EndForm(MainFormRef, _cardInfoForm);
                        _endForm.Show();

                        // Enable all picture boxes so we can still preview them
                        foreach (PictureBox pb in panelCards.Controls)
                        {
                            pb.Enabled = true;
                        }

                        return;
                    }

                    // Disable both picture boxes associated with the image
                    foreach (var pb in _firstCard.pictureBoxes)
                    {
                        panelCards.Controls.Find(pb, true)[0].Enabled = false;
                    }

                    _firstCard  = new Card();
                    _secondCard = new Card();
                    return;
                }

                timerCheckCards.Start();
            }
            // We finished the game, but you can still preview the cards info with right clicking them
            else if ((e.Button & MouseButtons.Right) != 0 && _cards.Count == 0)
            {
                CardInformation(card);
            }
        }