Exemple #1
0
 public void AddCoins(Coins coins)
 {
     switch (coins.CoinType)
     {
         case CoinType.One:
             Coins.MoveCoins(coins, CoinsInBox.CoinsOne);
             break;
         case CoinType.Two:
             Coins.MoveCoins(coins, CoinsInBox.CoinsTwo);
             break;
         case CoinType.Five:
             Coins.MoveCoins(coins, CoinsInBox.CoinsFive);
             break;
         case CoinType.Ten:
             Coins.MoveCoins(coins, CoinsInBox.CoinsTen);
             break;
     }
 }
        private void InsertCoin(Coins clientCoins, ProgressBar progressBar, Label coinStateLabel)
        {
            if (clientCoins.Amount != 0)
            {
                progressBar.Value--;
                clientCoins.Remove(1);
                _coffeMachine.CoinBox.AddCoin(clientCoins.CoinType);

                labelCoinsInserted.Text = _coffeMachine.CoinBox.GetSumm() + " рублей";
                coinStateLabel.Text = clientCoins.Amount + " монеты";
            }
        }
Exemple #3
0
 public static void MoveCoins(Coins coinsFrom, Coins coinsTo)
 {
     var transferAmoun = coinsFrom.Amount;
     coinsTo.Add(transferAmoun);
     coinsFrom.Remove(transferAmoun);
 }
Exemple #4
0
 public HandfulOfCoins(int coinsOne, int coinsTwo, int coinsFive, int coinsTen)
 {
     CoinsOne = new Coins(CoinType.One, coinsOne);
     CoinsTwo = new Coins(CoinType.Two, coinsTwo);
     CoinsFive = new Coins(CoinType.Five, coinsFive);
     CoinsTen = new Coins(CoinType.Ten, coinsTen);
 }
 /// <summary>
 /// Расчет сдачи по монетам каждого достоинства с проверкой их наличия
 /// </summary>
 /// <param name="summToBack"></param>
 /// <param name="coinsInMachine"></param>
 /// <returns></returns>
 private int GetChangeForCoins(ref int summToBack, Coins coinsInMachine)
 {
     var coinsToBack = summToBack / (int)coinsInMachine.CoinType;
     if (coinsToBack > 0 && coinsInMachine.Amount > 0)
     {
         var coinsToChange = coinsInMachine.Remove(coinsToBack);
         summToBack -= coinsToChange*(int) coinsInMachine.CoinType;
         return coinsToChange;
     }
     return 0;
 }