Exemple #1
0
 /// <summary>
 /// Display all cards in Tableau.
 /// </summary>
 private void PopulateTableau()
 {
     TableLayoutPanel[] tableauLayoutPanels = ReturnTableLayoutPanels();
     Hand[]             tableaus            = Solitare_Game.GetTableaus();
     for (int i = 0; i < tableauLayoutPanels.Length; i++)
     {
         DisplayGuiHand(tableaus[i], tableauLayoutPanels[i]);
     }
 }
Exemple #2
0
 /// <summary>
 /// Removes a card from the Tableau
 /// </summary>
 /// <param name="clickedCard"></param>
 private void RemoveCardsFromTableau(Card clickedCard)
 {
     TableLayoutPanel[] tableLayoutPanels = ReturnTableLayoutPanels();
     Hand[]             tableaus          = Solitare_Game.GetTableaus();
     for (int i = 0; i < tableLayoutPanels.Length; i++)
     {
         foreach (Card card in tableaus[i])
         {
             if (card == clickedCard)
             {
                 tableaus[i].Remove(clickedCard);
                 DisplayGuiHand(tableaus[i], tableLayoutPanels[i]);
                 break;
             }
         }
     }
 }
Exemple #3
0
        /// <summary>
        /// Move vards on the Tableau in respect to the current move the player is making or has made.
        /// </summary>
        /// <param name="clickedCard"></param>
        /// <param name="source"></param>

        private void SortCardsOnTableau(Card clickedCard, PictureBox source)
        {
            TableLayoutPanel[] tableLayoutPanels = ReturnTableLayoutPanels();
            Hand[]             tableaus          = Solitare_Game.GetTableaus();
            int indexOne = -1;
            int indexTwo = -1;

            for (int i = 0; i < tableaus.Length; i++)
            {
                foreach (Card card in tableaus[i])
                {
                    if (currentlySelectedCard == card)
                    {
                        indexOne = i;
                        DisplayGuiHand(tableaus[i], tableLayoutPanels[i]);
                        currentlyPlayingCard = false;
                    }
                    else if (clickedCard == card)
                    {
                        indexTwo = i;
                        DisplayGuiHand(tableaus[i], tableLayoutPanels[i]);
                        currentlyPlayingCard = false;
                    }
                }
            }
            if (indexTwo != -1 && !(source.Name.Contains("suitPile")))
            {
                tableaus[indexTwo].Add(currentlySelectedCard);
                DisplayGuiHand(tableaus[indexTwo], tableLayoutPanels[indexTwo]);
            }
            else if (indexOne != -1)
            {
                tableaus[indexOne].Remove(currentlySelectedCard);
                DisplayGuiHand(tableaus[indexOne], tableLayoutPanels[indexOne]);
            }
        }
Exemple #4
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();
                }
            }
        }