예제 #1
0
        public void HandleUse(Player player, Table table)
        {
            Console.WriteLine("[OK] Player {0} put on table a {1} card",
                              player.Id, CardBeautifuler.GetStringCard(this));

            switch (Value)
            {
            case CardValue.ChangeColor:
                break;

            case CardValue.PassTurn:
                table.TurnToNextPlayer();
                break;

            case CardValue.Revert:
                table.Players.Reverse();
                break;

            case CardValue.Plus2:
            case CardValue.Plus4:
                var nb   = (Value == CardValue.Plus2) ? 2 : 4;
                var next = table.GetNextPlayer();
                for (var i = 0; i != nb; ++i)
                {
                    var card = table.StackCard.PopRandomCard();
                    next.Hand.AddCard(card);
                }
                player.HasUno = false;
                break;
            }
        }
예제 #2
0
        public bool PutCardOnTable(Table table, Card card)
        {
            try
            {
                var player = table.Players.Find(x => x.Hand == this);

                if (!CardIsValidToBePut(card, table.GetTopStackCard()))
                {
                    Console.Error.WriteLine("Invalid à la pose");
                    return(false);
                }
                var cardInHand = Cards.Find(x =>
                                            x.Value.Equals(card.Value) && x.Color.Equals(card.Color));
                cardInHand.HandleUse(player, table);
                if (cardInHand.Color == CardColor.Undefined)
                {
                    cardInHand.JokerColor = card.JokerColor;
                }
                Cards.Remove(cardInHand);
                table.AddCard(cardInHand);
                if (Cards.Count == 0)
                {
                    table.SetGameEnd(player);
                }
                else
                {
                    table.TurnToNextPlayer();
                    table.NotifyTurnToAllPlayers();
                }
            }
            catch (Exception)
            {
                if (Cards.Count == 0)
                {
                    table.SetGameEnd(null);
                }
            }
            return(true);
        }