public void RemoveCards(PlayedCards playedCards) { foreach (var BTCard in playedCards) { Hand.RemoveCard(BTCard); } }
public void Validate(PlayedCards activeCards) { if (activeCards == null || activeCards[0] == null || this[0] == null) { return; } if (activeCards.Count != this.Count) { throw new InvalidHandException(this, "You must play the same number of cards."); } if (this.Count == 1) { // Validate single BTCard hand var nextCard = this[0]; var activeCard = activeCards[0]; if (nextCard.GameValue < activeCard.GameValue) { throw new InvalidHandException(this, "Cannot play a BTCard of lesser value."); } if (nextCard.GameValue == activeCard.GameValue && nextCard.Suit < activeCard.Suit) { throw new InvalidHandException(this, "Cannot play an equal value BTCard of a lesser suit."); } } // todo: validate poker style hands }
public PlayedCards PlayTurn(PlayedCards currentMove) { var cardsToPlay = new PlayedCards(this); // display the cards to the player DisplayCardList(); bool valid = false; do { var stillBuildingHand = true; do { int selectedCardIndex = GetUserSelectedCardIndex(); if (selectedCardIndex >= 0) { BTCard selectedCard = Hand[selectedCardIndex]; cardsToPlay.AddCard(selectedCard); valid = true; } if (!ContinueBuildingHandPrompt()) { stillBuildingHand = false; } } while (stillBuildingHand); try { // validate the move cardsToPlay.Validate(currentMove); } catch (Exception ex) { cardsToPlay.Clear(); Console.WriteLine("Invalid move: " + ex.Message); valid = false; } } while (valid == false); // play the cards); return(cardsToPlay); }
public InvalidHandException(PlayedCards cards, string message) : base(message) { Cards = cards; }