Exemplo n.º 1
0
 /// <summary>
 /// returns all of the coins in the machine and updates the lights
 /// </summary>
 public void CoinReturn()
 {
     if (_totalEntered > 0)
     {
         for (int i = coins.Length - 1; i >= 0; i--)
         {
             _totalEntered -= coins[i].ReduceCoins(_totalEntered);
         }
     }
     amountD.DisplayAmount(_totalEntered);
     LightUpCans();
     timerL.TurnOn3Sec();
 }
 public static void Purchase(Can product)
 {
     if (product.purchasableLight.IsOn() && !product.soldOutLight.IsOn())
     {
         if (GetChange(Coin.TotalCoinsInserted - product.Price))
         {
             product.canDispense.Actuate();
             product.Stock = product.Stock - 1;
         }
         else
         {
             noChangeLight.TurnOn3Sec();
         }
     }
 }
Exemplo n.º 3
0
 public bool CheckIfCanMakeChange(int changeAmount)
 {
     foreach (Coin c in coins)
     {
         changeAmount -= c.makeChange(changeAmount);
     }
     if (changeAmount == 0)
     {
         return(true);
     }
     else
     {
         noChangeLight.TurnOn3Sec();
         return(false);
     }
 }
Exemplo n.º 4
0
        public bool checkIfReturnChange(int price)
        {
            int tmp = totalInsertMoney - price;

            for (int i = coinList.Count - 1; i >= 0; --i)
            {
                tmp -= coinList[i].calculateChange(tmp);
            }

            if (tmp == 0)
            {
                totalInsertMoney = 0;
                return(true);
            }

            noChangeLight.TurnOn3Sec();
            return(false);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Carries out process for when client has purchased a can, determining whether or not the transaction can take place and if so, completing the transaction.
        /// </summary>
        /// <param name="index">Keeps track of which type of drink has been purchased.</param>
        public void PurchasedCan(int index)
        {
            int change; //used to keep track of how much money the machine needs to return

            if (!drinks[index].PurchaseOn())
            {
                return;
            }

            change = drinks[index].CalculateChangeValue(moneyInserted);

            if (!CanMakeChange(change))
            {
                noChange.TurnOn3Sec();
                return;
            }

            drinks[index].DispenseCan();
            MakeChange();
            ClearValues();
        }
Exemplo n.º 6
0
        /// <summary>
        /// Method to hand a purchase buttong being pushed on the machine
        /// </summary>
        /// <param name="index"></param>
        public void PurchaseButtonPushed(int index)
        {
            BeverageIndex = index; //sets the index of the beverage selected by the user

            if (!BeverageArray[BeverageIndex].IsPurchaseable())
            {
                return;                                                 //Checks if beverage is purchaseable or not
            }
            if (!TryGetChange(BeverageArray[BeverageIndex].Price))
            {
                NoChangeLight.TurnOn3Sec(); return;
            }                                        //checks to see if the appropriate amount of change can be made if a certain beverage is to be purchased

            BeverageArray[BeverageIndex].Purchase(); //purchases the beverage

            for (int i = 0; i < CoinArray.Length; i++)
            {
                CoinArray[i].DispenceCoins(); //dispenses the appropriate mixture of coins needed for change
            }
            UpdateLights();                   //updates all the lights on the machine
            AmtDisplay.DisplayAmount(credit); //updates the display amount of credits in the machine
        }
        public bool TryToReturnChange(int price)
        {
            int change = amount - price;

            for (int i = coins.Count - 1; i >= 0; i--)
            {
                change = coins[i].CalcNumCoinsToReturn(change);
            }
            if (change == 0)
            {
                foreach (Coin coin in coins)
                {
                    coin.ReturnCoins();
                }
                ResetDisplays();
                return(true);
            }
            else
            {
                noChangeLight.TurnOn3Sec();
                return(false);
            }
        }
Exemplo n.º 8
0
        public static void purchaseItem(Can product)
        {
            bool changeAvaliable = false;

            if (product.Stock > 0)
            {
                if (totalAmountInserted >= product.Price)
                {
                    changeAvaliable = Coin.returnChange(totalAmountInserted - product.Price);


                    if (changeAvaliable)
                    {
                        product.Stock--;

                        if (product.Stock <= 0)
                        {
                            product.flashSoldOut();
                        }

                        product.dispenseCan();

                        totalAmountInserted = 0;

                        for (int i = 0; i < 4; i++)
                        {
                            allProduct[i].canPurchaseItem();
                        }
                    }
                    else
                    {
                        noChangeLight.TurnOn3Sec();
                    }
                }
            }
        }