Example #1
0
        public void Deliver(Deck p1, Deck p2)
        {
            int count1 = 6 - p1.cards.Count;
            int count2 = 6 - p2.cards.Count;

            if (count1 > 0)
            {
                for (int i = 0; i < count1; ++i)
                {
                    if (cards.Count > 0)
                    {
                        p1.AddCard(cards[cards.Count - 1]);
                        cards.RemoveAt(cards.Count - 1);
                    }
                }
            }
            if (count2 > 0)
            {
                for (int i = 0; i < count2; ++i)
                {
                    if (cards.Count > 0)
                    {
                        p2.AddCard(cards[cards.Count - 1]);
                        cards.RemoveAt(cards.Count - 1);
                    }
                }
            }
        }
Example #2
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);
        }
Example #3
0
        public void Start()
        {
            for (int i = 0; i < 4; ++i)
            {
                for (int j = 6; j < 15; ++j)
                {
                    kolod.AddCard(j, (Suit)i);
                }
            }

            kolod.shuffle();
            kolod.Deliver(userDeck, computerDeck);
            kozr = kolod.Cards[0].Suit;
            Card start = new Card(14, kozr);

            foreach (Card c in userDeck)
            {
                if (c.Suit == kozr)
                {
                    if (c.Rank < start.Rank)
                    {
                        start = c;
                    }
                }
            }
            foreach (Card c in computerDeck)
            {
                if (c.Suit == kozr)
                {
                    if (c.Rank < start.Rank)
                    {
                        userAttacks = false;
                        break;
                    }
                }
            }
        }