當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。