void Start() {
     vendingMachine = GameObject.Find("VendingMachine").GetComponent<VendingMachine>();
     pauseUpgrade = GameObject.Find("PauseUpgrade");
     UpgadeList = new List<GameObject>();
     GetButtonReferences(false);
     DisablePauseScreen();
 }
        public void CustomerIsAbleToSelectProductAndReceiveChange()
        {
            var vendingMachine = new VendingMachine();
            vendingMachine.AddStock(Product.Candy);
            vendingMachine.AcceptCoin("quarter");
            vendingMachine.AcceptCoin("penny");
            vendingMachine.AcceptCoin("quarter");
            vendingMachine.AcceptCoin("dime");
            vendingMachine.AcceptCoin("dime");
            Assert.That(vendingMachine.GetDisplay(), Is.EqualTo("$0.70"));

            vendingMachine.SelectProduct(Product.Candy);
            Assert.That(vendingMachine.GetDisplay(), Is.EqualTo("THANK YOU"));
            Assert.That(vendingMachine.GetDisplay(), Is.EqualTo("INSERT COIN"));
            var change = vendingMachine.EmptyCoinReturn();
            foreach (var coin in change)
            {
                vendingMachine.AcceptCoin(coin);
            }

            Assert.That(vendingMachine.GetDisplay(), Is.EqualTo("$0.05"));
            vendingMachine.SelectProduct(Product.Candy);
            Assert.That(vendingMachine.GetDisplay(), Is.EqualTo("SOLD OUT"));
            Assert.That(vendingMachine.GetDisplay(), Is.EqualTo("$0.05"));
        }
 public void CreateAndStockVendingMachine()
 {
     var vm = new VendingMachine();
     vm.AddStock(Product.Candy);
     vm.AddStock(Product.Chips);
     vm.AddStock(Product.Cola);
     this.vendingMachine = vm;
 }
Example #4
0
        static void Main()
        {
            var vendingMachine = new VendingMachine();

            vendingMachine.DepositNickel();
            vendingMachine.DepositDime();
            vendingMachine.DepositNickel();
            vendingMachine.DepositNickel();
            vendingMachine.DepositNickel();
        }
