示例#1
0
        private void BuyProduct(int slot)
        {
            int column = slot % 10 - 1;
            int row    = slot / 10 - 1;

            if (row < 0 || row > _shelve.GetUpperBound(0) ||
                column < 0 || column > _shelve.GetUpperBound(1))
            {
                _displayScreen.DisplayMessage("Please enter a valid product number.");
                return;
            }

            var item = _shelve[row, column];

            if (item == null)
            {
                _displayScreen.DisplayMessage("Empty slot. Please make a new selection.");
                return;
            }

            if (item.Price > _userAmount)
            {
                _displayScreen.DisplayMessage($"Not enough balance to buy the item {item.ItemName}");
                return;
            }

            _displayScreen.DisplayMessage($"Transaction successful. Please collect the item.");
            _displayScreen.DisplayMessage($"Item Details: {item.DisplayMessage()}");
            _userAmount         -= _shelve[row, column].Price;
            _shelve[row, column] = null;
            Thread.Sleep(2000);
        }
示例#2
0
    // Shuffle board using Fisher-Yates algorithm
    public void ShuffleBoard(System.Random random)
    {
        // Get 2d array dimensions
        int num_rows  = _items.GetUpperBound(0) + 1;
        int num_cols  = _items.GetUpperBound(1) + 1;
        int num_cells = num_rows * num_cols;

        // Randomize the array.
        for (int i = 0; i < num_cells - 1; i++)
        {
            // Pick a random cell between i and the end of the array
            int j = random.Next(i, num_cells);

            // Convert to row/column indexes
            int row_i = i / num_cols;
            int col_i = i % num_cols;
            int row_j = j / num_cols;
            int col_j = j % num_cols;

            // Swap cells i and j
            Item temp = _items[row_i, col_i];
            _items[row_i, col_i] = _items[row_j, col_j];
            _items[row_j, col_j] = temp;
            SwapIndices(_items[row_i, col_i], _items[row_j, col_j]);
            RepositionItems(); // Reposition all items gameObject positions with the new ones
        }
    }
示例#3
0
 //product display
 public void DisplayMessage(Item[,] items)
 {
     for (int i = 0; i <= items.GetUpperBound(0); i++)
     {
         for (int j = 0; j <= items.GetUpperBound(1); j++)
         {
             if (items[i, j] != null)
             {
                 Console.Write($"|{i+1}{j+1} {items[i, j].ItemName,10} ${items[i, j].Price}|\t");
             }
             else
             {
                 Console.Write($"|{i+1}{j+1} ---Empty---|\t");
             }
         }
         Console.WriteLine("\n------------------------------------------------------------------------------------------");
     }
 }