Example #1
0
        ///////////////////////////////////////////////////////////////////////////////////////
        // Public Methods
        ///////////////////////////////////////////////////////////////////////////////////////


        /// <summary>
        /// Choose a card for the current player to play
        /// </summary>
        /// <param name="card"></param>
        public CardPlayStatus SelectCard(Card card)
        {
            // Don't let humans play on behalf of the computer!
            if (game.CurrentPlayer.Type != Player.PlayerType.Human)
            {
                return(CardPlayStatus.ComputerPlayer);
            }


            // Check if the card can be played before asking for wild colour
            CardPlayStatus wildCheckStatus = CanPlayCardStatus(card);

            if (wildCheckStatus != CardPlayStatus.Success)
            {
                return(wildCheckStatus);
            }

            // Ask for the color for a wild card
            if (card.Color == Card.CardColor.Wild)
            {
                // Show the color chooser dialog form
                WildColorChooser wildColorChooser = new WildColorChooser();
                wildColorChooser.ShowDialog();

                // Check if a colour was chosen, or if the action was cancelled
                if (wildColorChooser.DialogResult == DialogResult.OK)
                {
                    // Remember the chosen wild color
                    game.WildColor = wildColorChooser.Color;
                }
                else
                {
                    // Return that the user cancelled playing the card
                    return(CardPlayStatus.Cancelled);
                }
            }

            // Play the card, with the selected wild color already set if necessary
            return(SelectCard(card, game.CurrentPlayer, false));
        }
Example #2
0
        /// <summary>
        /// Choose a card for the current player to play
        /// </summary>
        public CardPlayStatus PlaySelectedCard(Card card)
        {
            // Check if the card  is allowed to be played
            CardPlayStatus status = CanPlayCardStatus(card);

            // Ask for the color for a wild card
            if (card.Color == Card.CardColor.Wild)
            {
                if (game.CurrentPlayer.Type == Player.PlayerType.Human)
                {
                    // Check if the card can be played before asking for wild colour
                    CardPlayStatus wildCheckStatus = CanPlayCardStatus(card);
                    if (wildCheckStatus != CardPlayStatus.Success)
                    {
                        return(wildCheckStatus);
                    }

                    // Show the color chooser dialog form
                    WildColorChooser wildColorChooser = new WildColorChooser();
                    wildColorChooser.ShowDialog();

                    // Check if a colour was chosen, or if the action was cancelled
                    if (wildColorChooser.DialogResult == DialogResult.OK)
                    {
                        // Remember the chosen wild color
                        game.WildColor = wildColorChooser.Color;
                    }
                    else
                    {
                        // Return that the user cancelled playing the card
                        return(CardPlayStatus.Cancelled);
                    }
                }
                else
                {
                    Random random = new Random();
                    game.WildColor = Card.IntToCardColor(random.Next(0, 3));
                }
            }

            // Check that the card is allowed
            if (status == CardPlayStatus.Success)
            {
                // Move it to the discard pile
                game.DiscardPile.Add(card);
                game.CurrentGamePlayer.Cards.Remove(card);

                // Perform action on action cards
                performAction(card);

                // Add to number of cards played statistic
                game.CurrentGamePlayer.NumberOfCardsPlayed++;

                // If the player is now finished, give them a rank
                if (game.CurrentGamePlayer.Finished)
                {
                    game.CurrentGamePlayer.FinishRank = game.NumberOfFinishedPlayers - 1;
                }

                if (!game.Options.EnableTeams && game.NumberOfFinishedPlayers == game.NumberOfPlayers - 1)
                {
                    // Show the final results
                    Program.NewSortedPlayersView(game);

                    // Setting this bool to true to end the game without dialog box
                    gameView.closeGameWithoutDialog = true;

                    // Close the game view
                    gameView.Close();
                    return(status);
                }
                else if (game.Options.EnableTeams && game.NumberOfFinishedPlayers > 0)
                {
                    int count = 0;
                    foreach (DictionaryEntry curgamePlayer in game.PlayersCards)
                    {
                        Player gamePlayer    = (Player)curgamePlayer.Key;
                        Player currentPlayer = game.CurrentPlayer;
                        if (gamePlayer.Name == currentPlayer.Name)
                        {
                            game.WinningPlayer = count;
                        }
                        count++;
                    }

                    Program.NewSortedPlayersView(game);

                    gameView.closeGameWithoutDialog = true;

                    gameView.Close();
                    return(status);
                }
                else
                {
                    // Setup next player, and update the game view
                    nextPlayer();
                    gameView.ReDraw();
                }
            }

            return(status);
        }