Example #5
0
        public static void Main()
        {
            VendingMachine vendingMachine = new VendingMachine();
            vendingMachine.AddDrink("coffee", 0.50);
            vendingMachine.AddDrink("tea", 0.30);
            vendingMachine.AddDrink("hot-chocolate", 0.80);

            vendingMachine.InsertCoins(0.30);
            vendingMachine.GetDrink("tea");
            vendingMachine.InsertCoins(1.0);
            vendingMachine.GetDrink("hot-chocolate");
        }
        public static void Send(Client client, VendingMachine vendingMachine)
        {
            PacketWriter packetWriter = new PacketWriter();

            packetWriter.PushByte(0xdf);
            packetWriter.PushByte(0xdf);
            packetWriter.PushShort(0xa);
            packetWriter.PushShort(1);
            packetWriter.PushShort(0);
            packetWriter.PushInt(3086);
            packetWriter.PushInt(client.Character.Id);
            packetWriter.PushInt(0x7f544905); // 20
            packetWriter.PushIdentity(vendingMachine.Type, vendingMachine.Id);
            packetWriter.PushByte(0);
            packetWriter.PushInt(0xb); // Counter??
            packetWriter.PushInt(0);
            packetWriter.PushInt(0); // 41
            packetWriter.PushCoord(vendingMachine.Coordinates);
            packetWriter.PushQuat(vendingMachine.Heading); // 69
            packetWriter.PushInt(vendingMachine.PlayField);
            packetWriter.PushInt(1000015);
            packetWriter.PushInt(0);
            packetWriter.PushShort(0x6f);
            packetWriter.PushInt(0x2379);
            packetWriter.PushInt(0); // 91
            packetWriter.PushByte(0x80);
            packetWriter.PushByte(2);
            packetWriter.PushShort(0x3603);
            packetWriter.PushInt(0x17);
            packetWriter.PushInt(vendingMachine.TemplateId);
            packetWriter.PushInt(0x2bd);
            packetWriter.PushInt(0); // 111
            packetWriter.PushInt(0x2be);
            packetWriter.PushInt(0);
            packetWriter.PushInt(0x2bf);
            packetWriter.PushInt(0);
            packetWriter.PushInt(0x19c); // 131
            packetWriter.PushInt(1);
            packetWriter.PushInt(0x1f5);
            packetWriter.PushInt(2);
            packetWriter.PushInt(0x1f4);
            packetWriter.PushInt(0);
            packetWriter.PushInt(0);
            packetWriter.PushInt(2);
            packetWriter.PushInt(0x32); // 147
            packetWriter.Push3F1Count(0);
            packetWriter.PushInt(3); // 155<

            byte[] packet = packetWriter.Finish();
            client.SendCompressed(packet);
        }
        public void CustomerIsAbleToReturnCoinsAfterSelectingSoldOutProduct()
        {
            var vendingMachine = new VendingMachine();
            vendingMachine.AddStock(Product.Candy);
            vendingMachine.AcceptCoin("quarter");
            vendingMachine.AcceptCoin("quarter");
            vendingMachine.AcceptCoin("quarter");
            vendingMachine.AcceptCoin("quarter");
            Assert.That(vendingMachine.GetDisplay(), Is.EqualTo("$1.00"));

            vendingMachine.SelectProduct(Product.Cola);
            Assert.That(vendingMachine.GetDisplay(), Is.EqualTo("SOLD OUT"));
            Assert.That(vendingMachine.GetDisplay(), Is.EqualTo("$1.00"));

            vendingMachine.ReturnCoins();
            Assert.That(vendingMachine.EmptyCoinReturn(), Is.EquivalentTo(new[] { "quarter", "quarter", "quarter", "quarter" }));
        }
        public static void SendOwner(Client client, VendingMachine vendingMachine, int itemNumber)
        {
            PacketWriter packetWriter = new PacketWriter();

            packetWriter.PushByte(0xdf);
            packetWriter.PushByte(0xdf);
            packetWriter.PushShort(0xa);
            packetWriter.PushShort(1);
            packetWriter.PushShort(0);
            packetWriter.PushInt(3086);
            packetWriter.PushInt(client.Character.Id);
            packetWriter.PushInt(0x3b11256f);
            packetWriter.PushIdentity(0xc76e, 0x021fa86f); // whats this one???
            packetWriter.PushByte(0);
            packetWriter.PushInt(11);
            packetWriter.PushIdentity(client.Character.Type, client.Character.Id);
            packetWriter.PushInt(client.Character.PlayField);
            packetWriter.PushInt(0x0f424f);
            packetWriter.PushInt(0);
            packetWriter.PushShort(0x656f); // ??????
            packetWriter.Push3F1Count(6);
            packetWriter.PushInt(0);
            packetWriter.PushByte(0x80);
            packetWriter.PushByte(0);
            packetWriter.PushShort(0x0203);
            packetWriter.PushInt(0x17);
            packetWriter.PushInt(vendingMachine.Inventory[itemNumber].Item.LowID);
            // TODO: Three times low id and no high id?
            packetWriter.PushInt(0x2bd);
            packetWriter.PushInt(1);
            packetWriter.PushInt(0x2be);
            packetWriter.PushInt(vendingMachine.Inventory[itemNumber].Item.LowID);
            packetWriter.PushInt(0x2bf);
            packetWriter.PushInt(vendingMachine.Inventory[itemNumber].Item.LowID);
            packetWriter.PushInt(0x19c);
            packetWriter.PushInt(1);
            packetWriter.PushInt(0);
            // TODO: Actually send the data, probably research needed
        }
        public static void Send(Client client, VendingMachine vendingMachine)
        {
            PacketWriter packetWriter = new PacketWriter();

            packetWriter.PushByte(0xdf);
            packetWriter.PushByte(0xdf);
            packetWriter.PushShort(0xa);
            packetWriter.PushShort(1);
            packetWriter.PushShort(0);
            packetWriter.PushInt(3086);
            packetWriter.PushInt(client.Character.Id);
            packetWriter.PushInt(0x58362220);
            packetWriter.PushIdentity(vendingMachine.Type, vendingMachine.Id);
            packetWriter.PushByte(1);
            packetWriter.Push3F1Count(vendingMachine.Inventory.Count);
            foreach (InventoryEntries ie in vendingMachine.Inventory)
            {
                packetWriter.PushInt(ie.Item.LowID);
                packetWriter.PushInt(ie.Item.HighID);
                packetWriter.PushInt(ie.Item.Quality);
            }
            byte[] packet = packetWriter.Finish();
            client.SendCompressed(packet);
        }
 protected abstract TOutEvent Execute(VendingMachine vendingMachine, TInCommand command);
Example #11
0
        public static void StatePattern()
        {
            var vm = new VendingMachine(new Full());

            vm.Request();
        }
 object OnBuyVendingItem(VendingMachine machine, BasePlayer player, int sellOrderID, int amount)
 {
     machine.ClientRPC <int>(null, "CLIENT_StartVendingSounds", sellOrderID);
     machine.DoTransaction(player, sellOrderID, amount);
     return(false);
 }
 // constructor
 public IdleVendingMachineState(VendingMachine vmIn) : base(vmIn)
 {
 }
Example #14
0
 public WinState(VendingMachine mVendingMachine)
 {
     this.m_vendingMachine = mVendingMachine;
 }
        public void only_a_dime_is_returned()
        {
            VendingMachine.InsertCoin(Coin.Dollar);

            Assert.Equal(Coin.Dollar, VendingMachine.CoinReturn().Single());
        }
 protected void given_a_new_VendingMachine()
 {
     machine = new VendingMachine();
 }
Example #17
0
 public void Dispense(VendingMachine vendingMachine)
 {
     System.Console.WriteLine("Sorry out of Stock");
 }
Example #18
0
 public void InsertDollar(VendingMachine vendingMachine)
 {
 }
Example #19
0
        public void VendingDoesHaveEnoughChangeTest()
        {
            Customer customer = new Customer("customer");
            Coin coin = new Coin(10);
            Coin coin1 = new Coin(5);
            customer.Wallet.AddItem(coin);
            customer.Wallet.AddItem(coin1);

            VendingMachine vmachine = new VendingMachine("vmachine");
            GoodsItem item = new GoodsItem(7, "green tea");
            vmachine.GoodsStorage.AddItem(item);

            customer.InsertCoin(coin, vmachine);
            customer.InsertCoin(coin1, vmachine);

            vmachine.SellTheItem(item, customer);

            Assert.AreEqual(15, customer.Wallet.MoneyAmount, "customer wallet");
            Assert.AreEqual(0, customer.GoodsStorage.GoodsCount, "customer goods storage");
            Assert.AreEqual(0, vmachine.Wallet.MoneyAmount, "vm wallet");
            Assert.AreEqual(1, vmachine.GoodsStorage.GoodsCount, "vm goods storage");
        }
