示例#1
0
        /// <summary>
        /// Determine the conditions of the game and try to move the card appropriately.
        /// </summary>
        /// <param name="clickedCard"></param>
        /// <param name="source"></param>
        private void TryToPlayCard(Card clickedCard, PictureBox source)
        {
            FaceValue facevalueOfClickedCard = clickedCard.GetFaceValue();

            Hand[]       suitPiles            = Solitare_Game.GetSuitPiles();
            PictureBox[] suitPilePictureBoxes = ReturnSuitPilePictureBoxes();
            Hand         discardPile          = Solitare_Game.GetDiscardPile();
            Hand         drawPile             = Solitare_Game.GetDrawPile();

            if (facevalueOfClickedCard == FaceValue.Ace)
            {
                EvaluatePlayingAce(clickedCard, source, suitPiles, suitPilePictureBoxes, discardPile, drawPile);
            }
            else if (facevalueOfClickedCard == FaceValue.King)
            {
                EvaluatePlayingKing(clickedCard, source);
            }
            else
            {
                EvaluatePlayingRegularCard(clickedCard, source, discardPile);
            }

            // Add code to do something with the clicked card.
        }
示例#2
0
        /// <summary>
        /// Try to play a King while checking for the special conditions that a King may be of.
        /// </summary>
        /// <param name="clickedCard"></param>
        /// <param name="source"></param>

        private void EvaluatePlayingKing(Card clickedCard, PictureBox source)
        {
            TableLayoutPanel[] tableLayoutPanels   = ReturnTableLayoutPanels();
            Hand[]             tablaus             = Solitare_Game.GetTableaus();
            int  currentlySelectedCardIntegerValue = ReturnIntegerValueOfCard(currentlySelectedCard);
            int  clickedCardIntegerValue           = ReturnIntegerValueOfCard(clickedCard);
            Hand discardPile = Solitare_Game.GetDiscardPile();

            Hand[] suitPiles = Solitare_Game.GetSuitPiles();
            Hand   drawPile  = Solitare_Game.GetDrawPile();

            PictureBox[] suitPilePictureBoxes = ReturnSuitPilePictureBoxes();
            for (int i = 0; i < tableLayoutPanels.Length; i++)
            {
                if (tableLayoutPanels[i].Controls.Count == 0 && !currentlyPlayingCard)
                {
                    tablaus[i].Add(clickedCard);
                    DisplayGuiHand(tablaus[i], tableLayoutPanels[i]);
                    DrawCardForDiscardPile();
                    break;
                }
                else if (source.Name.Contains("suitPile"))
                {
                    for (int ii = 0; ii < suitPiles.Length; i++)
                    {
                        if (((currentlySelectedCardIntegerValue == (clickedCardIntegerValue + 1)) && (currentlySelectedCard.GetSuit() == clickedCard.GetSuit())))
                        {
                            if (suitPiles[ii] != null)
                            {
                                foreach (Card card in suitPiles[i])
                                {
                                    if (card == clickedCard)
                                    {
                                        suitPiles[ii].Add(currentlySelectedCard);
                                        suitPilePictureBoxes[ii].Image = Images.GetCardImage(currentlySelectedCard);
                                        suitPilePictureBoxes[ii].Tag   = currentlySelectedCard;
                                        if (discardPile.Contains(currentlySelectedCard))
                                        {
                                            discardPile.Remove(clickedCard);
                                            drawPile.Remove(clickedCard);
                                            DrawCardForDiscardPile();
                                        }
                                        else
                                        {
                                            SortCardsOnTableau(clickedCard, source);
                                        }
                                        break;
                                    }
                                }
                                SortCardsOnTableau(clickedCard, source);
                                CheckIfWon();
                            }
                        }
                        else
                        {
                            CannotPlay();
                            break;
                        }
                    }
                }
                else if (((currentlySelectedCardIntegerValue == (clickedCardIntegerValue - 1)) && (currentlySelectedCard.GetColour() != clickedCard.GetColour())))
                {
                    if (discardPile.Contains(currentlySelectedCard))
                    {
                        discardPile.Remove(currentlySelectedCard);
                        DrawCardForDiscardPile();
                        SortCardsOnTableau(clickedCard, source);
                    }
                    else
                    {
                        SortCardsOnTableau(clickedCard, source);
                    }
                }
                else
                {
                    CannotPlay();
                }
            }
        }