Beispiel #1
0
        /// <summary>
        /// Gets next Player object, of which is next to perform an action.
        /// </summary>
        /// <returns> Player object. </returns>
        internal void GiveTurnToNextPlayer()
        {
            int indexOfCurrentPlayer = Players.IndexOf(CurrentPlayer);

            if( (NumberOfPlayers-1) > indexOfCurrentPlayer)
            {
                //The next player is an increment of the currentplayer index
                CurrentPlayer = Players[++indexOfCurrentPlayer];
            }
            //The next player in the list after the last player in the list is the first player.
            CurrentPlayer = Players[0];
        }
Beispiel #2
0
 public override bool StartTurnSequence(Player generalPlayer)
 {
     // To be implemented
     return _gameIsOngoing;
 }
Beispiel #3
0
 //Abstact methods
 public abstract bool StartTurnSequence(Player generalPlayer);
Beispiel #4
0
        /// <summary>
        /// Handles all functionality corresponding to a single turn of a player.
        /// Note That all steps given in the code correspond with the games manual.
        /// </summary>
        /// <param name="generalPlayer"> The player that is allowed to perform all actions corresponding to manual. </param>
        /// <returns> Returns false if game is not over yet, true otherwise. </returns>
        public override bool StartTurnSequence(Player generalPlayer)
        {
            //Cast the player to a Bohnanza player
            var player = (BohnanzaPlayer)generalPlayer;

            // This variable is needed to end the game in step 3 when the deck is exhausted in step 2.
            // See page 8, "Ending and scoring" of the games manual.
            var gameEndsInStep3 = false;

            //Step 1, page 4 manual, "Plant bean cards"
            //---------------------------------------//

            if (player.HandDeck.NumberOfCards > 0)                                               //This step can only be performed if the player has at least one card in the hand.
            {
                //Player MUST place first card in hand

                var beanField = player.Step1PlaceFirstCardFromHand();

                var card = player.HandDeck.GetCard();

                DiscardDeck.PutCards(player.PutCardToBeanField(card, beanField));         //Place card on chosen beanfield, in case a harvest was done return the cards on the discardPile which are no longer needed.

                //Player MAY place the next card in hand

                beanField = player.Step1PlaceSecondCardFromHand();                   //Let the player choose a beanfield on which he wants to plant the card, note that it may return null, in case the player does not want to place this card!

                if (beanField != null)                                                       //The player can choose not to play this card, therefore beanField might be null!
                {
                    card = player.HandDeck.GetCard();                                    //Get the next card of the player.

                    DiscardDeck.PutCards(player.PutCardToBeanField(card, beanField));     //Place card on chosen beanfield, in case a harvest was done return the cards on the discardPile which are no longer needed.
                }
            }

            //Step 2, page 4 manual, "Draw, trade & donate bean cards"
            //------------------------------------------------------//

            //Player must draw two cards from the deck, and place them in the trading area

            for (int i = 0; i < 2; i++)                                                      //Loop two times.
            {
                if (CardDeck.NumberOfCards > 0)                                            //If There are still cards left.
                {
                    player.TradingArea.PutCard(CardDeck.GetCard());                       //Put card to the trading area.
                }
                else
                {
                    if (CardPileExhaustions < MaxNumberOfCardPileExhaustions)         //Check whether another reshuffle is allowed.
                    {
                        ReInitialiseCardPile();                                             //Reshuffle the deck.
                    }
                    else
                    {
                        gameEndsInStep3 = true;                                             //See gameEndsInStep3 variable xml-description for more information.
                    }
                }
            }

            //The player can decide to keep some cards, and place them later on in this turn

            player.Step2KeepCardsOrNot();

            //This player may now trade cards with other players (which he did not want to keep himself)
            //Because all players are behind the same computer-screen, they can freely consult who is interested in the cards and who is not.
            //In other words, this conversation does not needs to be done digitally, which makes the implementation a lot easier:)

            while (player.Step2SuggestTradeToOtherPlayer(Players))                       //Let the player make suggestions of trades to the other players.
            {
            }

            while (player.TradingArea.NumberOfCards > 0)                                   //The player must place any non-traded cards in its sideDeck.
            {
                player.SideDeck.PutCard(player.TradingArea.GetCard());                    //Move one card from tradingArea to the sideDeck of the player.
            }

            //Step 3, page 6 manual, "Plant traded & donated beans"
            //---------------------------------------------------//

            //ALL players must now put all there cards from the sideDeck to the bean fields.
            foreach (Player somePlayer in Players)
            {
                ((BohnanzaPlayer)somePlayer).Step3PlaceAllCardsFromSideDeck(this);
            }

            //Game will be ended here, when gameEndsInStep3 = true. See gameEndsInStep3 variable xml-description for more information.
            if(gameEndsInStep3)
            {
                return false;                                                               //Return false, to end the turn immediately.
            }

            //Step 4, page 4 manual, "Draw new bean cards"
            //------------------------------------------//

            //If the player cannot draw 3 cards, then the game ends immediately (page 8, "Ending and Scoring")

            if (CardDeck.NumberOfCards < 3)                                               //If There are not enough cards left.
            {
                if (CardPileExhaustions < MaxNumberOfCardPileExhaustions)                 //Check whether another reshuffle is allowed.
                {
                    ReInitialiseCardPile();                                                 //Reshuffle the deck.
                }
                else
                {
                    return false;                                                           //Return false, to end the turn immediately.
                }
            }

            player.HandDeck.PutCard(CardDeck.GetCard());                                 //Give 3 cards to the player.
            player.HandDeck.PutCard(CardDeck.GetCard());
            player.HandDeck.PutCard(CardDeck.GetCard());

            //In case this method has not yet returned false (game is not active), then return true (game is still active)
            return true;
        }