示例#1
0
        /// <summary>
        /// Function to enable the dragdrop event to each card
        /// </summary>
        private void onCardMouseDown(object sender, MouseEventArgs e)
        {
            Card      card  = (Card)sender;
            CardPanel panel = (CardPanel)card.Parent;

            bool canMove = EvaluateCard(card);

            if (canMove)
            {
                this.DoDragDrop(card, DragDropEffects.Move);
            }
            else if (panel.GetCardIndex(card) == panel.GetLength() - 1) //Check if the selected card is at the top of the stack
            {
                this.DoDragDrop(card, DragDropEffects.Move);
            }
            else if (GameRules.IsStackValid(panel.cardStack, panel.GetCardIndex(card))) //Check if the stack is valid
            {
                this.DoDragDrop(card, DragDropEffects.Move);
            }
            else
            {
                MessageBox.Show("This card cannot be moved.");
            }

            bool isGameCompleted = GameRules.isGameCompleted(cardPanels, freecellCardPanels, homecellCardPanels); //Check if the user has won the game

            if (isGameCompleted)
            {
                MessageBox.Show("Congratulations! You have won the game!");
                DialogResult res = MessageBox.Show("Do you want to review your gameplay?", "Confirmation", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                if (res == DialogResult.OK)
                {
                    startCurrentGameAnimation();
                }
            }
        }