예제 #1
0
        private bool TryBuyCard(IStructureCard card, ITurnPlayer player, Age age, SpecialCaseType specialCase)
        {
            if (CanGetForFree(card))
            {
                LoggerHelper.Debug("Card is free.");
                return(true);
            }
            if (HasDemandedCard(card, player.Cards))
            {
                LoggerHelper.Debug("Player can build for free because of previous card");
                return(true);
            }
            if (UseSpecialCase(player, specialCase, age))
            {
                LoggerHelper.DebugFormat("Player can play card for free, because of {0}", specialCase);
                return(true);
            }

            var coins     = card.ResourceCosts.Count(r => r == ResourceType.Coin);
            var resources = card.ResourceCosts.Where(r => r != ResourceType.Coin);

            LoggerHelper.DebugFormat("Structure card costs {0} coins and {1} resources", coins, resources.Count());
            if (player.CoinsLeft >= coins && !player.CheckResourceAvailability(resources.ToList(), false).Any())
            {
                if (coins > 0)
                {
                    unitOfWork.AddEvent(new PayCoinEvent(player, coins));
                }
                return(true);
            }

            return(false);
        }
예제 #2
0
 private bool CanGetForFree(IStructureCard card)
 {
     //The card doesn't cost anything.
     if (!card.CardCosts.Any() && !card.ResourceCosts.Any())
     {
         return(true);
     }
     return(false);
 }
예제 #3
0
        public void Initialize()
        {
            players = new List <ITurnPlayer>
            {
                new TurnPlayer("jennifer"),
                new TurnPlayer("jessica"),
                new TurnPlayer("amanda")
            };

            CreateCards();

            IStructureCard caravansery = cards.First(c => c.Name == CardName.Caravansery);
            IStructureCard foundry     = cards.First(c => c.Name == CardName.Foundry);
            IStructureCard laboratory  = cards.First(c => c.Name == CardName.Laboratory);
            IStructureCard oreVein     = cards.First(c => c.Name == CardName.OreVein);

            #region Player 1
            var player1 = players[0];
            player1.SetSelectableCards(new List <IStructureCard>
            {
                caravansery,
                foundry,
                laboratory,
                oreVein
            });
            player1.SetWonder(WonderFactory.CreateWonder(WonderName.StatueOfZeusInOlimpia, WonderBoardSide.A));
            player1.ReceiveCoin(ConstantValues.INITIAL_COINS);
            player1.InitializeTurnData();
            #endregion

            #region Player 2
            players[1].SetSelectableCards(new List <IStructureCard>
            {
                foundry,
                caravansery,
                laboratory,
                oreVein
            });
            players[1].SetWonder(WonderFactory.CreateWonder(WonderName.LighthouseOfAlexandria, WonderBoardSide.A));
            players[1].ReceiveCoin(ConstantValues.INITIAL_COINS);
            players[1].InitializeTurnData();
            #endregion

            #region Player 3
            players[2].SetSelectableCards(new List <IStructureCard>
            {
                laboratory,
                caravansery,
                foundry,
                oreVein
            });
            players[2].SetWonder(WonderFactory.CreateWonder(WonderName.TempleOfArthemisInEphesus, WonderBoardSide.A));
            players[2].ReceiveCoin(ConstantValues.INITIAL_COINS);
            players[2].InitializeTurnData();
            #endregion
        }
예제 #4
0
        public bool HasCard(IStructureCard card)
        {
            var result = this.Cards.Any(c => c.Name == card.Name);

            if (result)
            {
                LoggerHelper.Debug("Player has the card already.");
            }
            return(result);
        }
예제 #5
0
        /// <summary>
        /// Buys the selected card.
        /// </summary>
        /// <param name="card">The selected card.</param>
        /// <param name="player">Player buying the card.</param>
        /// <param name="age">The age that is being played.</param>
        /// <param name="specialCase">The user wants to use a special case card.</param>
        /// <returns></returns>
        private bool BuyCard(IStructureCard card, ITurnPlayer player, Age age, SpecialCaseType specialCase = SpecialCaseType.None)
        {
            bool result = TryBuyCard(card, player, age, specialCase);

            if (result)
            {
                LoggerHelper.Debug("Card can be bought");
                unitOfWork.AddEvent(new AddCardEvent(player, card));
            }
            return(result);
        }
