public void Result()
        {
            var discardPile = new Discard();

            discardPile.Add(new Card(Suit.Clubs, Value.Eight));
            discardPile.Add(new Card(Suit.Diamonds, Value.Seven));
            discardPile.Add(new Card(Suit.Diamonds, Value.Ace));

            discardPile.Accept(_discardPileVisitor);

            Assert.AreEqual(3, _discardPileVisitor.Result().Count);
            Assert.AreEqual(Value.Ace, _discardPileVisitor.Result().Peek().Value);
            Assert.AreEqual(Suit.Diamonds, _discardPileVisitor.Result().Peek().Suit);
        }
示例#2
0
        //discard a card, change state
        public void DiscardCard(Player player, Card c)
        {
            //check state
            if (!CanDiscard(player))
            {
                _currentError = ErrorMessage.NotPlayerTurn;
                throw new ArgumentException("It is not this player's turn", "player");
            }
            //check if player has the card
            PlayerHasCard(player, c);

            //check if the card was just drawn
            if (c.Equals(_cardJustDrawn))
            {
                _currentError = ErrorMessage.CannotDiscard;
                throw new ArgumentException("Cannot discard a card that was just drawn", "player");
            }
            RemovePlayerCard(player, c);
            Discard.Add(c);

            State newState = (player == Player.One) ? State.Player2Draw : State.Player1Draw;

            AfterActStuff(new DiscardMove(player, c), newState);

            _currentError = ErrorMessage.NoError;
        }
示例#3
0
        public void Discard_ShouldBeInitialised()
        {
            var dealer = new Dealer();

            _discard = new Discard();
            _discard.Add(dealer.DealCard());
        }
示例#4
0
    public Card PlayFromHand(Card cardToPlay, CardGame gameToPlayIn, Discard receivingDiscard)
    {
        cardsInHand.Remove(cardToPlay);
        receivingDiscard.Add(cardToPlay);
        gameToPlayIn.Play(cardToPlay);

        return(cardToPlay);
    }
示例#5
0
    public Card Discard(Card cardToDiscard, Discard receivingDiscard)
    {
        cardsInHand.Remove(cardToDiscard);

        receivingDiscard.Add(cardToDiscard);


        return(cardToDiscard);
    }
示例#6
0
        public void DiscardHand()
        {
            foreach (Card c in PlayerHand.Cards)
            {
                PlayerHand.Cards.Remove(c);
                Discard.Add(c);
                PlayerHand.Actions   = new List <Action>();
                PlayerHand.Resources = new Dictionary <Res, int>();

                Draw();
            }
        }
示例#7
0
 public void DiscardCard() //...............Discard Action cards......................
 {
     int count = 1;
     Console.WriteLine("Choose a card to Discard");
     
     foreach (Action card in ActionHand)
     {
         Console.Write("{0}). {1}, ", count, card.Name.ToString());
         count += 1;
     }
     Int32.TryParse(Console.ReadLine(), out int query2);
     //Instead of backing out, which is difficult, it assumes the first card will be dropped
     if (query2 < 1 || query2 > ActionHand.Count) query2 = 1;
     Discard.Add(ActionHand[query2-1]);
     ActionHand.RemoveAt(query2 - 1);
 }
示例#8
0
        //draw a card from stock or discard
        //player
        //pile
        public void DrawCard(Player player, PileName pn)
        {
            if (!CanDraw(player))
            {
                _currentError = ErrorMessage.NotPlayerTurn;
                throw new ArgumentException("It is not this player's turn", "player");
            }

            if (IsPileEmpty(pn))
            {
                throw new ArgumentException("The pile is empty", "pn");
            }

            Card c = PopFromPile(pn);

            AddToPlayerCards(player, c);
            //if drawn from discard pile, remeber the card
            if (pn == PileName.Discard)
            {
                _cardJustDrawn = c;
            }
            else
            {
                _cardJustDrawn = null;
            }

            if (pn == PileName.Stock && IsPileEmpty(PileName.Stock))
            {
                var topOnDiscard = Discard.Pop();
                while (Discard.Count > 0)
                {
                    Stock.Add(Discard.Pop());
                    Stock.Shuffle(null);
                }

                Discard.Add(topOnDiscard);
            }


            _currentError = ErrorMessage.NoError;

            var newState = (player == Player.One) ?State.Player1MeldLayDiscard : State.Player2MeldLayDiscard;

            AfterActStuff(new DrawMove(player, pn), newState);
        }
