コード例 #1
0
ファイル: Form1.cs プロジェクト: EcGitOrg/Lab2MedForm
        private void _stand_Click(object sender, EventArgs e)
        {
            if (DealerTotalCardValue < 17 && ValidBet)
            {
                DealerTotalCardValue = 0;
                while (Rules.GiveDealerCard(DealerTotalCardValue))
                {
                    dealer.GetCardToDealer();
                    DealerTotalCardValue = StaticMethods.CountValue(dealer.ShowDealerHand());
                }
                Update();

                if (!Rules.NotOver21(DealerTotalCardValue))
                {
                    player.balance += bet;
                    player.balance += bet;
                    Win();
                }
                else if (StaticMethods.CountValue(player.PlayerHand) > StaticMethods.CountValue(dealer.DealerHand))
                {
                    player.balance += bet;
                    player.balance += bet;
                    Win();
                }
                else
                {
                    Loose();
                }
            }
            Update();
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: EcGitOrg/Lab2MedForm
 /// <summary>
 /// Player stands and let dealer get cards
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void _stand_Click(object sender, EventArgs e)
 {
     if (DealerCardValue < 17 && validBet)
     {
         DealerCardValue = 0;
         while (Rules.GiveDealerCard(DealerCardValue))
         {
             dealer.GetCardToDealer();
             DealerCardValue = StaticMethods.CountValue(dealer.ShowDealerHand());
         }
         Update();
         if (!Rules.NotOver21(DealerCardValue))
         {
             Win();
         }
         else if (PlayerWinValue == 21 && DealerWinValue == 21)
         {
             Draw();
         }
         else if (PlayerWinValue > DealerWinValue)
         {
             Win();
         }
         else
         {
             Loose();
         }
     }
     Update();
 }
コード例 #3
0
ファイル: GameFlow.cs プロジェクト: EcGitOrg/Lab2MedForm
        /// <summary>
        /// Progess of the game - From start to end;
        /// </summary>
        public bool RunGame()
        {
            int  DealerValue    = 0;
            int  DealerAceValue = 0;
            int  playerValue    = 0;
            int  PlayerAceValue = 0;
            int  SplitValue     = 0;
            int  SplitAceValue  = 0;
            bool winSplit       = false;
            bool split          = false;
            bool IWantSplit     = false;

            Console.Clear();
            dealer.CheckActiveDeck(deck);
            Printer.LOGG();


            int bet = Printer.AskBet(player); // Get player bet

            dealer.GiveCards(player, dealer); // Clear hands and give start cards
            #region SplittTest
            /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //int y = 1;   ///////////////////////////////////////////// TRY SPLITT /////////////////////////////////////////////////////
            //int x = 1;  ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //string CardType = StaticMethods.GetType(x);  //////////////////////////////////////////////////////////////////////////////
            //player.GetCard(new Card(value: 10, aceValue: 10, color: StaticMethods.ReturnType(y), type: CardType));/////////////////////
            //player.GetCard(new Card(value: 10, aceValue: 10, color: StaticMethods.ReturnType(y), type: CardType));/////////////////////
            /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

            #endregion
            Printer.PrintGame(player.ShowPlayerHand(), dealer.ShowDealerHand(), bet, player.balance, split, player);
            split = Rules.SplittPosible(player.ShowPlayerHand(), player, bet);
            if (split)
            {
                IWantSplit = Printer.AskSplitt(dealer, player);
            }
            if (IWantSplit)
            {
                dealer.SplittPlayerCards(player);
                {
                    //    player.HitMeSplitt(player, dealer, bet, split);
                }
            }
            else
            {
                Printer.HitMePrint(player, dealer, split, bet); // Give all players card
            }
            if (Rules.NotOver21(StaticMethods.CountValue(player.ShowPlayerHand())))
            {
                Printer.PrintGame(player.ShowPlayerHand(), dealer.ShowDealerHand(), bet, player.balance, split, player);

                dealer.DealerGetAllHisCards(player, dealer, bet, split); // Give dealer all his cards

                if (Rules.NotOver21(StaticMethods.CountValue(dealer.ShowDealerHand())) || Rules.NotOver21(StaticMethods.CountAceValue(dealer.ShowDealerHand())))
                {
                    DealerValue    = StaticMethods.CountValue(dealer.ShowDealerHand());
                    DealerAceValue = StaticMethods.CountAceValue(dealer.ShowDealerHand());
                    playerValue    = StaticMethods.CountValue(player.ShowPlayerHand());
                    PlayerAceValue = StaticMethods.CountAceValue(player.ShowPlayerHand());
                    if (IWantSplit)
                    {
                        SplitValue    = StaticMethods.CountValue(player.SplittHand);
                        SplitAceValue = StaticMethods.CountAceValue(player.SplittHand);
                    }

                    int PlayerwinValue = Rules.SetWinValue(PlayerAceValue, playerValue, player);
                    int SplitwinValue  = 0;
                    int DealerwinValue = Rules.SetWinValue(DealerAceValue, DealerValue, dealer);



                    if (SplitAceValue < 22)
                    {
                        SplitwinValue = SplitAceValue;
                    }
                    else if (SplitValue < 22)
                    {
                        SplitwinValue = SplitValue;
                    }
                    else
                    {
                        SplitwinValue = 0;
                    }

                    win = Rules.PlayerWin(PlayerwinValue, DealerwinValue);
                    if (IWantSplit)
                    {
                        winSplit = Rules.PlayerWin(SplitwinValue, DealerwinValue);
                    }
                }
                else
                {
                    win = true;
                    if (IWantSplit)
                    {
                        if (SplitValue < 22)
                        {
                            winSplit = true;
                        }
                    }
                }
            }
            else
            {
                win = false;
            }


            Rules.WinManager(win, winSplit, bet, player, IWantSplit);

            Printer.EndMsg(player.ShowPlayerHand(), dealer.ShowDealerHand(), bet, player.balance, split, player, win, winSplit);


            if (player.balance < 1)
            {
                gameOver = true; Printer.GameOver();
            }
            return(gameOver);
        }