Exemplo n.º 1
0
        public static string JoinList(this IEnumerable <Development> developments)
        {
            var    quantity = developments.Count();
            string bonus    = (developments.Select(x => x.Bonus).Distinct().Count() == 1) ? $" ({developments.First().Bonus.ToString()})" : "";

            return($"{quantity} {(quantity == 1 ? Development.Singular() : Development.Plural())}{bonus}");
        }
Exemplo n.º 2
0
        private void TakeCard(Development development)
        {
            var taken = deck.Remove(development);

            if (!taken)
            {
                throw new NotFoundException(nameof(Development));
            }

            updateDeck?.Invoke();
        }
Exemplo n.º 3
0
        public void BuyCard(Development development)
        {
            if (!deck.Contains(development))
            {
                throw new NotFoundException($"Can not take {development.ToString()} because it is not in the deck");
            }

            if (!IsVisible(development))
            {
                throw new DomainException($"Can not take {development.ToString()} because it is not visible");
            }

            TakeCard(development);
        }
Exemplo n.º 4
0
        public GameAction MakeMove()
        {
            var development = globalElectionService.Search();

            if (!(development is null))
            {
                new PurchaseService(development, currentPlayer).Purchase(deck, market);
                var noble = ChooseRandomNobleIfPossible();
                return(log.BuyDevelopment(currentTurn, currentPlayer, noble, development));
            }

            if (currentPlayer.TotalGems() <= 5)
            {
                var gems = ThreeRandomGems()?.ToArray() ?? new Gem[0];
                if (market.CanBeTaken(gems))
                {
                    new TakeGemsService(currentPlayer, market, gems).Take();
                    var noble = ChooseRandomNobleIfPossible();
                    return(log.TakeGems(currentTurn, currentPlayer, noble, gems));
                }
            }

            if (currentPlayer.TotalGems() <= 8)
            {
                var gems = TwoSameRandomGems()?.ToArray() ?? new Gem[0];
                if (market.CanBeTaken(gems))
                {
                    new TakeGemsService(currentPlayer, market, gems).Take();
                    var noble = ChooseRandomNobleIfPossible();
                    return(log.TakeGems(currentTurn, currentPlayer, noble, gems));
                }
            }

            Development developmentToReserve = RandomDevelopment();
            var         reserveService       = new ReserveService(developmentToReserve, currentPlayer, market);

            if (reserveService.CanReserve())
            {
                bool takeGold = reserveService.WouldTakeGoldToken();
                reserveService.Reserve(deck);
                var noble = ChooseRandomNobleIfPossible();
                return(log.ReserveDevelopment(currentTurn, currentPlayer, noble, developmentToReserve, takeGold));
            }

            return(null);
        }
Exemplo n.º 5
0
 public void ReserveCard(Development development)
 {
     ReservedDevelopments.Add(development);
     updatePlayer?.Invoke();
 }
Exemplo n.º 6
0
 public void BuyCard(Development development)
 {
     Developments.Add(development);
     updatePlayer?.Invoke();
 }
Exemplo n.º 7
0
        public GameAction ReserveDevelopment(int currentTurn, Player player, Noble noble, Development development, bool takeGold)
        {
            var move = new ReserveDevelopment(development, takeGold, noble);

            Entries.Add(new LogEntry(currentTurn, move, player));
            return(move);
        }
Exemplo n.º 8
0
        public GameAction BuyDevelopment(int currentTurn, Player player, Noble noble, Development development)
        {
            var move = new BuyDevelopment(development, noble);

            Entries.Add(new LogEntry(currentTurn, move, player));
            return(move);
        }
Exemplo n.º 9
0
 public ReserveService(Development development, Player player, Market market)
 {
     this.development = development;
     this.player      = player;
     this.market      = market;
 }
Exemplo n.º 10
0
 public PurchaseService(Development development, Player player)
 {
     this.development = development;
     this.player      = player;
     gold             = player.TotalGems(Gems.Gold);
 }
Exemplo n.º 11
0
 public bool IsVisible(Development development) => VisibleDevelopments().Contains(development);
Exemplo n.º 12
0
 public void ReserveCard(Development development) => TakeCard(development);