Ejemplo n.º 1
0
        private void PlayPropertyFlippingRound()
        {
            _state.ChequesOnTable = _state.ChequeDeck.Draw(Players.Count()).OrderBy(c => c.Value).ToList();

            foreach (var player in Players)
            {
                var turn = new ForSaleGameTurn {
                    CurrentPlayerId = player.Id, State = _state
                };
                player.GetTurn(turn);
                ProcessTurn(turn);
            }

            // give cheques out to players
            var chequesInOrder            = _state.ChequesOnTable.OrderByDescending(c => c.Value).ToList();
            var flippingPropertiesInOrder = _state.PlayerStates
                                            .Select(p => p.Value.PropertySelling.Value)
                                            .OrderByDescending(p => p)
                                            .ToList();

            foreach (var propertyToFlip in flippingPropertiesInOrder)
            {
                var flippingPlayer = _state.PlayerStates
                                     .SingleOrDefault(p => p.Value.PropertySelling.Value == propertyToFlip);
                var chequeToAllocate = chequesInOrder[0];
                if (chequesInOrder.Remove(chequeToAllocate))
                {
                    flippingPlayer.Value.ChequeCards.Add(chequeToAllocate);
                }
            }
        }
Ejemplo n.º 2
0
        private void PlayPropertyBidRound()
        {
            _state.PropertyCardsOnTable = _state.PropertyDeck.Draw(Players.Count()).OrderBy(c => c.Value).ToList();

            _logger.Information($"Property cards drawn for bidding round");

            var passedPlayers = new List <int>();

            while (_state.PropertyCardsOnTable.Any())
            {
                foreach (var player in Players.Where(p => !passedPlayers.Contains(p.Id)))
                {
                    var turn = new ForSaleGameTurn {
                        CurrentPlayerId = player.Id, State = _state
                    };

                    if (_state.PropertyCardsOnTable.Count() == 1)
                    {
                        PlayerPaysForLastPropertyCard(turn);
                        // TODO this player gos first in next round
                    }
                    else
                    {
                        player.GetTurn(turn);
                        ProcessTurn(turn);
                        if (turn.Passed)
                        {
                            passedPlayers.Add(player.Id);
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private void ProcessPropertyFlippingTurn(ForSaleGameTurn turn)
        {
            var playerState          = _state.PlayerStates[turn.CurrentPlayerId];
            var propertyBeingFlipped = playerState.PropertyCards.SingleOrDefault(p => p.Value == turn.PropertyToFlip.Value);

            if (propertyBeingFlipped != null && playerState.PropertyCards.Remove(propertyBeingFlipped))
            {
                playerState.PropertySelling = propertyBeingFlipped;
            }
        }
Ejemplo n.º 4
0
 private void ProcessPropertyBidTurn(ForSaleGameTurn turn)
 {
     if (turn.Passed)
     {
         ProcessPassingTurn(turn.CurrentPlayerId);
     }
     else
     {
         ProcessBiddingTurn(turn.CurrentPlayerId, turn.BidAmount);
     }
 }
Ejemplo n.º 5
0
 private void ProcessTurn(ForSaleGameTurn turn)
 {
     if (_state.PropertyCardsOnTable.Any())
     {
         ProcessPropertyBidTurn(turn);
     }
     else
     {
         ProcessPropertyFlippingTurn(turn);
     }
 }
Ejemplo n.º 6
0
        private void PlayerPaysForLastPropertyCard(ForSaleGameTurn turn)
        {
            var playerState  = _state.PlayerStates[turn.CurrentPlayerId];
            var cardsOnTable = _state.PropertyCardsOnTable.ToList();
            var cardToTake   = cardsOnTable[0];

            if (cardsOnTable.Remove(cardToTake))
            {
                playerState.PropertyCards.Add(cardToTake);
                playerState.CoinsBid        = 0;
                _state.PropertyCardsOnTable = cardsOnTable;
            }
        }