Example #1
0
        private void _dealButton_Click(object sender, RoutedEventArgs e)
        {
            //Deals the cards out
            _dealButton.IsEnabled = false;
            int  handSize = 8;
            Deck deck     = new Deck();

            _gameDeck = deck;
            deck.ShuffleCards();

            //Deals to the user
            userHand = deck.Deal(handSize);
            Player player = new Player("jack", userHand);

            _player = player;

            //Deals to the computer
            comp1Hand = deck.Deal(handSize);
            AIComputer comp1 = new AIComputer(comp1Hand);

            //Deals to computer 2
            comp2Hand = deck.Deal(handSize);
            AIComputer comp2 = new AIComputer(comp2Hand);

            //Deals to computer 3
            comp3Hand = deck.Deal(handSize);
            AIComputer comp3 = new AIComputer(comp3Hand);

            //Deals the card in the center
            playPile = deck.Deal(1);
            ShowCardImage(_playPile, playPile[playPile.Count - 1]);

            int           value        = 0;
            List <Button> _userButtons = new List <Button>()
            {
                _userCard1, _userCard2, _userCard3, _userCard4, _userCard5, _userCard6, _userCard7,
                _userCard8, _userCard9, _userCard10, _userCard11, _userCard12, _userCard13, _userCard14
            };

            //Displays the cards in users hand
            foreach (Card card in userHand)
            {
                _userCards.Add(card);
                ShowCardButton(_userButtons[value], card);
                value += 1;
            }

            //Makes the cards visible
            for (int x = 0; x < 8; x++)
            {
                _userButtons[x].Visibility = Visibility;
            }
        }
Example #2
0
        private void _cantGoButton_Click(object sender, RoutedEventArgs e)
        {
            _cantGoButton.IsEnabled = false;
            Player      player     = new Player("name", _userCards);
            List <Card> cardsDrawn = _gameDeck.Deal(1);

            //Checks if card draw is equal to the card in the pile
            if (player.CardMatches(cardsDrawn[cardsDrawn.Count - 1], playPile[playPile.Count - 1]) == true)
            {
                playPile.Add(cardsDrawn[cardsDrawn.Count - 1]);
                ShowCardImage(_playPile, playPile[playPile.Count - 1]);
            }
            foreach (Button button in _userButtons)
            {
                button.IsEnabled = false;
            }
            //AI Computers turns
            AIComputer comp1 = new AIComputer(comp1Hand);

            //Adds the AI computers cards into the pile
            playPile.AddRange(comp1.Play(playPile[playPile.Count - 1]));
            //Checks if the computer wins
            _win = comp1.CheckWinOrLoss();
            //Shows the card in the center pile
            ShowCardImage(_playPile, playPile[playPile.Count - 1]);
            AIComputer comp2 = new AIComputer(comp2Hand);

            playPile.AddRange(comp2.Play(playPile[playPile.Count - 1]));
            _win = comp2.CheckWinOrLoss();
            ShowCardImage(_playPile, playPile[playPile.Count - 1]);
            AIComputer comp3 = new AIComputer(comp3Hand);

            playPile.AddRange(comp3.Play(playPile[playPile.Count - 1]));
            _win = comp3.CheckWinOrLoss();
            ShowCardImage(_playPile, playPile[playPile.Count - 1]);

            _cantGoButton.IsEnabled = true;

            //Enables all the user card buttons after the AI's have gone
            foreach (Button button in _userButtons)
            {
                button.IsEnabled = true;
            }
        }