コード例 #1
0
        private void LoopGame()
        {
            bool correctInput = false;

            while (correctInput == false)
            {
                ConCont.AskToDiscard();
                String discardAnswer = ConCont.EvaluateDiscardAnswer();

                if (discardAnswer == "Y")
                {
                    correctInput = true;
                    DiscardCards();
                    EvaluateHand();
                }
                else if (discardAnswer == "N")
                {
                    correctInput = true;
                    EvaluateHand();
                }
                else
                {
                    correctInput = false;
                    ConCont.PrintWrongInput();
                }
            }
        }
コード例 #2
0
        private void EvaluateHand()
        {
            int prize = Hand.Prize;

            Balance += prize;
            ConCont.PrintWinningHand(prize);
        }
コード例 #3
0
 public void StartGame()
 {
     while (Balance > 0)
     {
         Deck = new Deck();
         DealCards();
         ConCont.PrintBalance(Balance);
         ConCont.PrintDealtCards(Hand.DealtCards);
         LoopGame();
     }
 }
コード例 #4
0
        private void DiscardCards()
        {
            List <int> discardIndices = new List <int>();

            ConCont.AskHowManyCardsToDiscard();
            int numOfDiscards = ConCont.EvaluateDiscardNumberAnswer();

            if (numOfDiscards <= 0 || numOfDiscards > 5)
            {
                while (numOfDiscards == 0)
                {
                    ConCont.PrintWrongInput();
                    ConCont.AskHowManyCardsToDiscard();
                    numOfDiscards = ConCont.EvaluateDiscardNumberAnswer();
                }
            }

            while (numOfDiscards > 0)
            {
                ConCont.AskWhichCardToDiscard();
                int discardIndex = ConCont.EvaluateDiscardNumberAnswer();
                if (discardIndex > 0 && !discardIndices.Contains(discardIndex - 1))
                {
                    discardIndex--;
                    discardIndices.Add(discardIndex);
                    numOfDiscards--;
                }
                else
                {
                    ConCont.PrintWrongInput();
                }
            }
            var sortedIndices = discardIndices.OrderBy(o => o).ToList();

            for (int i = 0; i < sortedIndices.Count; i++)
            {
                sortedIndices[i] -= i;
                Hand.RemoveCard(sortedIndices[i]);
                Hand.AddCard(Deck.Cards[0]);
                Deck.RemoveCard();
            }

            ConCont.PrintDealtCards(Hand.DealtCards);
        }