public Card PickUpCard(IRummyPlayer sender, CardPiles pile) { if (sender.PlayerIndex != _currentPlayerIndex) { throw new Exception("The Player Indexes don't align"); } Card returnitem = null; if (pile == CardPiles.Discard) { _playersHands[sender.PlayerIndex].Hand.Add(_table.DiscardPile[_table.DiscardPile.Count - 1]); returnitem = _table.DiscardPile[_table.DiscardPile.Count - 1]; _table.DiscardPile.RemoveAt(_table.DiscardPile.Count - 1); _currentTurnCardPickedUp = returnitem; } else if (pile == CardPiles.Stock) { _playersHands[sender.PlayerIndex].Hand.Add(_currentGameDeck.DrawDeck[_currentGameDeck.DrawDeck.Count - 1]); returnitem = _currentGameDeck.DrawDeck[_currentGameDeck.DrawDeck.Count - 1]; _currentGameDeck.DrawDeck.RemoveAt(_currentGameDeck.DrawDeck.Count - 1); _currentTurnCardPickedUp = null; } if (returnitem == null) { throw new Exception("Picking up a card failed"); } return(returnitem); }
public void TurnLayoff(IRummyPlayer sender, int meldID, Card cardToAdd) { if (sender.PlayerIndex != _currentPlayerIndex) { throw new Exception("The Player Indexes don't align"); } bool invalidCard = false; foreach (Card card in _table.SetMelds[meldID]) { if (card.Pips != cardToAdd.Pips) { invalidCard = true; break; } } foreach (Card card in _table.RunMelds[meldID]) { if (card.Suit != cardToAdd.Suit) { invalidCard = true; break; } } var numbers = new List <int>(); foreach (Card card in _table.RunMelds[meldID]) { numbers.Add((int)card.Pips); } numbers.Sort(); if ((numbers[0] - 1) == (int)cardToAdd.Pips) { invalidCard = false; } else if ((numbers[numbers.Count - 1] + 1) == (int)cardToAdd.Pips) { invalidCard = false; } if (invalidCard) { throw new Exception("The card is not aloud in any set in the table"); } //Remove the caard from the hand _playersHands[_currentPlayerIndex].Hand.Remove(cardToAdd); _currentTurnLayoffs.Add(cardToAdd); }
private void Bots_DoneTurn(IRummyPlayer sender, Card CardBeingDiscarded, bool OutOfCards = false) { _mainGame.TellTheOtherBotsWhatHappened(CardBeingDiscarded); if (OutOfCards == true) { Debug.Print("Game is now over"); _mainGame.GameOverHappened(); } else { _mainGame.Discarded(CardBeingDiscarded); Debug.Print("Turn Ended"); } }
public void RunMelds(IRummyPlayer sender, List <Card> cardsInMeld) { if (sender.PlayerIndex != _currentPlayerIndex) { throw new Exception("The Player Indexes don't align"); } Suit suit = Suit.None; var runMeld = new List <int>(); //check to see if the cards are in the senders hand foreach (var item in cardsInMeld) { if (_playersHands[_currentPlayerIndex].Hand.Contains(item) == false) { throw new Exception("The card wasn't in the players hand"); } else { _playersHands[_currentPlayerIndex].Hand.Remove(item); } if (suit == Suit.None) { suit = item.Suit; } else if (suit != item.Suit) { throw new Exception("The RUN MELD must have the same suit"); } runMeld.Add((int)item.Pips); } runMeld.Sort(); for (int i = runMeld[0]; i < runMeld.Count; i++) { if (i != runMeld[i]) { throw new Exception("The RUN MELD wasn't consective"); } } //Add it to the table _table.RunMelds.Add(_table.SetMelds.Count, cardsInMeld); }
public void SetMelds(IRummyPlayer sender, List <Card> cardsInMeld) { if (sender.PlayerIndex != _currentPlayerIndex) { throw new Exception("The Player Indexes don't align"); } Pips number = Pips.Joker; //check to see if the cards are in the senders hand foreach (var item in cardsInMeld) { if (_playersHands[_currentPlayerIndex].Hand.Contains(item) == false) { throw new Exception("The card wasn't in the players hand"); } else { _playersHands[_currentPlayerIndex].Hand.Remove(item); } //Check to see if the SET MELDS are valid if (number == Pips.Joker) { number = item.Pips; } else if (item.Pips != number) { throw new Exception("Wasn't a valid SET MELD"); } } //Add it to the table _table.SetMelds.Add(_table.SetMelds.Count, cardsInMeld); _currentTurnMeldID.Add(_table.SetMelds.Count); }
private void Bots_ChoosePile(IRummyPlayer sender, CardPiles Pile, out Card DrawCard) { DrawCard = _mainGame.PickUpCard(sender, Pile); }
private void Bots_RunMelds(IRummyPlayer sender, List <Card> CardsInMeld) { _mainGame.RunMelds(sender, CardsInMeld); }
private void Bots_TurnLayoff(IRummyPlayer sender, int MeldID, Card CardToAdd) { _mainGame.TurnLayoff(sender, MeldID, CardToAdd); }