Example #20
0
        public void VendingReturnChangeTest()
        {
            Customer customer = new Customer("customer");
            Coin coin = new Coin(10);
            Coin coin1 = new Coin(10);
            customer.Wallet.AddItem(coin);
            customer.Wallet.AddItem(coin1);

            VendingMachine vmachine = new VendingMachine("vmachine");
            GoodsItem item = new GoodsItem(15, "green tea");
            vmachine.GoodsStorage.AddItem(item);
            
            Coin coin0 = new Coin(5);
            Coin coin01 = new Coin(3);
            Coin coin02 = new Coin(2);
            vmachine.Wallet.AddItem(coin0);
            vmachine.Wallet.AddItem(coin01);
            vmachine.Wallet.AddItem(coin02);

            customer.InsertCoin(coin, vmachine);
            customer.InsertCoin(coin1, vmachine);

            vmachine.SellTheItem(item, customer);

            Assert.AreEqual(5, customer.Wallet.MoneyAmount, "customer wallet");
            Assert.AreEqual(1, customer.GoodsStorage.GoodsCount, "customer goods storage");
            Assert.AreEqual(1, customer.Wallet.GetItems(a=>a==coin0,-1).Count, "customer wallet");
            Assert.AreEqual(25, vmachine.Wallet.MoneyAmount, "vm wallet");
            Assert.AreEqual(0, vmachine.GoodsStorage.GoodsCount, "vm goods storage");
        }
        public void throws_an_exception()
        {
            var exception = Assert.Throws <ArgumentException>(() => VendingMachine.InsertCoin(new FakeCoin()));

            Assert.Equal("This vending machine does not accept FakeCoin. Please insert legal tender.", exception.Message);
        }
 public void CreateVendingMachine()
 {
     this.vendingMachine = new VendingMachine();
 }
Example #23
0
 public void EjectMoney(VendingMachine vendingMachine)
 {
 }
 void before_each()
 {
     vendingMachine = new VendingMachine();
 }
Example #25
0
 void before_each()
 {
     vendingMachine = new VendingMachine();
 }
 public void Initialize()
 {
     stockInventory = new VMFileReader("vendingmachine.csv");
     inventory      = stockInventory.GetInventory();
     vend           = new VendingMachine(inventory);
 }
Example #27
0
 // constructor
 public MakeChangeVendingMachineState(VendingMachine VM) : base(VM)
 {
 }
Example #28
0
 public BuyingSpecs()
 {
     _vendingMachine = new VendingMachine();
 }
Example #29
0
 public UserInterface(VendingMachine thisVendingMachine)
 {
     vend = thisVendingMachine;
 }
Example #30
0
    public void InitlizeVendingState(T state, VendingMachine vendingMachine)
    {
        Initlize(vendingMachine as StateMachine <T>);

        _vendingMachine = vendingMachine;
    }
 public void SetupTest()
 {
     machine = new VendingMachine();
 }
        /*
         * This area may come of use later once I do more advanced damage detection on shop buildings
         *
         * private BasePlayer Owner(BaseEntity entity) =>
         *  this.Player.Players.FirstOrDefault(x => x.userID == entity.OwnerID);
         */

        //this would normally be hammer only but since spawning on ground is a thing i made it for all weapons
        private void OnPlayerAttack(BasePlayer attacker, HitInfo info)
        {
            VendingMachine machine = info.HitEntity as VendingMachine;

            if (machine == null)
            {
                if (this.queuedSpawns.Contains(attacker))
                {
                    Vector3 spawn = info.HitPositionWorld;

                    Quaternion rotation = Quaternion.LookRotation(attacker.ServerPosition - spawn);  //flipped so front faces player
                    rotation = Quaternion.Euler(0f, rotation.eulerAngles.y, rotation.eulerAngles.z); //lock X so it doesnt rotate up or down

                    VendingMachine entity = (VendingMachine)GameManager.server.CreateEntity("assets/prefabs/deployable/vendingmachine/vendingmachine.deployed.prefab", spawn, rotation);
                    entity.Spawn();

                    attacker.ChatMessage(this.Lang("SpawnSuccess", attacker));
                    this.NextFrame(() => this.queuedSpawns.Remove(attacker)); //remove next frame so the hit entity doesnt take damage
                }

                return;
            }

            if (this.queuedShops.ContainsKey(attacker))
            {
                this.ApplyMachine(machine, this.queuedShops[attacker]);

                if (_activeShops.ContainsKey(machine))
                {
                    _activeShops[machine] = this.queuedShops[attacker];
                }
                else
                {
                    _activeShops.Add(machine, this.queuedShops[attacker]);
                }

                attacker.ChatMessage(this.Lang("ApplySuccess", attacker, this.queuedShops[attacker].CommandName));
                this.queuedShops.Remove(attacker);
            }
            else if (this.queuedWipes.Contains(attacker))
            {
                if (_activeShops.ContainsKey(machine))
                {
                    this.WipeMachine(machine);
                    this.queuedWipes.Remove(attacker);
                    attacker.ChatMessage(this.Lang("WipeSuccess", attacker));
                }
            }
            else if (this.queuedDisables.Contains(attacker))
            {
                if (_activeShops.ContainsKey(machine))
                {
                    _activeShops.Remove(machine);
                    this.queuedDisables.Remove(attacker);
                    attacker.ChatMessage(this.Lang("DisableSuccess", attacker));
                }
            }
            else if (this.queuedSaves.ContainsKey(attacker))
            {
                this.SaveMachine(machine, this.queuedSaves[attacker]);
                this.Config.WriteObject(WorldShopsSettings.Loaded);

                attacker.ChatMessage(this.Lang("SaveSuccess", attacker, this.queuedSaves[attacker].CommandName));
                this.queuedSaves.Remove(attacker);
            }
        }
