public VendingMachine(int inventory, dynamic price)
 {
     canRack       = new CanRack(inventory);
     purchasePrice = new PurchasePrice(price);
     trxBox        = new CoinBox();
     box           = new CoinBox();
 }
        private void RefreshCoinBoxListView(CoinBox coinBoxToRead, ListView listViewToRefresh)
        {
            //First clear out the old listView entries
            listViewToRefresh.Items.Clear();

            //Loop through each type of coin and add it to the listview
            foreach (Coin.Denomination aCoin in Coin.AllDenominations)
            {
                //Special case to skip SLUGs
                if (aCoin == Coin.Denomination.SLUG)
                {
                    continue;
                }

                //Create a row item and add two columns to it
                ListViewItem lviRow = new ListViewItem(aCoin.ToString());
                lviRow.SubItems.Add($"{coinBoxToRead.coinCount(aCoin)}");
                lviRow.SubItems.Add($"{(Coin.ValueOfCoin(aCoin) * coinBoxToRead.coinCount(aCoin)).ToString("C")}");

                //Add the row item to the listview
                listViewToRefresh.Items.Add(lviRow);
            }

            //Create a TOTAL row to show the total amount of coins in the coin box
            ListViewItem lviTotalRow = new ListViewItem("TOTAL");

            lviTotalRow.Font = new Font(lviTotalRow.Font, lviTotalRow.Font.Style | FontStyle.Bold);
            lviTotalRow.SubItems.Add($"");
            lviTotalRow.SubItems.Add($"{coinBoxToRead.ValueOf.ToString("C")}");
            listViewToRefresh.Items.Add(lviTotalRow);

            //After pulling data in, set to auto resize
            listViewToRefresh.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
            listViewToRefresh.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
        }
Beispiel #3
0
        public Machine(ProductBox prodcutBox, CoinBox rBox, CoinBox sBox, IMessenger messenger)
        {
            this._pBox = prodcutBox;
            this._rBox = rBox;
            this._sBox = sBox;
            this._msg = messenger;

            this._status = MachineStatus.Init;
        }
 public VendingMachineViewModel(int inventory, dynamic price)
 {
     canRack         = new CanRack(inventory);
     purchasePrice   = new PurchasePrice(price);
     trxBox          = new CoinBox();
     box             = new CoinBox();
     canPriceMessage = $"Please deposit {(this.purchasePrice.Price * .01).ToString("C2")}";
     MainTitle       = "WPF Vending Machine - Assignment 6";
     canMakeChange   = true;
 }
