/// <summary> /// Choose a card for the current player to play /// </summary> public CardPlayStatus SelectCard(Card card, Player player, bool computer) { // Check if the card is allowed to be played CardPlayStatus status = CanPlayCardStatus(card); // 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; } // Setup next player, and update the game view nextPlayer(); gameView.ReDraw(); } return(status); }
// Check if a card can be played public CardPlayStatus CanPlayCardStatus(Card card) { // Assume success unless otherwise (because we're looking for the reason it isn't allowed) CardPlayStatus success = CardPlayStatus.Success; // Check the colour is correct, or the card is a wild if (card.Color != Card.CardColor.Wild && card.Color != game.CurrentColor && card.Face != game.CurrentFace) { success = CardPlayStatus.WrongColor; } // Don't allow Draw 4s when the player has a card of the current color if (!game.Options.AllowDraw4Always && card.Face == Card.CardFace.Draw4) { bool checkForCurrentColor = false; // Look at each card to check if the player holds any cards of the current color foreach (Card c in game.CurrentGamePlayer.Cards) { if (c.Color == game.CurrentColor) { // We can stop checking now checkForCurrentColor = true; break; } } // Set the success status if (checkForCurrentColor) { success = CardPlayStatus.Draw4NotAllowed; } } // Don't allow playing somebody else's cards! // TODO: allow optional pickup put downs if (game.CurrentGamePlayer.Cards.IndexOf(card) < 0) { if (game.DiscardPile.IndexOf(card) > -1) { // The card is in the discard pile success = CardPlayStatus.DiscardPile; } else { // The card is in someone else's hand success = CardPlayStatus.IncorrectPlayer; } } return(success); }
/////////////////////////////////////////////////////////////////////////////////////// // 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)); }
/// <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); }