Example #33
0
        public void InitialState_NoMoneyInserted()
        {
            var vm = new VendingMachine();

            Assert.That(vm.Amount, Is.EqualTo(0.00M));
        }
        public void T01_good_insert_and_press_exact_change()
        {
            List <VendingMachine> vendingMachines = new List <VendingMachine>();          // Create list of VMs.

            //==========================================================================================================
            //  CREATE(5, 10, 25, 100; 3; 10; 10; 10):
            int[] coinKinds            = { 5, 10, 25, 100 };
            int   selectionButtonCount = 3;
            int   coinRackCapacity     = 10;
            int   popRackCapcity       = 10;
            int   receptacleCapacity   = 10;
            // Create VM:
            var vm = new VendingMachine(coinKinds, selectionButtonCount, coinRackCapacity, popRackCapcity, receptacleCapacity);
            VendingMachineLogic vmLogic = new VendingMachineLogic(vm);

            //Add it to the list of VM's:
            vendingMachines.Add(vm);

            int index = 0;                                                              // Index of VM which is going to be checked.

            vm = vendingMachines[index];                                                // Reference to the vending machine at index 0.

            //==================================================================================================================
            //  CONFIGURE([0] "Coke", 250; "water", 250; "stuff", 205):
            List <string> popNames = new List <string>()
            {
                "Coke", "water", "stuff"
            };
            List <int> popCosts = new List <int>()
            {
                250, 250, 205
            };

            vm.Configure(popNames, popCosts);

            //===================================================================================================================
            //  COIN_LOAD([0] 0; 5, 1):
            int         coinKindIndex = 0;
            List <Coin> coins         = new List <Coin> {
                new Coin(5)
            };

            vm.CoinRacks[coinKindIndex].LoadCoins(coins);

            // COIN_LOAD([0] 1; 10, 1):
            coinKindIndex = 1;
            coins         = new List <Coin> {
                new Coin(10)
            };
            vm.CoinRacks[coinKindIndex].LoadCoins(coins);

            //  COIN_LOAD([0] 2; 25, 2):
            coinKindIndex = 2;
            coins         = new List <Coin> {
                new Coin(25), new Coin(25)
            };
            vm.CoinRacks[coinKindIndex].LoadCoins(coins);

            //=====================================================================================================================
            //  POP_LOAD([0] 0; "Coke", 1):
            int           popKindIndex = 0;
            List <PopCan> pops         = new List <PopCan> {
                new PopCan("Coke")
            };

            vm.PopCanRacks[popKindIndex].LoadPops(pops);

            //  POP_LOAD([0] 1; "water", 1):
            popKindIndex = 1;
            pops         = new List <PopCan> {
                new PopCan("water")
            };
            vm.PopCanRacks[popKindIndex].LoadPops(pops);

            //  POP_LOAD([0] 2; "stuff", 1):
            popKindIndex = 2;
            pops         = new List <PopCan> {
                new PopCan("stuff")
            };
            vm.PopCanRacks[popKindIndex].LoadPops(pops);

            //=======================================================================================================================
            //  INSERT([0] 100)
            //  INSERT([0] 100)
            //  INSERT([0] 25)
            //  INSERT([0] 25):
            vm.CoinSlot.AddCoin(new Coin(100));
            vm.CoinSlot.AddCoin(new Coin(100));
            vm.CoinSlot.AddCoin(new Coin(25));
            vm.CoinSlot.AddCoin(new Coin(25));

            //======================================================================================================================
            //  PRESS([0] 0):
            vm.SelectionButtons[0].Press();

            //=====================================================================================================================
            //  EXTRACT([0])
            //  CHECK_DELIVERY(0, "Coke"):
            // Get actual list of items from the delivery chute and create expected list of items:
            var items = vm.DeliveryChute.RemoveItems();
            List <IDeliverable> itemsAsList         = new List <IDeliverable>(items);
            List <IDeliverable> expectedItemsAsList = new List <IDeliverable> {
                new PopCan("Coke")
            };

            // Check to see if two lists are of the same length, if not, throw the exception:
            if (itemsAsList.Count == expectedItemsAsList.Count)
            {
                int i = 0;
                while (i < items.Length)
                {
                    // Compare element by element:
                    var element1 = items[i];
                    var element2 = expectedItemsAsList[i];
                    Assert.AreEqual(element1.ToString(), element2.ToString());
                    i++;
                }
            }
            // Lists have different length, they are not the same, throw the exception:
            else
            {
                throw new AssertFailedException();
            }

            //=====================================================================================================================
            //  UNLOAD([0])
            //  CHECK_TEARDOWN(315; 0; "water", "stuff"):
            //  Modify fields of the StoredContents obj, which corresponds to actual VM:
            var storedContents = new VendingMachineStoredContents();

            foreach (var coinRack in vm.CoinRacks)
            {
                // Add items to CoinInCoinsRacks field:
                storedContents.CoinsInCoinRacks.Add(coinRack.Unload());
            }

            // Modify PaymentCoinsInStorageBin field (add some items to it):
            storedContents.PaymentCoinsInStorageBin.AddRange(vm.StorageBin.Unload());

            foreach (var popCanRack in vm.PopCanRacks)
            {
                // Add items to PopCansInPopCanRacks field:
                storedContents.PopCansInPopCanRacks.Add(popCanRack.Unload());
            }

            // Modify fields of the StoredContents obj, based on expected values:
            VendingMachineStoredContents expectedStoredContents = new VendingMachineStoredContents();

            // Modify PaymentCoinsInStorageBin field of the expected one:
            List <Coin> expectedCoinsInStorageBin = new List <Coin>();

            foreach (var coin in expectedCoinsInStorageBin)
            {
                expectedStoredContents.PaymentCoinsInStorageBin.Add(coin);
            }

            // Create some lists in order to add them to CoinsInCoinRacks of the expected one:
            List <Coin> expectedCoinRack0 = new List <Coin> {
                new Coin(5)
            };
            List <Coin> expectedCoinRack1 = new List <Coin> {
                new Coin(10)
            };
            List <Coin> expectedCoinRack2 = new List <Coin> {
                new Coin(25), new Coin(25), new Coin(25), new Coin(25)
            };
            List <Coin> expectedCoinRack3 = new List <Coin> {
                new Coin(100), new Coin(100)
            };
            List <List <Coin> > expectedListOfCoinRacks = new List <List <Coin> > {
                expectedCoinRack0, expectedCoinRack1, expectedCoinRack2, expectedCoinRack3
            };

            foreach (var list in expectedListOfCoinRacks)
            {
                //  Modify CoinsInCoinRacks field by adding some items to it:
                expectedStoredContents.CoinsInCoinRacks.Add(list);
            }

            // Create some lists in order to add them to PopCansInPopCanRacks of the expected one:
            List <PopCan> expectedPopRack0 = new List <PopCan>();
            List <PopCan> expectedPopRack1 = new List <PopCan> {
                new PopCan("water")
            };
            List <PopCan> expectedPopRack2 = new List <PopCan> {
                new PopCan("stuff")
            };
            List <List <PopCan> > expectedListOfPopRacks = new List <List <PopCan> > {
                expectedPopRack0, expectedPopRack1, expectedPopRack2
            };

            foreach (var list in expectedListOfPopRacks)
            {
                //  Modify PopCansInPopCanRacks field by adding some items to it:
                expectedStoredContents.PopCansInPopCanRacks.Add(list);
            }

            // Comparison of expected and actual VM's storage bins:
            // Check length of lists first, if different, throw the exception:
            if (storedContents.PaymentCoinsInStorageBin.Count == expectedStoredContents.PaymentCoinsInStorageBin.Count)
            {
                int i = 0;

                // Check each element of the list:
                while (i < storedContents.PaymentCoinsInStorageBin.Count)
                {
                    Assert.AreEqual(storedContents.PaymentCoinsInStorageBin[i].Value, expectedStoredContents.PaymentCoinsInStorageBin[i].Value);
                    i++;
                }
            }
            // Length is different, throw the exception:
            else
            {
                throw new AssertFailedException();
            }

            // Comparison of expected and actual VM's storage coin racks:
            // Check length of lists first, if different, throw the exception:
            if (storedContents.CoinsInCoinRacks.Count == expectedStoredContents.CoinsInCoinRacks.Count)
            {
                int i = 0;
                int j = 0;
                // Length is the same, check the inner lists:
                while (i < storedContents.CoinsInCoinRacks.Count)
                {
                    // Check the length of the innner lists, throw exception if different:
                    if (storedContents.CoinsInCoinRacks[i].Count == expectedStoredContents.CoinsInCoinRacks[i].Count)
                    {
                        // Compare the values of each elements in the inner lists:
                        while (j < storedContents.CoinsInCoinRacks[i].Count)
                        {
                            Assert.AreEqual(storedContents.CoinsInCoinRacks[i][j].Value, expectedStoredContents.CoinsInCoinRacks[i][j].Value);
                            j++;
                        }
                    }
                    // Length is different of the inner lists, throw the exception:
                    else
                    {
                        throw new AssertFailedException();
                    }
                    // Go to the next pair of inner lists:
                    j = 0;
                    i++;
                }
            }
            // Length of the outer lists is different, throw the exception:
            else
            {
                throw new AssertFailedException();
            }

            // Check to see if length of PopCansInPopCanRacks lists is the same:
            if (storedContents.PopCansInPopCanRacks.Count == expectedStoredContents.PopCansInPopCanRacks.Count)
            {
                int i = 0;
                int j = 0;
                // Length of outer lists is the same, check the inner lists:
                while (i < storedContents.PopCansInPopCanRacks.Count)
                {
                    // Make sure that the length of the inner lists is the same:
                    if (storedContents.PopCansInPopCanRacks[i].Count == expectedStoredContents.PopCansInPopCanRacks[i].Count)
                    {
                        // Length of the inner lists is the same, compare the name of all elements in the inner lists:
                        while (j < storedContents.PopCansInPopCanRacks[i].Count)
                        {
                            Assert.AreEqual(storedContents.PopCansInPopCanRacks[i][j].Name, expectedStoredContents.PopCansInPopCanRacks[i][j].Name);
                            j++;
                        }
                    }
                    // Length of the inner lists is different, throw the exception:
                    else
                    {
                        throw new AssertFailedException();
                    }
                    j = 0;
                    i++;
                }
            }
            // Length of the outer lists is different, throw the exception:
            else
            {
                throw new AssertFailedException();
            }
        }
