Esempio n. 1
0
        private async System.Threading.Tasks.Task AfterTapAsync(object sender, int index)
        {
            PlayingCards cardUsed = (PlayingCards)sender;

            //1. Display card on the table
            PlayerCard.DisplayCard($"{game.PlayerCards[index]}C");

            //2. hide selected card

            cardUsed.DisplayCard("BC");
            cardUsed.IsEnabled       = false;
            Shuffle_Button.IsEnabled = false;

            //3. show the computer selection
            game.SetPlayerCard(game.PlayerCards[index]);
            CompCard.DisplayCard($"{game.ComputerSelection}C");

            UpdateScores();

            _cardTapCounter++;

            if (_cardTapCounter == 3)
            {
                if (game.ComputerScore > game.PlayerScore)
                {
                    game.ComputerScore = 0;
                    game.PlayerScore   = 0;
                    winner             = "COMPUTER";
                }
                else if (game.ComputerScore < game.PlayerScore)
                {
                    game.ComputerScore = 0;
                    game.PlayerScore   = 0;
                    winner             = "PLAYER";
                }

                Winner.Text = $"{winner} IS THE WINNER";



                Shuffle_Button.IsEnabled = true;

                _cardTapCounter = 0;
            }
        }
Esempio n. 2
0
        private async System.Threading.Tasks.Task AfterTap(object sender, int index)
        {
            BackCard.IsEnabled = false;
            Moves.Text         = "";
            Moves.Foreground   = new SolidColorBrush(Colors.White);

            if (index == 9)//9 = Draw from Deck
            {
                game.Draw();
                UpCard.DisplayCard(game.upFacedCard.CardName);
                if (game.upFacedCard.CardNumber == "1")
                {
                    Moves.Text = "YOU DREW AN ACE! COMPUTER TURN SKIPPED, GO AGAIN.";
                    whosTurn   = WhosTurn.Player;
                }
                else if (game.upFacedCard.CardNumber == "8")
                {
                    Moves.Text = "YOU DREW A WILDCARD! CHOOSE A NEW CARD WITH A DESIRED SUIT!";

                    whosTurn = WhosTurn.Player;
                }
                else
                {
                    whosTurn = WhosTurn.Computer;
                }
            }
            else
            {
                if (whosTurn == WhosTurn.Player)
                {
                    //Checks if players card is valid or not

                    if (game.ValidatePlay(game.PlayerHand[index]) == 0)
                    {
                        Moves.Text       = "YOU CANNOT CHOOSE THIS CARD";
                        Moves.Foreground = new SolidColorBrush(Colors.Maroon);


                        await Task.Delay(700);

                        Moves.Text = "";
                    }
                    else
                    {
                        //If valid checks for special cards
                        if (game.ValidatePlay(game.PlayerHand[index]) == 8)//Card is eight
                        {
                            Moves.Text = "WILDCARD! CHOOSE A NEW CARD WITH A DESIRED SUIT!";

                            whosTurn = WhosTurn.Player;
                        }
                        else if (game.ValidatePlay(game.PlayerHand[index]) == 2)//Card is one
                        {
                            Moves.Text = "COMPUTER TURN SKIPPED, GO AGAIN.";

                            whosTurn = WhosTurn.Player;
                        }
                        else if (game.ValidatePlay(game.PlayerHand[index]) == 1)// Card is regular
                        {
                            whosTurn = WhosTurn.Computer;
                        }

                        userCardsChosen += 1;                     //Keep count of player cards chosen
                        game.SetUserCard(game.PlayerHand[index]); // CHANGES THE UPFACED CARD TO USER CARD
                        UpCard.DisplayCard(game.upFacedCard.CardName);

                        PlayingCards cardUsed = (PlayingCards)sender;

                        cardUsed.DisplayCard("BC");
                        cardUsed.IsEnabled = false; //Makes the chosen card unclickable

                        if (userCardsChosen == 8)   // if player plays all eight cards they win
                        {
                            game.GameOver("PLAYER");
                        }
                    }
                }
            }

            // Computer's turn
            if (whosTurn == WhosTurn.Computer && userCardsChosen != 8)
            {
                await ComputerTurnAsync();

                Moves.Text = game.ComputerMoves;
            }

            BackCard.IsEnabled = true;
            //Displays winner if there is one
            if (game.Winner != null)
            {
                DisableCards();
                Moves.Text       = game.Winner;
                Moves.Foreground = new SolidColorBrush(Colors.Gold);
            }
        }