本文整理汇总了C#中IPlayer.TakeResources方法的典型用法代码示例。如果您正苦于以下问题:C# IPlayer.TakeResources方法的具体用法?C# IPlayer.TakeResources怎么用?C# IPlayer.TakeResources使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPlayer
的用法示例。
在下文中一共展示了IPlayer.TakeResources方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Accept
public void Accept(IPlayer player)
{
if (player == null)
throw new ArgumentNullException(nameof(player));
if (player == Owner)
throw new ArgumentException("Can't accept a trade if owner == player");
if (!player.HasResources(Request))
throw new InvalidOperationException("Player should have the requested resources");
if (!Owner.HasResources(Offer))
throw new InvalidOperationException("Owner doesn't have the required resources (anymore)!");
lock (tradeLock)
{
if (State != TradeState.Open)
throw new InvalidOperationException("Trade can no longer be accepted, because it's no longer open!");
IRawMaterial[] requested = player.TakeResources(Request);
IRawMaterial[] offered = Owner.TakeResources(Offer);
Owner.AddResources(requested);
player.AddResources(offered);
State = TradeState.Processed;
}
logger.Info($"Trade accepted From {Owner.Name} To {player.Name}. Offer {string.Join(", ", Offer)}, Request {string.Join(", ", Request)}");
}
示例2: BuyResource
public void BuyResource(MaterialType request, MaterialType offer, IPlayer player)
{
if (request == offer)
throw new ArgumentException("Can't request same material as you are offering");
if (!VALID_RESOURCES.Contains(request))
throw new ArgumentException($"Request ({request}) is not a valid material!");
//GetInvestment also validates player != null, and offer is valid resource
MaterialType[] investment = GetInvestmentCost(offer, player);
if (!player.HasResources(investment))
throw new InvalidOperationException("Player does not have the resources to buy");
player.TakeResources(investment);
player.AddResources(new RawMaterial(request));
logger.Info($"{player.Name} bought {request} for {offer}({investment.Count()})");
}
示例3: BuyDevelopmentCard
// 25 Development Cards (14 Knight/Soldier Cards, 6 Progress Cards, 5 Victory Point Cards)
//ore, wool and grain
public void BuyDevelopmentCard(IPlayer player, ITurn turn)
{
if (player == null)
throw new ArgumentNullException(nameof(player));
if (turn == null)
throw new ArgumentNullException(nameof(turn));
if (!player.HasResources(DEVELOPMENTCARD_COST))
throw new InvalidOperationException("Player does not have the resources to buy a Development Card");
player.TakeResources(DEVELOPMENTCARD_COST);
player.AddCard(new DevelopmentCard(deck.Pop(), turn));
}