Example #35
0
 static bool Prefix(VendingMachine __instance)
 {
     VendingMachineOnCustomImportFinishedPatch.PatchedOnCustomImportFinished(__instance);
     return(false);
 }
Example #36
0
        public void Test_CreditsLeftInSystemThenUsed()
        {
            int[] coinKinds = new int[4] {
                5, 10, 25, 100
            };

            int[] costs = new int[3] {
                25, 10, 25
            };
            List <int> popCosts = new List <int>(costs);

            string[] names = new string[3] {
                "Coke", "Pepsi", "FourLoco"
            };
            List <string> popNames = new List <string>(names);

            int[] coinsToLoad = new int[4] {
                0, 0, 4, 0
            };
            int[] popsToLoad = new int[3] {
                4, 1, 1,
            };



            //Mimic Test Script Calls
            var vm = new VendingMachine(coinKinds, 3, 4, 10, 10);

            VMs.Add(vm);
            new VendingMachineLogic(vm);

            VMs[0].Configure(popNames, popCosts);
            VMs[0].LoadCoins(coinsToLoad);
            VMs[0].LoadPopCans(popsToLoad);
            VMs[0].CoinSlot.AddCoin(two5);
            VMs[0].CoinSlot.AddCoin(two5);
            VMs[0].CoinSlot.AddCoin(two5);
            VMs[0].CoinSlot.AddCoin(two5);
            VMs[0].CoinSlot.AddCoin(two5);
            VMs[0].CoinSlot.AddCoin(two5);
            VMs[0].CoinSlot.AddCoin(two5);
            VMs[0].CoinSlot.AddCoin(two5);

            //First Press
            VMs[0].SelectionButtons[0].Press();


            //Get Actual Delivery and set Expected Delivery
            delivered = new List <IDeliverable>(VMs[0].DeliveryChute.RemoveItems());
            expected.Add(coke);
            expected.Add(two5);
            expected.Add(two5);
            expected.Add(two5);
            expected.Add(two5);


            //Compare Actual Delivery to Exepected Delivery
            foreach (var item in expected)
            {
                Assert.IsTrue(checker.contains(delivered, item));
                checker.remove(delivered, item);
            }

            Assert.IsTrue(delivered.Count == 0);



            //Second Press
            VMs[0].SelectionButtons[0].Press();

            //Get Actual Delivery and set Expected Delivery
            delivered = new List <IDeliverable>(VMs[0].DeliveryChute.RemoveItems());
            expected.Clear();
            expected.Add(coke);

            //Compare Actual Delivery to Exepected Delivery
            foreach (var item in expected)
            {
                Assert.IsTrue(checker.contains(delivered, item));
                checker.remove(delivered, item);
            }

            Assert.IsTrue(delivered.Count == 0);



            //Third Press
            VMs[0].SelectionButtons[0].Press();

            //Get Actual Delivery and set Expected Delivery
            delivered = new List <IDeliverable>(VMs[0].DeliveryChute.RemoveItems());
            expected.Clear();
            expected.Add(coke);

            //Compare Actual Delivery to Exepected Delivery
            foreach (var item in expected)
            {
                Assert.IsTrue(checker.contains(delivered, item));
                checker.remove(delivered, item);
            }

            Assert.IsTrue(delivered.Count == 0);



            //Fourth Press
            VMs[0].SelectionButtons[0].Press();

            //Get Actual Delivery and set Expected Delivery
            delivered = new List <IDeliverable>(VMs[0].DeliveryChute.RemoveItems());
            expected.Clear();
            expected.Add(coke);

            //Compare Actual Delivery to Exepected Delivery
            foreach (var item in expected)
            {
                Assert.IsTrue(checker.contains(delivered, item));
                checker.remove(delivered, item);
            }

            Assert.IsTrue(delivered.Count == 0);



            //Get Actual Unload
            var coinRacks = VMs[0].CoinRacks;

            foreach (var item in coinRacks)
            {
                actualUnload.CoinsInCoinRacks.Add(item.Unload());
            }

            var popCanRacks = VMs[0].PopCanRacks;

            foreach (var item in popCanRacks)
            {
                actualUnload.PopCansInPopCanRacks.Add(item.Unload());
            }

            var unload = VMs[0].StorageBin.Unload();

            foreach (var item in unload)
            {
                actualUnload.PaymentCoinsInStorageBin.Add(item);
            }

            //Set Expected Unload
            var expectedPopList = new List <PopCan>()
            {
                pepsi, fourloco
            };
            var expectedCoinsInBin = new List <Coin>()
            {
                two5, two5, two5, two5, two5, two5, two5, two5
            };

            expectedUnload.PopCansInPopCanRacks.Add(expectedPopList);
            expectedUnload.PaymentCoinsInStorageBin.AddRange(expectedCoinsInBin);

            //Compare Actual Unload with Expected Unload -- See Function Documentation for "checkUnload" in Checker.cs
            //--------------------------------------------------------------------------------------------------------
            //Remove all items from expected unload that are also in actual unload, return the difference (if any)
            unaccountedForUnload = checker.checkUnload(expectedUnload, actualUnload);

            //Assert that the difference is an empty set
            foreach (var coinList in unaccountedForUnload.CoinsInCoinRacks)
            {
                Assert.IsTrue(coinList.Count == 0);
            }

            foreach (var popList in unaccountedForUnload.PopCansInPopCanRacks)
            {
                Assert.IsTrue(popList.Count == 0);
            }

            Assert.IsTrue(unaccountedForUnload.PaymentCoinsInStorageBin.Count == 0);


            //Reset expected unload
            expectedUnload  = new VendingMachineStoredContents();
            expectedPopList = new List <PopCan>()
            {
                pepsi, fourloco
            };
            expectedCoinsInBin = new List <Coin>()
            {
                two5, two5, two5, two5, two5, two5, two5, two5
            };
            expectedUnload.PopCansInPopCanRacks.Add(expectedPopList);
            expectedUnload.PaymentCoinsInStorageBin.AddRange(expectedCoinsInBin);


            //Reverse the inputs to the function call to ensure neither expected nor actual contain different elements from eachother
            //Remove all items from actual unload that are also in expected unload, return the difference (if any)
            unaccountedForUnload = checker.checkUnload(actualUnload, expectedUnload);

            //Assert that the difference is an empty set
            foreach (var coinList in unaccountedForUnload.CoinsInCoinRacks)
            {
                Assert.IsTrue(coinList.Count == 0);
            }

            foreach (var popList in unaccountedForUnload.PopCansInPopCanRacks)
            {
                Assert.IsTrue(popList.Count == 0);
            }

            Assert.IsTrue(unaccountedForUnload.PaymentCoinsInStorageBin.Count == 0);
        }