示例#9
0
    /// <summary>
    /// Discard Function --> Take a specified card, add it to the discard pile and remove it from target collection.
    /// </summary>
    /// <param name="_Target"> The collection of cards to target </param>
    /// <param name="_index"> The index of the card to discard </param>
    void DiscardCardsFrom(List <Cards> _Target, int _index)
    {
        if (_Target == null)
        {
            Debug.Log("ERROR");
        }
        else if (_Target == Discard)
        {
            Debug.Log("You can't discard a card that's already in this pile");
        }
        else
        {
            Discard.Add(_Target.ElementAt(_index));

            Status.NumCardsDiscarded++;

            _Target.RemoveRange(_index, 1);
        }
        Debug.Log(Status.NumCardsDiscarded);
    }
示例#10
0
 public void Discard(Card card)
 {
     _discard.Add(card);
 }
示例#11
0
        public void Simulate()
        {
            //TODO: Add Plus2 Accumulation -- probably will be hacky
            Card currentCard;

            currentCard = Deck.Pop();
            try
            {
                int turnPlayer = 0;
                int direction  = 1;

                void AdvancePlayer(int modifier = 1)
                {
                    turnPlayer += direction * modifier;

                    // I don´t wanna do bounds checking every time i modify player! just do it here
                    turnPlayer = turnPlayer % Players;
                    if (turnPlayer < 0)
                    {
                        turnPlayer = 0;
                    }
                }

                Card?GetFittingCard()
                {
                    Card?specialOption = null;

                    foreach (var card in Hands[turnPlayer])
                    {
                        if (card.Color == Color.Nigro)
                        {
                            specialOption = card;
                            continue;
                        }

                        if (card.CanBePlaceOn(currentCard))
                        {
                            return(Hands[turnPlayer].Pop(card));
                        }
                    }

                    return(specialOption == null ? null : (Card?)Hands[turnPlayer].Pop(specialOption));
                }

                bool LayFittingCard()
                {
                    Card?possibleCard;

                    if ((possibleCard = GetFittingCard()) != null)
                    {
                        Card card = possibleCard.Value;
                        switch (card.Suit)
                        {
                        case Suit.Skip:
                            AdvancePlayer(2);
                            break;

                        case Suit.Reverse:
                            direction *= -1;
                            AdvancePlayer();
                            break;

                        case Suit.Plus2:

                            int cards = 2;

                            AdvancePlayer();

                            while (true)
                            {
                                // Ceck if the player has a plus2 card and lay it onto the discard pile
                                if (Hands[turnPlayer].Exists(c => c.Suit == Suit.Plus2))
                                {
                                    Discard.Add(Hands[turnPlayer].Pop(Hands[turnPlayer].Where(c => c.Suit == Suit.Plus2).First()));
                                }
                                else     // the player cant block; take cards
                                {
                                    for (int i = 0; i < cards; i++)
                                    {
                                        Hands[turnPlayer].Add(Deck.Pop());
                                    }
                                    AdvancePlayer();
                                    break;
                                }

                                AdvancePlayer();
                            }
                            break;

                        case Suit.Plus4:
                            AdvancePlayer();

                            Hands[turnPlayer].Add(Deck.Pop());
                            Hands[turnPlayer].Add(Deck.Pop());
                            Hands[turnPlayer].Add(Deck.Pop());
                            Hands[turnPlayer].Add(Deck.Pop());

                            AdvancePlayer();
                            break;

                        case Suit.Pick:
                            // Find out which color is the most in the players hand and set the picking card to that
                            currentCard.Color = Hands[turnPlayer].Where(c => c.Color != Color.Nigro).GroupBy(c => c.Color).Aggregate((g1, g2) => g1.Count() > g2.Count() ? g1 : g2).First().Color;
                            break;

                        default:
                            AdvancePlayer();
                            break;
                        }

                        Discard.Add(currentCard);
                        currentCard = card;

                        return(true);
                    }

                    return(false);
                }


                while (Deck.Count > 0)
                {
                    if (Hands[turnPlayer].Count == 0)
                    {
                        turnPlayer = (turnPlayer + 1) % Players; //wrap around so we don't get issues when the last player has no cards left.

                        //Check if all players are out of cards
                        bool allEmpty = true;
                        foreach (List <Card> hand in Hands)
                        {
                            if (hand.Count != 0)
                            {
                                allEmpty = false;
                                break;
                            }
                        }
                        if (allEmpty)
                        {
                            break;
                        }
                        continue;
                    }



                    if (LayFittingCard())
                    {
                        continue;
                    }

                    Hands[turnPlayer].Add(Deck.Pop());

                    if (!LayFittingCard())
                    {
                        AdvancePlayer();
                    }

                    if (Hands.Sum(h => h.Count) == 0)
                    {
                        break;
                    }
                }
            }
            catch (InvalidOperationException) { }
            Discard.Add(currentCard);
        }
示例#12
0
 public void DiscardCard(Action card) //base method to discard card....................
 {
     Discard.Add(card);
     ActionHand.Remove(card);
     Shuffle(1);
 }