Beispiel #1
0
 public Coin(int inventory, int coinValue, CoinInserter inserter, CoinDispenser dispenser, VendingMachineController vmController)
 {
     numCoins          = inventory;
     value             = coinValue;
     coinInserter      = inserter;
     coinDispenser     = dispenser;
     this.vmController = vmController;
 }
 public CoinReturnButton(VendingMachineController controller)
 {
     vmController = controller;
 }
        private void Form1_Load(object sender, EventArgs e)
        {
            amountDisplay = new AmountDisplay(txtAmount);

            displayNum10Yen  = new DebugDisplay(txtNum10Yen);
            displayNum50Yen  = new DebugDisplay(txtNum50Yen);
            displayNum100Yen = new DebugDisplay(txtNum100Yen);
            displayNum500Yen = new DebugDisplay(txtNum500Yen);
            displayPrice0    = new DebugDisplay(txtPrice0);
            displayPrice1    = new DebugDisplay(txtPrice1);
            displayPrice2    = new DebugDisplay(txtPrice2);
            displayPrice3    = new DebugDisplay(txtPrice3);
            displayName0     = new DebugDisplay(txtName0);
            displayName1     = new DebugDisplay(txtName1);
            displayName2     = new DebugDisplay(txtName2);
            displayName3     = new DebugDisplay(txtName3);
            displayNumCans0  = new DebugDisplay(txtNumCan0);
            displayNumCans1  = new DebugDisplay(txtNumCan1);
            displayNumCans2  = new DebugDisplay(txtNumCan2);
            displayNumCans3  = new DebugDisplay(txtNumCan3);

            soldOutLight0 = new Light(pbxSOLight0, Color.Orange);
            soldOutLight1 = new Light(pbxSOLight1, Color.Orange);
            soldOutLight2 = new Light(pbxSOLight2, Color.Orange);
            soldOutLight3 = new Light(pbxSOLight3, Color.Orange);

            noChangeLight = new TimerLight(pbxNoChange, Color.Red, timer1);

            purchasableLight0 = new Light(pbxPurLight0, Color.Aqua);
            purchasableLight1 = new Light(pbxPurLight1, Color.Aqua);
            purchasableLight2 = new Light(pbxPurLight2, Color.Aqua);
            purchasableLight3 = new Light(pbxPurLight3, Color.Aqua);

            coinDispenser10Yen  = new CoinDispenser(txtChange10Yen);
            coinDispenser50Yen  = new CoinDispenser(txtChange50Yen);
            coinDispenser100Yen = new CoinDispenser(txtChange100Yen);
            coinDispenser500Yen = new CoinDispenser(txtChange500Yen);

            // All candispensers share the same output textbox for simulation
            canDispenser0 = new CanDispenser(txtCanDispenser, CANNAMES[0]);
            canDispenser1 = new CanDispenser(txtCanDispenser, CANNAMES[1]);
            canDispenser2 = new CanDispenser(txtCanDispenser, CANNAMES[2]);
            canDispenser3 = new CanDispenser(txtCanDispenser, CANNAMES[3]);

            // Instantiate your entity and control objects
            // Connect these objects

            cans         = new List <Can>();
            coins        = new List <Coin>();
            vmController = new VendingMachineController(cans, coins, noChangeLight, amountDisplay);
            canCola      = new Can(CANPRICES[0], NUMCANS[0], CANNAMES[0], soldOutLight0, purchaseButton0, canDispenser0, vmController, purchasableLight0);
            cans.Add(canCola);
            canPepsi = new Can(CANPRICES[1], NUMCANS[1], CANNAMES[1], soldOutLight1, purchaseButton1, canDispenser1, vmController, purchasableLight1);
            cans.Add(canPepsi);
            canDrPepper = new Can(CANPRICES[2], NUMCANS[2], CANNAMES[2], soldOutLight2, purchaseButton2, canDispenser2, vmController, purchasableLight2);
            cans.Add(canDrPepper);
            canSprite = new Can(CANPRICES[3], NUMCANS[3], CANNAMES[3], soldOutLight3, purchaseButton3, canDispenser3, vmController, purchasableLight3);
            cans.Add(canSprite);

            coin500 = new Coin(NUMCOINS[3], COINVALUES[3], coinInserter500Yen, coinDispenser500Yen, vmController);
            coins.Add(coin500);
            coin100 = new Coin(NUMCOINS[2], COINVALUES[2], coinInserter100Yen, coinDispenser100Yen, vmController);
            coins.Add(coin100);
            coin50 = new Coin(NUMCOINS[1], COINVALUES[1], coinInserter50Yen, coinDispenser50Yen, vmController);
            coins.Add(coin50);
            coin10 = new Coin(NUMCOINS[0], COINVALUES[0], coinInserter10Yen, coinDispenser10Yen, vmController);
            coins.Add(coin10);

            // You must replace the following default constructors with
            // constructors with arguments (non-default constructors)
            // to pass (set) the first object that ButtonPressed() will
            // visit

            purchaseButton0 = new PurchaseButton(canCola);
            purchaseButton1 = new PurchaseButton(canPepsi);
            purchaseButton2 = new PurchaseButton(canDrPepper);
            purchaseButton3 = new PurchaseButton(canSprite);

            // You must replace the following default constructors with
            // constructors that take armuments to pass the first object that
            // the CoinInserted() will call
            coinInserter10Yen  = new CoinInserter(coin10);
            coinInserter50Yen  = new CoinInserter(coin50);
            coinInserter100Yen = new CoinInserter(coin100);
            coinInserter500Yen = new CoinInserter(coin500);

            coinReturnButton = new CoinReturnButton(vmController);

            // Display debug information
            displayCanPricesAndNames();
            updateDebugDisplays();
        }