Example #37
0
        static void PatchedOnCustomImportFinished(VendingMachine __instance)
        {
            VendingMachineOnCustomImportFinishedPatch.CallBaseCustomImportFinished(__instance);

            if (!GameManager.IsServer)
            {
                return;
            }

            if (__instance.ImportingThing)
            {
                var importing   = __instance.ImportingThing;
                var skipNewSlot = false;

                var importingStackable = __instance.ImportingThing as Stackable;
                if (importingStackable)
                {
                    foreach (Slot slot in __instance.Slots)
                    {
                        if (slot.IsInteractable)
                        {
                            continue;
                        }

                        var occupant = slot.Occupant as Stackable;
                        if (!occupant)
                        {
                            continue;
                        }

                        if (occupant.PrefabName != importingStackable.PrefabName)
                        {
                            continue;
                        }

                        OnServer.Merge(occupant, importingStackable);
                        if (importingStackable.NetworkQuantity == 0)
                        {
                            // Skip adding the now-empty item if we are empty.
                            // The empty stack was already deleted when its quantity was set to zero.
                            skipNewSlot = true;
                        }
                        else
                        {
                            // It is possible for us to not be empty, in which case a new slot should be started.
                        }

                        break;
                    }
                }

                if (!skipNewSlot)
                {
                    foreach (Slot slot in __instance.Slots)
                    {
                        if (!slot.IsInteractable && !slot.Occupant)
                        {
                            OnServer.MoveToSlot(__instance.ImportingThing, slot);
                            break;
                        }
                    }
                }
            }

            OnServer.Interact(__instance.InteractImport, 0, false);

            if (GameManager.GameState == GameState.Running && !__instance.CurrentSlot.Occupant)
            {
                __instance.PlanForward();
            }
        }
 public void Setup()
 {
     _VendingMachine = new VendingMachine();
 }
