private void player_OnCardDiscarded(object sender, CardEventArgs e) { // Update the discard pile by making the specified card the available card. CurrentAvailableCard = e.Card; // Determine the index of the next player. If the current player is the last player, // then the first player is the next player. var nextIndex = CurrentPlayer.Index + 1 >= _gameOptions.NumberOfPlayers ? 0 : CurrentPlayer.Index + 1; // If the game deck is empty, the discarded cards need to be reshuffled. if (GameDeck.CardsInDeck == 0) { // Get a list of all the cards that are in play. This includes all the cards in // players' hands, and the top card on the discard pile. var cardsInPlay = new List <Card>(); foreach (var player in Players) { cardsInPlay.AddRange(player.GetCards()); } cardsInPlay.Add(CurrentAvailableCard); // Reshuffle all the cards *except* for the list of cards that are in play. GameDeck.ReshuffleDiscarded(cardsInPlay); } // Finally, set the next player. AssignCurrentPlayer(nextIndex); }
void player_OnCardDiscarded(object sender, CardEventArgs e) { CurrentAvailableCard = e.Card; var nextIndex = CurrentPlayer.Index + 1 >= _gameOptions.NumberOfPlayers ? 0 : CurrentPlayer.Index + 1; if (GameDeck.CardsInDeck == 0) { var cardsInPlay = new List <Card>(); foreach (var player in Players) { cardsInPlay.AddRange(player.GetCards()); } cardsInPlay.Add(CurrentAvailableCard); GameDeck.ReshuffleDiscarded(cardsInPlay); } AssignCurrentPlayer(nextIndex); }