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


C# Coin.ToValue方法代码示例

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


在下文中一共展示了Coin.ToValue方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddCoin

        public void AddCoin(Coin coin, int ammount)
        {
            Contract.Requires(ammount > 0);
            Contract.Requires(Contract.Exists(Wallet, el => (decimal)el.Element("Type") == coin.ToValue()),
                "PRE: The coin type must exist in the wallet");
            Contract.Ensures(ammount <= (int)Wallet.Where(c => (decimal)c.Element("Type") == coin.ToValue()).Single().Element("Ammount"));
            Contract.Ensures(Contract.OldValue((int)Wallet.Where(c => (decimal)c.Element("Type") == coin.ToValue()).Single().Element("Ammount")) + ammount ==
                    (int)Wallet.Where(c => (decimal)c.Element("Type") == coin.ToValue()).Single().Element("Ammount"));

            XElement soughtCoin = Wallet.Where(c => (decimal)c.Element("Type") == coin.ToValue()).Single();
            soughtCoin.Element("Ammount").Value = ((int)soughtCoin.Element("Ammount") + ammount).ToString();

            Database.Save("CoinDatabase.xml");
        }
开发者ID:haljin,项目名称:robust,代码行数:14,代码来源:CoinManager.cs

示例2: InsertCoin

        public TransactionResult InsertCoin(Coin coin)
        {
            Contract.Requires(state == State.ProductChosen || state == State.MoneyInserted);
            Contract.Ensures(state == State.MoneyInserted);

            InsertedValue += coin.ToValue();

            CoinMan.AddCoin(coin, 1);
            state = State.MoneyInserted;
            if (SelectedProduct != null && !CoinMan.CheckChange(SelectedProduct.Price, InsertedValue))
                return TransactionResult.SuccessButNoChange;

            return TransactionResult.Success;
        }
开发者ID:haljin,项目名称:robust,代码行数:14,代码来源:VendingMachine.cs

示例3: EjectCoin

        public void EjectCoin(Coin coin, int ammount, LinkedList<Coin> coinCase)
        {
            Contract.Requires(coinCase != null);
            Contract.Requires(ammount >= 0);
            Contract.Requires(Wallet.Where(c => (decimal)c.Element("Type") == coin.ToValue()).Select(c => (int)c.Element("Ammount")).Single() >= ammount,
                    "PRE: There must be enough of coins of given type to eject");
            Contract.Ensures(Contract.OldValue(coinCase.Where(c => c == coin).Count()) + ammount == coinCase.Where(c => c == coin).Count(),
                    "POST: The ejected coins must be in the case");
            Contract.Ensures(Contract.OldValue((int)Wallet.Where(c => (decimal)c.Element("Type") == coin.ToValue()).Single().Element("Ammount")) - ammount ==
                   (int)Wallet.Where(c => (decimal)c.Element("Type") == coin.ToValue()).Single().Element("Ammount"));

            XElement soughtCoin = Wallet.Where(c => (decimal)c.Element("Type") == coin.ToValue()).Single();
            soughtCoin.Element("Ammount").Value = ((int)soughtCoin.Element("Ammount") - ammount).ToString();
            for (int i = 0; i < ammount; ++i)
                coinCase.AddLast(coin);

             Database.Save("CoinDatabase.xml");
        }
开发者ID:haljin,项目名称:robust,代码行数:18,代码来源:CoinManager.cs


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