Example #39
0
 public void Setup()
 {
     _paymentProcessor = new Mock <IPaymentProcessor>();
     _vendingMachine   = new VendingMachine(_paymentProcessor.Object);
 }
 public void FindGameObjects() {
     vendingMachine = FindObjectOfType<VendingMachine>();
     pauseMenu = GameObject.Find("PauseMenuManager").GetComponent<PauseMenuScript>();
     coverSpots = FindObjectsOfType<CoverSpotScript>();
     weaponManager = FindObjectOfType<WeaponManager>();
 }
Example #41
0
        static void Main(string[] args)
        {
            // create an object
            VendingMachine myVendingMachine = new VendingMachine();

            // define one variable to store the user's answer
            // and the other one to keep track of how many times the user has put money in
            string answer;
            int    howmany = 0;

            // ask a user to enter one of several commands
            // P to pay a dollar, B to buy a Coke, R  refund to get all their money back, or Q to quit the program.
            do
            {
                Console.WriteLine("Please type P to insert a dollar, \nor B to buy a Coke, \nor R to get all your money back, \nor Q to quit this program.");
                Console.WriteLine();
                answer = Console.ReadLine().ToUpper();
                switch (answer)
                {
                case "P":
                    myVendingMachine.AcceptCash();
                    howmany++;
                    Console.WriteLine("Thank you, you now have " + string.Format("{0:c}", myVendingMachine.MoneyBalance));
                    break;

                case "B":
                    int returnValue = myVendingMachine.BuyCoke();
                    switch (returnValue)
                    {
                    case 0:
                        Console.WriteLine("Thank you for your purchase, you have {0:c} left.", myVendingMachine.MoneyBalance);
                        break;

                    case 1:
                        Console.WriteLine("Sorry, the machine is empty, enter an R to get your money back.");
                        break;

                    case 2:
                        if (howmany == 0)
                        {
                            Console.WriteLine("Sorry, you need to insert a dollar.");
                        }
                        else
                        {
                            Console.WriteLine("Sorry, you have to insert more money.");
                        }
                        break;

                    case 3:
                        Console.WriteLine("Sorry, the machine is empty, and you have no money left in the machine.");
                        break;
                    }
                    break;

                case "R":
                    int refund = myVendingMachine.GiveRefund();
                    Console.WriteLine("Here is your {0:c}", refund);
                    break;

                case "Q":
                    if (myVendingMachine.MoneyBalance != 0)
                    {
                        int refundWithouturchase = myVendingMachine.GiveRefund();
                        Console.WriteLine("Here is your {0:c}", refundWithouturchase);
                    }
                    Console.WriteLine("Thank you, have a nice day.");
                    break;
                }

                Console.WriteLine();
            } while (answer != "Q");

            Console.ReadLine();
        }