Beispiel #5
0
    private void Start()
    {
        characterList       = new List <GameObject>();
        appointedCharacters = 0;
        CreateQuestList();     //Skapar listan av alla valbara quests
        CreateCharacterList(); //Skapar listan av alla karaktärer som kan gå på mission
        CheckMissionReady();

        CoinBox = GameObject.FindGameObjectWithTag("CoinBox");
        CoinBox.SetActive(false);
    }
        public VendingMachineViewModel()
        {
            Vm            = vm;
            canMakeChange = true;
            SelectedCoins = new ObservableCollection <Coin>();

            // Represent financial institution - seed it with 20 random coins
            Bank = new CoinBox();
            foreach (var c in CoinBox.GenerateRandomCoins(20))
            {
                Bank.Deposit(c);
            }
        }
    private void UICharacters()
    {
        hubCharacters     = GameObject.FindGameObjectsWithTag("Character");
        forHospitalParent = GameObject.Find("forHospital");
        forHealingParent  = GameObject.Find("forHealingSlots");
        CoinBox           = GameObject.FindGameObjectWithTag("CoinBox");

        CoinBox.SetActive(false);
        showCharacter = false;


        foreach (GameObject character in hubCharacters)    //Går igenom alla karaktärer
        {
            statsScript = character.GetComponent <Stats>();

            if (statsScript.hp <= statsScript.maxHp)   //För att bara få de skadade karaktärena
            {
                showCharacter = true;
            }
            else
            {
                foreach (QuirkObject quirk in statsScript.quirkList)    //Går in i alla quirks för att se om karaktären är skadad
                {
                    if (quirk.quirkType == QuirkScript.QuirkType.woundQuirk)
                    {
                        showCharacter = true;
                        break;
                    }
                }
            }
            if (showCharacter)      //Om karaktären har mindre hp än max eller har en woundQuirk kommer den att ritas us i hospital
            {
                hubCharacterScript = character.GetComponent <CharacterScript>();

                UIHolder = Instantiate(UIHospital);

                UIHolder.GetComponent <CharacterScript>().LoadPlayer(hubCharacterScript);
                UIHolder.GetComponent <Stats>().LoadPlayer(statsScript);
                UIHolder.GetComponent <UIHospitalBoi>().Hospital = gameObject;

                if (UIHolder.GetComponent <CharacterScript>().inHospital)
                {
                    UIHolder.transform.SetParent(forHealingParent.transform, false);
                }
                else
                {
                    UIHolder.transform.SetParent(forHospitalParent.transform, false);
                }
            }
        }
    }
    public void Exit()
    {
        hospitalCharacters = GameObject.FindGameObjectsWithTag("UIHospitalCharacter"); //Tar fram alla som är i hospital
        foreach (GameObject hospitalCharacter in hospitalCharacters)                   //Kollar alla i hospital
        {
            hospitalCharacterScript = hospitalCharacter.GetComponent <CharacterScript>();

            foreach (GameObject hubCharacter in hubCharacters)   //Kollar alla karaktärer i hubben
            {
                hubCharacterScript = hubCharacter.GetComponent <CharacterScript>();

                if (hospitalCharacterScript.id == hubCharacterScript.id)   //Samma boi
                {
                    hubCharacterScript.LoadPlayer(hospitalCharacterScript);
                    break;
                }
            }
        }
        CoinBox.SetActive(true);
        Destroy(gameObject);
    }
Beispiel #9
0
        public void IsEmptyTest()
        {
            /// ProductBox
            ProductBox pBox = new ProductBox("temp product box", 40, 20);

            Assert.IsTrue(pBox.IsEmpty);

            string productName = Guid.NewGuid().ToString();
            int productPrice = Guid.NewGuid().GetHashCode();

            pBox.AddProduct(new Product(productName, productPrice), 0);
            Assert.IsTrue(pBox.IsEmpty);

            Assert.AreEqual(0, pBox[new Product(productName, productPrice)]);

            pBox.AddProduct(new Product(productName, productPrice), 10);
            Assert.IsFalse(pBox.IsEmpty);
            Assert.AreEqual(10, pBox[new Product(productName, productPrice)]);

            /// CoinBox
            CoinBox cBox = new CoinBox("temp coin box");
            Assert.IsTrue(cBox.IsEmpty);

            cBox.AddCoins(new Coin(1), 0);
            Assert.IsTrue(cBox.IsEmpty);
            cBox.AddCoins(new Coin(2), 0);
            Assert.IsTrue(cBox.IsEmpty);
            cBox.AddCoins(new Coin(5), 0);
            Assert.IsTrue(cBox.IsEmpty);

            cBox.AddCoins(new Coin(1), 1);
            Assert.IsFalse(cBox.IsEmpty);

            cBox.Clear();
            Assert.IsTrue(cBox.IsEmpty);
        }
Beispiel #10
0
        private void constructCoinBoxDisplay(ListView CoinBoxDisplay, CoinBox CoinBoxToDisplay)
        {
            CoinBoxDisplay.Items.Clear();
            List <Coin.Denomination> reverseCoinList = new List <Coin.Denomination>(Coin.AllDenominations);

            reverseCoinList.Reverse();

            foreach (Coin.Denomination coinDenomination in reverseCoinList)
            {
                int          coinCount  = CoinBoxToDisplay.coinCount(coinDenomination);
                decimal      coinsValue = coinCount * Coin.ValueOfCoin(coinDenomination);
                ListViewItem coinRow    = new ListViewItem(coinDenomination.ToString());
                coinRow.SubItems.Add(coinCount.ToString());
                coinRow.SubItems.Add(string.Format("{0:c}", coinsValue));
                CoinBoxDisplay.Items.Add(coinRow);
            }

            ListViewItem totalRow = new ListViewItem("Total");

            totalRow.SubItems.Add(string.Empty);
            totalRow.SubItems.Add(string.Format("{0:c}",
                                                CoinBoxToDisplay.ValueOf));
            CoinBoxDisplay.Items.Add(totalRow);
        }
