public void Purchase(Deck deck, Market market) { if (!CanAffordPayingGold()) { throw new DomainException($"{player.ToString()} can not afford {development.ToString()}"); } var goldSpended = Enumerable.Range(0, RequiredGold()).Select(x => Gems.Gold).ToArray(); player.TakeGems(goldSpended); market.Add(goldSpended); var expenses = new List <Gem>(); foreach (var gem in Gems.GetAllGems()) { foreach (int i in Enumerable.Range(0, WouldSpend(gem))) { expenses.Add(gem); market.Add(gem); } } player.TakeGems(expenses.ToArray()); deck.BuyCard(development); player.BuyCard(development); }
public IEnumerable <Noble> CanReceiveVisitFrom() { foreach (var noble in box.NobleList) { bool visitable = Gems.GetAllGems().All(gem => player.Bonus(gem) >= noble.RequiredQuantity(gem)); if (visitable) { yield return(noble); } } }
public Market(int gemCount, int goldCount) { gems = new List <Gem>(); foreach (var gem in Gems.GetAllGems()) { foreach (var i in Enumerable.Range(0, gemCount)) { gems.Add(gem); } } foreach (var i in Enumerable.Range(0, goldCount)) { gems.Add(Gems.Gold); } }
private IEnumerable <Gem> TwoSameRandomGems() => Gems.GetAllGems() .Where(gem => market.CanBeTakenTwoOfType(gem)) .ToList() .RandomizeList() .FirstOrDefault()? .Get(2);
private IEnumerable <Gem> ThreeRandomGems() => Gems.GetAllGems() .Where(gem => market.AvaliableOfType(gem) > 0) .ToList() .RandomizeList() .Take(3);
private string AreMissingText() { return(Gems.GetAllGems() .SelectMany(gem => gem.Get(Missing(gem))) .JoinList()); }
private string WouldSpendText() { return(Gems.GetAllGems() .SelectMany(gem => gem.Get(WouldSpend(gem))) .JoinList()); }
private int RequiredGold() => Gems.GetAllGems().Sum(gem => Missing(gem));
public bool CanAfford() => Gems.GetAllGems().All(gem => player.TotalGems(gem) >= WouldSpend(gem));
public bool IsFree() => Gems.GetAllGems().All(gem => player.Bonus(gem) >= WouldSpend(gem));
public int Cost() => Gems.GetAllGems().Sum(x => WouldSpend(x));