Example #42
0
 protected State(VendingMachine machine)
 {
     this.VendingMachine = machine;
 }
Example #43
0
        static void Main(string[] args)
        {
            var vendingMachine = new VendingMachine();
            var card           = new CashCard(300);

            bool run = true;

            while (run)
            {
                System.Console.Title           = " Han Wei Teo : CS Test";
                System.Console.ForegroundColor = ConsoleColor.White;
                System.Console.WriteLine("==========  Welcome To CS Vending Machine  =========");
                System.Console.WriteLine("|       Cans Avail    : {0}                        |", vendingMachine.Inventory);
                System.Console.WriteLine("|       Card Balance  : {0}                       |", card.Balance);
                System.Console.WriteLine("========      [Please Select An Option]    =========");
                System.Console.ForegroundColor = ConsoleColor.Green;
                System.Console.WriteLine("========      Press 1 - Buy Can            =========");
                System.Console.WriteLine("========      Press 2 - Top Up Card (100)  =========");
                System.Console.WriteLine("========      Press 3 - Refill Machine     =========");
                System.Console.WriteLine("========      Press 4 - Quit               =========");
                System.Console.ForegroundColor = ConsoleColor.White;
                System.Console.WriteLine("====================================================");

                var option = System.Console.ReadKey();
                switch (option.KeyChar)
                {
                case '1':
                    try
                    {
                        vendingMachine.BuyCan(card);
                        System.Console.ForegroundColor = ConsoleColor.Blue;
                        System.Console.WriteLine("=============== Vending......  ==================");
                        Thread.Sleep(500);
                    }
                    catch (InsufficientFundsException)
                    {
                        System.Console.ForegroundColor = ConsoleColor.Red;
                        System.Console.WriteLine("============= Not enough funds on card!!  ==============");
                        Thread.Sleep(500);
                    }
                    catch (VendingMachineEmptyException)
                    {
                        System.Console.ForegroundColor = ConsoleColor.Red;
                        System.Console.WriteLine("=============== Out Of Stock!! ================");
                        Thread.Sleep(500);
                    }
                    break;

                case '2':
                    card.TopUp(100);
                    System.Console.ForegroundColor = ConsoleColor.Blue;
                    System.Console.WriteLine("=============== Topping Up......  ==================");
                    Thread.Sleep(500);
                    break;

                case '3':
                    vendingMachine = new VendingMachine();
                    System.Console.ForegroundColor = ConsoleColor.Blue;
                    System.Console.WriteLine("=============== Refilling ......  ==================");
                    Thread.Sleep(500);
                    break;

                case '4':
                    run = false;
                    System.Console.ForegroundColor = ConsoleColor.Red;
                    System.Console.WriteLine("=============== Bye !!  ==================");
                    Thread.Sleep(500);
                    break;

                default:
                    break;
                }
                System.Console.Clear();
            }
        }
Example #44
0
 static void CallBaseCustomImportFinished(VendingMachine __instance)
 {
     // Cant find a way to do this from harmony, so reimplement it.
     __instance.FinishedImporting = true;
 }
        public void only_a_nickel_is_returned()
        {
            VendingMachine.InsertCoin(Coin.Nickel);

            Assert.Equal(Coin.Nickel, VendingMachine.CoinReturn().Single());
        }
Example #46
0
 public void Initialize()
 {
     test     = new VendingMachine();
     testItem = new VendingMachineItem();
 }
 public void TestInitialize()
 {
     _vendingMachine = new VendingMachine(new InMemoryProductInfoRepository());
 }