Beispiel #11
0
        private void ReturnChanges(CoinBox changes)
        {
            if (changes == null)
                throw new ArgumentNullException("changes");

            if (_msg != null)
            {
                if (changes.IsEmpty)
                {
                    _msg.Show("No changes.");
                }
                else
                {
                    _msg.Show(string.Format("Changes: {0}", changes));
                }
            }

            _rBox.Clear();
        }
Beispiel #12
0
        private CoinBox MakeChangesCore(int changesValue)
        {
            CoinBox totalCoins = _sBox + _rBox;

            CoinBox changes = new CoinBox("changes");

            int temp = changesValue;
            foreach (var coin in totalCoins.OrderByCoinValue(true))
            {
                if (temp == 0)
                    break;

                while (temp > 0)
                {
                    if (coin.Key.Value > temp || coin.Value == 0)
                        break;

                    totalCoins.RemoveCoins(coin.Key, 1);
                    changes.AddCoins(coin.Key, 1);

                    temp -= coin.Key.Value;

                    if (temp == 0)
                        break;
                }
            }

            if (temp != 0)
            {
                /// not enough coins to make changes
                return null;
            }
            else
            {
                /// changes has made

                _sBox = totalCoins;

                return changes;
            }
        }
Beispiel #13
0
        public void Start()
        {
            if (_pBox == null || _pBox.IsEmpty)
            {
                this._status = MachineStatus.OutOfOrder;
                if (_msg != null)
                    _msg.Show("Mahince is out of order.");

                return;
            }

            if (_sBox == null || _sBox.IsEmpty)
            {
                this._status = MachineStatus.OutOfOrder;

                if (_msg != null)
                    _msg.Show("Mahince is out of order.");

                return;
            }

            if (_rBox == null)
                _rBox = new CoinBox(ReceiveCoinBox);
            _rBox.Clear();

            if (_msg != null)
                _msg.Show("Mahince has started.");

            this._status = MachineStatus.Running;

            if (_msg != null)
                _msg.Show("Mahince is running.");
        }
Beispiel #14
0
        public void InsertCoin(Coin coin)
        {
            if (_status != MachineStatus.Running)
                throw new Exception("The machine is not running.");

            if (_rBox == null) _rBox = new CoinBox(ReceiveCoinBox);

            _rBox.AddCoins(coin, 1);

            _msg.Show(string.Format("Coin {0} has inserted.", coin));
        }
Beispiel #15
0
        public void TestInit()
        {
            pBox = new ProductBox("products", 40, 20); // name, typs of products, capacity of each product

            pBox.AddProduct(water, 20); // product, count
            pBox.AddProduct(soda, 20);
            pBox.AddProduct(cola, 20);

            ///  100 x 1p, 50 x 5p, 50 x 10p
            sBox = new CoinBox(Machine.StoreCoinBox);
            sBox.AddCoins(one, 100); // coin, count
            sBox.AddCoins(five, 50);
            sBox.AddCoins(ten, 50);

            rBox = new CoinBox(Machine.ReceiveCoinBox);
            rBox.Clear();

            machine = new TestMachine(pBox, rBox, sBox, TestMessenger.Default);

            machine.Start();
        }
Beispiel #16
0
 public TestMachine(ProductBox pBox, CoinBox rBox, CoinBox sBox, TestMessenger messenger)
     : base(pBox, rBox, sBox, messenger)
 {
 }