当前位置: 首页>>代码示例>>C#>>正文


C# IPlayer.HasResources方法代码示例

本文整理汇总了C#中IPlayer.HasResources方法的典型用法代码示例。如果您正苦于以下问题:C# IPlayer.HasResources方法的具体用法?C# IPlayer.HasResources怎么用?C# IPlayer.HasResources使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IPlayer的用法示例。


在下文中一共展示了IPlayer.HasResources方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)}");
        }
开发者ID:Corne,项目名称:VOC,代码行数:25,代码来源:Trade.cs

示例2: 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));
        }
开发者ID:Corne,项目名称:VOC,代码行数:14,代码来源:Bank.cs

示例3: 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()})");
        }
开发者ID:Corne,项目名称:VOC,代码行数:17,代码来源:Bank.cs

示例4: Trade

        public Trade(MaterialType[] offer, MaterialType[] request, IPlayer owner)
        {
            if (offer == null)
                throw new ArgumentNullException(nameof(offer));
            if (request == null)
                throw new ArgumentNullException(nameof(request));
            if (owner == null)
                throw new ArgumentNullException(nameof(owner));

            if (!offer.Any() && !request.Any())
                throw new ArgumentException("You can't create a trade without at least an offer or a request");
            if (offer.Any(m => INVALID_MATERIALS.Contains(m)) || request.Any(m => INVALID_MATERIALS.Contains(m)))
                throw new ArgumentException($"Can't create a trade with invalid material resources ({string.Join(", ", INVALID_MATERIALS)})");
            if (!owner.HasResources(offer))
                throw new InvalidOperationException("Can't offer materials if you don't have them");

            Id = Guid.NewGuid();
            Offer = offer;
            Request = request;
            Owner = owner;
            State = TradeState.Open;
        }
开发者ID:Corne,项目名称:VOC,代码行数:22,代码来源:Trade.cs


注:本文中的IPlayer.HasResources方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。