Exemple #1
0
        public void DrawCards(int amount)
        {
            if (amount <= 0)
            {
                return;
            }

            if (amount > Deck.Cards.Count)
            {
                IsDead = true;
            }

            var drawnCards = new List <Card>();

            for (int i = 0; i < amount; i++)
            {
                if (Deck.Cards.Count > 0)
                {
                    var card = Deck.DrawCard();
                    drawnCards.Add(card);
                    Hand.Add(card);
                }
            }

            OnCardsDrawn?.Invoke(this, new PlayerCardDraw()
            {
                Amount = drawnCards.Count,
                Cards  = new List <Card>(drawnCards),
                Player = this
            });
        }
Exemple #2
0
        public void DrawCardsFromDeck(List <Card> selectedCards)
        {
            Deck.Cards = new Stack <Card>(Deck.Cards.Except(selectedCards));
            Hand.AddRange(selectedCards);
            Deck.Shuffle();

            OnCardsDrawn?.Invoke(this, new PlayerCardDraw()
            {
                Amount = selectedCards.Count(),
                Cards  = new List <Card>(selectedCards),
                Player = this
            });
        }
Exemple #3
0
    private static bool DrawCards()
    {
        var good = true;

        for (var i = 0; i < 5; i++)
        {
            if (Holds[i] != CorrectHolds[i])
            {
                good = false;
            }
        }
        if (!good)
        {
            statistics.MistakesMade++;
            if (BlockIncorrectHolds)
            {
                return(false);
            }
        }

        var timeTaken = (DateTime.Now - handDealtAt).TotalSeconds;

        statistics.AvgHandLength = (statistics.AvgHandLength * (statistics.HandsPlayed - 1) + timeTaken) / statistics.HandsPlayed;


        var heldCards = new List <Hands.Entities.Card>();

        for (var i = 0; i < Holds.Length; i++)
        {
            if (Holds[i])
            {
                heldCards.Add(Hand[i]);
            }
        }

        var results = new Hands.HandResult[HandsPlayed];

        for (var i = 0; i < HandsPlayed; i++)
        {
            results[i] = _controller.ResolveHand(heldCards.ToArray(), Bet, PayTable);
        }

        //re-order the cards so the hold cards are in the right spot
        foreach (var result in results)
        {
            var reorderedHand = new List <Hands.Entities.Card>();
            var i             = 0;
            for (var j = 0; j < 5; j++)
            {
                if (heldCards.Contains(Hand[j]))
                {
                    reorderedHand.Add(Hand[j]);
                }
                else
                {
                    if (Hand[j] != result.Hand[i])
                    {
                        reorderedHand.Add(result.Hand[i]);
                    }
                    i++;
                }
            }
            result.Hand = reorderedHand.ToArray();
        }

        MainHandResult = results[0];
        Hand           = results[0].Hand;
        HandResults    = results;

        //tabulate winnings
        AmountWon = results.Sum(r => r.Payout);
        Credits  += AmountWon;

        GameState = 1;

        OnCardsDrawn?.Invoke(new DrawEventArgs
        {
            Hand           = Hand,
            MainHandResult = MainHandResult,
            CorrectHolds   = CorrectHolds,
            AmountWon      = AmountWon,
            HandResults    = HandResults
        });

        return(true);
    }