Пример #1
0
        private void Deal()
        {
            _didBash                 = false;
            _player                  = new Player();
            _computer                = new ComputerPlayer();
            _player.DealedNewCard   += OnPlayerDealedNewCard;
            _computer.DealedNewCard += OnComputerDealedNewCard;
            FieldCards               = new FieldCardsModel();
            List <Card> deck = new List <Card>();

            for (byte i = 7; i < 15; i++)
            {
                byte i1 = i;
                deck.AddRange(from Suit suit in Enum.GetValues(typeof(Suit)) where suit != Suit.None select new Card()
                {
                    Number = i1, Suit = suit
                });
            }
            Random random = new Random();


            if (!_didPlayerDealLast)
            {
                #region Player Is Dealing
                #region First Hand Cards
                for (int i = 0; i < 3; i++)
                {
                    int place = random.Next(0, deck.Count - 1);
                    _computer.AddPlayerCard(deck[place]);
                    deck.RemoveAt(place);
                }
                for (int i = 0; i < 3; i++)
                {
                    int place = random.Next(0, deck.Count - 1);
                    _player.AddPlayerCard(deck[place]);
                    deck.RemoveAt(place);
                }
                #endregion
                #region Faced Down Cards
                for (int i = 0; i < 4; i++)
                {
                    int place = random.Next(0, deck.Count - 1);
                    _computer.AddPlayerDownFieldCard(deck[place]);
                    deck.RemoveAt(place);
                    place = random.Next(0, deck.Count - 1);
                    _player.AddPlayerDownFieldCard(deck[place]);
                    deck.RemoveAt(place);
                }
                #endregion
                #region Second Hand Cards
                for (int i = 0; i < 2; i++)
                {
                    int place = random.Next(0, deck.Count - 1);
                    _computer.AddPlayerCard(deck[place]);
                    deck.RemoveAt(place);
                }
                for (int i = 0; i < 2; i++)
                {
                    int place = random.Next(0, deck.Count - 1);
                    _player.AddPlayerCard(deck[place]);
                    deck.RemoveAt(place);
                }
                #endregion
                #region Faced Up Cards
                for (int i = 0; i < 4; i++)
                {
                    int place = random.Next(0, deck.Count - 1);
                    _computer.AddPlayerUpFieldCard(deck[place]);
                    deck.RemoveAt(place);
                    place = random.Next(0, deck.Count - 1);
                    _player.AddPlayerUpFieldCard(deck[place]);
                    deck.RemoveAt(place);
                }
                #endregion
                #region Third Hand Cards
                for (int i = 0; i < 3; i++)
                {
                    int place = random.Next(0, deck.Count - 1);
                    _computer.AddPlayerCard(deck[place]);
                    deck.RemoveAt(place);
                }
                for (int i = 0; i < 3; i++)
                {
                    int place = random.Next(0, deck.Count - 1);
                    _player.AddPlayerCard(deck[place]);
                    deck.RemoveAt(place);
                }
                #endregion
                #endregion
                _player.SortPlayersHand();
                _didPlayerDealLast = true;
                IsPlayerTurn       = false;
                return;
            }
            #region Computer Is Dealing
            #region First Hand Cards
            for (int i = 0; i < 3; i++)
            {
                int place = random.Next(0, deck.Count - 1);
                _player.AddPlayerCard(deck[place]);
                deck.RemoveAt(place);
            }
            for (int i = 0; i < 3; i++)
            {
                int place = random.Next(0, deck.Count - 1);
                _computer.AddPlayerCard(deck[place]);
                deck.RemoveAt(place);
            }
            #endregion
            #region Faced Down Cards
            for (int i = 0; i < 4; i++)
            {
                int place = random.Next(0, deck.Count - 1);
                _player.AddPlayerDownFieldCard(deck[place]);
                deck.RemoveAt(place);
                place = random.Next(0, deck.Count - 1);
                _computer.AddPlayerDownFieldCard(deck[place]);
                deck.RemoveAt(place);
            }
            #endregion
            #region Second Hand Cards
            for (int i = 0; i < 2; i++)
            {
                int place = random.Next(0, deck.Count - 1);
                _player.AddPlayerCard(deck[place]);
                deck.RemoveAt(place);
            }
            for (int i = 0; i < 2; i++)
            {
                int place = random.Next(0, deck.Count - 1);
                _computer.AddPlayerCard(deck[place]);
                deck.RemoveAt(place);
            }
            #endregion
            #region Faced Up Cards
            for (int i = 0; i < 4; i++)
            {
                int place = random.Next(0, deck.Count - 1);
                _player.AddPlayerUpFieldCard(deck[place]);
                deck.RemoveAt(place);
                place = random.Next(0, deck.Count - 1);
                _computer.AddPlayerUpFieldCard(deck[place]);
                deck.RemoveAt(place);
            }
            #endregion
            #region Third Hand Cards
            for (int i = 0; i < 3; i++)
            {
                int place = random.Next(0, deck.Count - 1);
                _player.AddPlayerCard(deck[place]);
                deck.RemoveAt(place);
            }
            for (int i = 0; i < 3; i++)
            {
                int place = random.Next(0, deck.Count - 1);
                _computer.AddPlayerCard(deck[place]);
                deck.RemoveAt(place);
            }

            #endregion
            _player.SortPlayersHand();
            IsPlayerTurn       = true;
            _didPlayerDealLast = false;

            #endregion
        }