Exemple #1
0
        /// <summary>
        /// Plays a round of snap
        /// </summary>
        /// <returns></returns>
        public bool PlayRound()
        {
            if (CheckIfNoCardsLeft())
            {
                return(true);
            }

            // The player places a card onto the central pile
            var poppedCard = Players[PlayerTurn].Cards.Pop();

            Console.WriteLine(Players[PlayerTurn].Name + " adds " + poppedCard.Rank + " of " + poppedCard.Suit + " to central pile.");

            CentralPile.Push(poppedCard);

            if (LastCard != null)
            {
                if (CheckForSnap(poppedCard))
                {
                    return(true);
                }
            }

            LastCard = poppedCard;

            SetPlayerTurn();

            return(true);
        }
Exemple #2
0
        public void Simulate()
        {
            while (true)
            {
                foreach (var currentPlayer in Players)
                {
                    if (currentPlayer.HasCards())
                    {
                        var currentCard = currentPlayer.Cards.TakeFromTop();
                        CentralPile.AddToTop(currentCard);
                        Console.WriteLine($"Player {currentPlayer.Id} added card {currentCard} to the pile.");

                        if (_snapDecider.IsSnap(CentralPile))
                        {
                            var winner = _winnerDecider.GetSnapWinner(currentPlayer, PlayersById);
                            Snap(winner);

                            if (winner.Cards.Count() == _numberOfCardsUsedInGame)
                            {
                                Console.WriteLine($"Player {winner.Id} Won!");
                                return;
                            }
                        }
                    }
                }

                if (Players.All(p => !p.HasCards()))
                {
                    Console.WriteLine("No more Cards Available");
                    return;
                }
            }
        }
Exemple #3
0
        private void Snap(Player winnerPlayer)
        {
            Console.WriteLine($"Player {winnerPlayer.Id} Snaps the cards!");

            while (CentralPile.Any())
            {
                winnerPlayer.Cards.AddToBottom(CentralPile.TakeFromTop());
            }
        }