Пример #1
0
        /// <summary>
        /// Checks if the player has won. UNABLE TO CHECK FOR STALEMATE.
        /// </summary>
        private void CheckIfWon()
        {
            Hand[] suitPiles = Solitare_Game.GetSuitPiles();
            bool   hasWon    = false;

            foreach (Hand hand in suitPiles)
            {
                if (hand.GetCount() == 13)
                {
                    hasWon = true;
                }
                else
                {
                    hasWon = false;
                    break;
                }
            }
            if (hasWon)
            {
                MessageBox.Show("Congratulations! You've won the game of Solitare. Reselect the Soliate Game in the Card Games menu to replay.");
                this.Close();
            }
        }
Пример #2
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.
        }
Пример #3
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();
                }
            }
        }
Пример #4
0
 /// <summary>
 /// Try to play a Regular Playing Card (not a King or an Ace)
 /// </summary>
 /// <param name="clickedCard"></param>
 /// <param name="source"></param>
 /// <param name="discardPile"></param>
 private void EvaluatePlayingRegularCard(Card clickedCard, PictureBox source, Hand discardPile)
 {
     if (source.Name.Contains("suitPile"))
     {
         Hand[]       suitPiles            = Solitare_Game.GetSuitPiles();
         Hand         drawPile             = Solitare_Game.GetDrawPile();
         PictureBox[] suitPilePictureBoxes = ReturnSuitPilePictureBoxes();
         for (int i = 0; i < suitPiles.Length; i++)
         {
             int currentlySelectedCardIntegerValue = ReturnIntegerValueOfCard(currentlySelectedCard);
             int clickedCardIntegerValue           = ReturnIntegerValueOfCard(clickedCard);
             if (((currentlySelectedCardIntegerValue == (clickedCardIntegerValue + 1)) && (currentlySelectedCard.GetSuit() == clickedCard.GetSuit())))
             {
                 if (suitPiles[i] != null)
                 {
                     foreach (Card card in suitPiles[i])
                     {
                         if (card == clickedCard)
                         {
                             suitPiles[i].Add(currentlySelectedCard);
                             suitPilePictureBoxes[i].Image = Images.GetCardImage(currentlySelectedCard);
                             suitPilePictureBoxes[i].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 (currentlyPlayingCard && source.Name == "discardPilePictureBox")
     {
         CannotPlay();
     }
     else if (!currentlyPlayingCard)
     {
         currentlyPlayingCard  = true;
         currentlySelectedCard = clickedCard;
     }
     else if (currentlyPlayingCard)
     {
         int currentlySelectedCardIntegerValue = ReturnIntegerValueOfCard(currentlySelectedCard);
         int clickedCardIntegerValue           = ReturnIntegerValueOfCard(clickedCard);
         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();
         }
     }
 }