/* @brief Moves a card from the foundation to a tableau * @param SrcFoundationIdx - Index of source foundation to move a card from. * @param DestTableauIdx - Index to destination tableau. * @return Boolean indicating if the move was valid or invalid. */ public bool MoveFromFoundation(int SrcFoundationIdx, int DestTableauIdx) { bool validMove = false; Tableau DestTableau = tableaus[DestTableauIdx]; /* Check if we can even move from the source */ if (foundations[SrcFoundationIdx].Count > 0) { Card srcCard = foundations[SrcFoundationIdx][0]; /* Check if destination tableau is empty, only a king can go in there */ if (DestTableau.Cards.Count == 0 && srcCard.Value == 13) { DestTableau.InsertCard(srcCard); validMove = true; } /* Check if different suit color and the value is 1 lower. */ else { Card destCard = DestTableau.Cards[DestTableau.Cards.Count - 1]; if (CheckSuit(srcCard, destCard, true) && CheckCardValue(srcCard, destCard, true)) { DestTableau.InsertCard(srcCard); validMove = true; } } } if (validMove) { points -= 15; foundations[SrcFoundationIdx].RemoveAt(0); } return(validMove); }
/* @brief Performs the move of one or more cards from one tableau to another. * @param SrcTableau - Tableau where the cards are moving from. * @param Depth - How many cards are being moved. * @param DestTableau - Tableau where the cards are moving to. * */ private void MoveBetweenTableaus(Tableau SrcTableau, int Depth, Tableau DestTableau) { List <Card> cardsToMove = new List <Card>(); cardsToMove = SrcTableau.GetCards(Depth); foreach (Card card in cardsToMove) { DestTableau.InsertCard(card); } if (SrcTableau.RemoveCards(Depth)) { points += 5; } }
/* @brief Moves a card from the waste pile to a tableau * @param DestTableauIdx - Index to destination tableau. * @return Boolean indicating if the move was valid or invalid. */ public bool MoveFromWaste(int DestTableauIdx) { bool validMove = false; Tableau DestTableau = tableaus[DestTableauIdx]; Card srcCard = waste[0]; /* Check if we can even move from the source */ if (waste.Count > 0 && wasteVisible > 0) { if (DestTableau.Cards.Count == 0 && srcCard.Value == 13) { validMove = true; } /* Check if different suit color and the value is 1 lower. */ else { Card destCard = DestTableau.Cards[DestTableau.Cards.Count - 1]; if (CheckSuit(srcCard, destCard, true) && CheckCardValue(srcCard, destCard, true)) { validMove = true; } } } if (validMove) { points += 5; DestTableau.InsertCard(waste[0]); waste.RemoveAt(0); if (wasteVisible > 0) { wasteVisible--; } } return(validMove); }