Exemple #1
0
        public bool userThrows(String s, int rank)
        {
            Suit suit = (Suit)Enum.Parse(typeof(Suit), s, true);
            Card c    = new Card(rank, suit);

            if (!userDeck.Cards.Contains(c))
            {
                return(false);
            }
            if (userAttacks)
            {
                if (currentDeck.Cards.Count == 0)
                {
                    currentDeck.AddCard(c);
                    userDeck.Remove(c);
                    info = "OK";
                }
                else
                {
                    if (currentDeck.Cards.Count % 2 == 0)
                    {
                        if (currentDeck.HasRank(c.Rank))
                        {
                            currentDeck.AddCard(c);
                            userDeck.Remove(c);
                        }
                        else
                        {
                            info = "Throw a valid card"; return(false);
                        }
                    }
                    else
                    {
                        info = "Wait until computer make move"; return(false);
                    }
                }
            }
            else
            {
                Card thrown = currentDeck.Cards[currentDeck.Cards.Count - 1];
                if (Covers(c, thrown))
                {
                    currentDeck.AddCard(c);
                    userDeck.Remove(c);
                }
                else
                {
                    info = "That card doesn't cover the thrown one"; return(false);
                }
            }

            if (kolod.Cards.Count == 0 && userDeck.Cards.Count == 0)
            {
                GameOver();
                info = "Game is over. You have won";
                return(false);
            }
            return(true);
        }