Ejemplo n.º 1
0
        public async Task PlayTurn(PlayerTurn previousTurn, CardDeck drawPile)
        {
            Console.WriteLine($"Current Color is: {previousTurn.DeclaredColor}\nCurrent value is {previousTurn.Card.Value}");

userPicksCard:
            if ((previousTurn.Result == TurnResult.Skip ||
                 previousTurn.Result == TurnResult.DrawTwo ||
                 previousTurn.Result == TurnResult.WildDrawFour))
            {
                await ProcessAttack(previousTurn.Card, drawPile);
            }
            else if ((previousTurn.Result == TurnResult.WildCard ||
                      previousTurn.Result == TurnResult.Attacked ||
                      previousTurn.Result == TurnResult.ForceDraw) &&
                     previousTurn.Card.Color == CardColor.Wild &&
                     HasMatch(previousTurn.DeclaredColor))
            {
                await selectCard();

                if (Hand.Find(x => x.Color == Golab.currentCard.Color && x.Value == Golab.currentCard.Value) != null)
                {
                    var cardPlayed = Hand.Find(x => x.Color == Golab.currentCard.Color && x.Value == Golab.currentCard.Value);
                    if (cardPlayed.Value == CardValue.Wild || cardPlayed.Color == CardColor.Wild)
                    {
                        if (!HasMatch(previousTurn.Card))
                        {
                            await playCard(cardPlayed);
                        }
                        else
                        {
                            await discordPlayer.SendMessageAsync("You have to play a matching card if you have it!");

                            goto userPicksCard;
                        }
                    }
                    else if (cardPlayed.Color != previousTurn.DeclaredColor && cardPlayed.Value != previousTurn.Card.Value)
                    {
                        await discordPlayer.SendMessageAsync("Your card needs to either be the same color or same face value of the last card played!");

                        goto userPicksCard;
                    }
                    else
                    {
                        await playCard(cardPlayed);
                    }
                }
                else
                {
                    await discordPlayer.SendMessageAsync("You don't currently have that card!");

                    goto userPicksCard;
                }
            }
            else if (HasMatch(previousTurn.Card))
            {
                await selectCard();

                if (Hand.Find(x => x.Color == Golab.currentCard.Color && x.Value == Golab.currentCard.Value) != null)
                {
                    var cardPlayed = Hand.Find(x => x.Color == Golab.currentCard.Color && x.Value == Golab.currentCard.Value);
                    if (cardPlayed.Value == CardValue.Wild || cardPlayed.Color == CardColor.Wild)
                    {
                        if (!HasMatch(previousTurn.Card))
                        {
                            await playCard(cardPlayed);
                        }
                        else
                        {
                            await discordPlayer.SendMessageAsync("You have to play a matching card if you have it!");

                            goto userPicksCard;
                        }
                    }
                    else if (cardPlayed.Color != previousTurn.DeclaredColor && cardPlayed.Value != previousTurn.Card.Value)
                    {
                        await discordPlayer.SendMessageAsync("Your card needs to either be the same color or same face value of the last card played!");

                        goto userPicksCard;
                    }
                    else
                    {
                        await playCard(cardPlayed);
                    }
                }
                else
                {
                    await discordPlayer.SendMessageAsync("You don't currently have that card!");

                    goto userPicksCard;
                }
            }
            //When the player has no matching cards
            else //Draw a card and see if it can play
            {
                Golab.turn = DrawCard(previousTurn, drawPile);
            }

            await DisplayTurn(Golab.turn);
        }