예제 #6
0
        private void CheckResourcesToBorrow(IStructureCard card, ITurnPlayer player)
        {
            IList <ResourceType> missingResources = new List <ResourceType>();

            if ((player.ChosenAction == TurnAction.BuyCard && (CanGetForFree(card) || HasDemandedCard(card, player.Cards))) || ValidSpecialCase(player, player.SpecialCaseToUse, age) != null)
            {
                return;
            }

            IList <ResourceType> resourcesToCheck = new List <ResourceType>();

            if (player.ChosenAction == TurnAction.BuildWonderStage && player.Wonder.NextStage != null)
            {
                foreach (var c in player.Wonder.NextStage.Costs)
                {
                    resourcesToCheck.Add(c);
                }
            }
            if (player.ChosenAction == TurnAction.BuyCard)
            {
                foreach (var c in card.ResourceCosts)
                {
                    resourcesToCheck.Add(c);
                }
            }
            //Remove predefined resources to borrow
            foreach (var r in player.ResourcesToBorrow)
            {
                var index = resourcesToCheck.IndexOf(r.ResourceType);
                if (index >= 0)
                {
                    resourcesToCheck.RemoveAt(index);
                }
            }
            missingResources = player.CheckResourceAvailability(resourcesToCheck.Where(r => r != ResourceType.Coin).ToList(), false);

            if (missingResources.Any())
            {
                LoggerHelper.DebugFormat("Will need to borrow {0} resources that were not set.", missingResources.Count);
            }
            //Add the rest of the needed resources to list
            foreach (var r in missingResources)
            {
                player.ResourcesToBorrow.Add(new BorrowResourceData
                {
                    ChosenNeighbor = PlayerDirection.None,
                    ResourceType   = r
                });
            }
        }
예제 #7
0
        private bool HasDemandedCard(IStructureCard card, IList <IStructureCard> currentCards)
        {
            bool result = false;

            foreach (var c in card.CardCosts)
            {
                //Player has the required card to be able to construct for free
                if (currentCards.Any(cc => cc.Name == c))
                {
                    result = true;
                    continue;
                }
            }
            return(result);
        }
예제 #8
0
        static void ShowCardOption(IStructureCard card, int choice)
        {
            var sb        = string.Format("{0} - {1} ({2})", choice, card.Name.ToString().ToUpper(), card.Type);
            var resSb     = new StringBuilder();
            var separator = "";

            if (!card.CardCosts.Any() && !card.ResourceCosts.Any())
            {
                resSb.Append(" -> Free");
            }
            else
            {
                resSb.Append(" -> ");
                if (card.CardCosts.Any())
                {
                    var cc = string.Empty;
                    foreach (var c in card.CardCosts)
                    {
                        cc       += separator + c.ToString();
                        separator = ";";
                    }
                    resSb.AppendFormat("Card costs = {0}", cc);
                }

                if (card.CardCosts.Any() && card.ResourceCosts.Any())
                {
                    resSb.Append(" | ");
                }

                if (card.ResourceCosts.Any())
                {
                    var rc = string.Empty;
                    separator = "";
                    foreach (var r in card.ResourceCosts)
                    {
                        rc       += separator + r.ToString();
                        separator = ";";
                    }
                    resSb.AppendFormat("Resource costs = {0}", rc);
                }
            }
            var efSb = new StringBuilder(" => ");

            separator = "";
            foreach (var e in card.StandaloneEffect)
            {
                var addInfo = "";
                var dir     = GetPlayerDirections(e.Direction);
                if (!string.IsNullOrWhiteSpace(dir))
                {
                    addInfo = "(" + dir + ")";
                }
                efSb.Append(separator + e.Type.ToString() + dir);
                separator = ";";
            }
            separator = "";
            foreach (var e in card.ChoosableEffect)
            {
                var addInfo = "";
                var dir     = GetPlayerDirections(e.Direction);
                if (!string.IsNullOrWhiteSpace(dir))
                {
                    addInfo = "(" + dir + ")";
                }
                efSb.Append(separator + e.Type.ToString() + dir);
                separator = "|";
            }
            Console.WriteLine(sb.ToString().PadRight(35) + resSb.ToString().PadRight(65) + efSb.ToString());
        }
예제 #9
0
 public DrawFromDiscardPileEvent(IStructureCard cardToRemove, IList <IStructureCard> discardedCards)
 {
     this.cardToRemove   = cardToRemove;
     this.discardedCards = discardedCards;
 }
 public DiscardCardEvent(IStructureCard cardToAdd, IList <IStructureCard> discardedCards)
 {
     this.cardToAdd      = cardToAdd;
     this.discardedCards = discardedCards;
 }
예제 #11
0
 public AddCardEvent(IGamePlayer player, IStructureCard card)
 {
     this.player = player;
     this.card   = card;
 }