コード例 #1
0
        public void Accept(Coin coin)
        {
            if (coin.Value() == 0)
            {
                ReturnTray.Add(coin);
                return;
            }

            CoinSlot.Add(coin);
            Context.State = new CurrentValueState(this);
        }
コード例 #2
0
        public PaymentFacade(VendingMachine vendingMachine)
        {
            this.vendingMachine = vendingMachine;
            this.funds          = 0;

            CoinSlot coinSlot = vendingMachine.Hardware.CoinSlot;

            coinSlot.CoinAccepted += new EventHandler <CoinEventArgs>(coinSlot_AcceptCoin);

            this.coinToIndex = new Dictionary <int, int>();
            for (int i = 0; i < vendingMachine.Hardware.CoinRacks.Length; i++)
            {
                coinToIndex[this.vendingMachine.Hardware.GetCoinKindForCoinRack(i).Value] = i;
            }
        }
コード例 #3
0
    public VendingMachineSoftware(List <int> coinKinds, int selectionButtonCount, int coinRackCapacity, int popRackCapacity, int receptacleCapacity)
    {
        // process information
        buttonCount             = selectionButtonCount;
        this.coinRackCapacity   = coinRackCapacity;
        this.popRackCapacity    = popRackCapacity;
        this.receptacleCapacity = receptacleCapacity;
        this.coinKinds          = coinKinds;
        // create machine hardware
        vendingHardware = new VendingMachine(coinKinds.ToArray(), selectionButtonCount, coinRackCapacity, popRackCapacity, receptacleCapacity);
        // default information
        pops          = new List <SoftwarePop>();
        softwareRacks = new List <SoftwareCoinRacks>();
        // create software version of coin racks
        for (int i = 0; i < coinKinds.Count; i++)
        {
            SoftwareCoinRacks newCoinRack = new SoftwareCoinRacks(coinKinds[i], 0);
            softwareRacks.Add(newCoinRack);
        }
        insertedAmount = 0;
        // set up handlers
        CoinSlot coinSlot = vendingHardware.CoinSlot;

        coinSlot.CoinRejected += new EventHandler <CoinEventArgs>(printCoinRejected);
        coinSlot.CoinAccepted += new EventHandler <CoinEventArgs>(printCoinAccepted);
        SelectionButton[] buttons = vendingHardware.SelectionButtons;
        // add handler to each button
        foreach (SelectionButton button in buttons)
        {
            button.Pressed += new EventHandler(printButtonPressed);
        }
        CoinRack[] coinRacks = vendingHardware.CoinRacks;
        // add handler to each coin rack
        foreach (CoinRack coinRack in coinRacks)
        {
            coinRack.CoinAdded += new EventHandler <CoinEventArgs>(printCoinLoaded);
        }
        PopCanRack[] popRacks = vendingHardware.PopCanRacks;
        // add handler to each pop rack
        foreach (PopCanRack rack in popRacks)
        {
            rack.PopCanRemoved += new EventHandler <PopCanEventArgs>(printPopDispensed);
        }
    }
コード例 #4
0
        protected override void DispenseCallback(string sku)
        {
            var priceInCents = ProductInfoRepository.GetPrice(sku);
            var currentTotal = CurrentTotal();

            if (currentTotal < priceInCents)
            {
                Context.State = new PriceState(this, priceInCents.Value);
            }
            else
            {
                Output.Add(sku);
                ProductInfoRepository.DecrementProductCount(sku);

                Vault.AddRange(CoinSlot);
                CoinSlot.Clear();

                Refund(currentTotal, priceInCents);

                Context.State = new ThankYouState(this);
            }
        }
コード例 #5
0
    public void insertCoin(Coin coin)
    {
        CoinSlot coinSlot = vendingHardware.CoinSlot;

        coinSlot.AddCoin(coin);
    }
コード例 #6
0
 public void ReturnCoins()
 {
     ReturnTray.AddRange(CoinSlot);
     CoinSlot.Clear();
     Context.State = new NoMoneyState(this);
 }