示例#1
0
    void Update()
    {
        if (Input.GetKey("j")) // Adds 100 money if j key is pressed
        {
            _gameMoneyHandler.MoneyChange(100, true);
        }
        
        if (Input.GetKey("h")) // Subtracts 100 money if h key is pressed
        {
            _gameMoneyHandler.MoneyChange(100, false);
        }
        
        if (Input.GetKey("k")) // Increases in game time by 1 hour if k key is pressed
        {
            _gameTimeHandler.UpdateTime(1);
        }

        if (Input.GetKey("m")) // Saves the game if m key is pressed
        {
            _fileHandler.FileAction('s');
        }

        if (Input.GetKey("n")) // Loads a save game if n key is pressed 
        {
            _fileHandler.FileAction('l');
        }
        
    }
示例#2
0
    // Gets called when the sell button in the sell menu is pressed
    // Takes the items from the menu and then resolve what was sold and what actions should be taken
    public void ResolveSell(GameObject menu)
    {
        string locationId = FindLocationIdOfCurrentLocation();

        int[] rowChildIndex = FindRowsWithinMenu(menu);

        // Goes through each row in the menu
        for (int i = 0; i < rowChildIndex.Length; i++)
        {
            GameObject tempRow              = menu.transform.GetChild(rowChildIndex[i]).gameObject;
            string[]   rowElements          = ReadRow(tempRow);
            string     itemName             = rowElements[0];
            float      itemPrice            = float.Parse(rowElements[1]);
            int        itemStockInInventory = int.Parse(rowElements[2]);
            int        itemToSell           = 0;
            string     currentProductId     = FindProductIdOfInputString(itemName);

            // If the input field was empty then itemToSell is assigned 0
            // if it wasn't empty then it takes whatever value was in it
            itemToSell = rowElements[3] == "" ? 0 : int.Parse(rowElements[3]);

            // Checks to make sure that certain conditions are met before activating the sell
            if (itemToSell < 0) // if the number of items to sell is negative then an error message is displayed
            {
                _errorGui.enabled      = true;
                _errorGui.errorMessage = "To Sell is negative";
            }
            else if (itemToSell > itemStockInInventory) // If there are more items to sell than in inventory an error message is displayed
            {
                _errorGui.enabled      = true;
                _errorGui.errorMessage = "Not enough stock in inventory";
            }
            else if (itemToSell == 0) // If the items to sell was 0 then it is skipped
            {
            }
            else // If it passes all the conditions then the correct changes are made
            {
                // The revenue is calculated, so is the new amount of stock that is to be inputed
                int revenue = Convert.ToInt32(Math.Round(itemToSell * itemPrice));
                itemStockInInventory -= itemToSell;

                // The data displayed on the rows are updated and the input field are wiped
                WriteRow(tempRow, itemName, itemPrice, itemStockInInventory);
                WipeInput(tempRow);

                // The money increases by the revenue value
                _gameMoneyHandler.MoneyChange(revenue, true);

                // The stock changes in PlayerInventory and the change is recorded in the Changes table
                _dataBaseConnector.DataBasePlayerInventoryInput(int.Parse(locationId), itemPrice, itemToSell, true, true);
                _dataBaseConnector.DataBaseProductChangesInsert(int.Parse(currentProductId), int.Parse(locationId), itemPrice, itemToSell);
            }

            // The Input field in the row is wiped weather or not the sale succeeds
            WipeInput(tempRow);
        }
    }