Exemple #1
0
        /// <summary>
        /// Gets all army and bonus items from board and puts them to arrays given as arguments.
        /// Assuming that all blocks have the same size.
        /// Blocks and out arrays are 1-indexed.
        /// </summary>
        public void ConvertToArrays(out BoardStorageItem[,] items, out BoardStorageItem[,] bonusItems)
        {
            //Blocks have the same size, so take this size of the first block
            var blockWidth  = blocks[1, 1].GetBoardWidth();
            var blockHeight = blocks[1, 1].GetBoardHeight();

            //Create global arrays
            items      = new BoardStorageItem[width * blockWidth + 1, height *blockHeight + 1];
            bonusItems = new BoardStorageItem[width * blockWidth + 1, height *blockHeight + 1];

            //Enumerate all blocks, calculate the corresponding segment in the global arrays and copy items to it.
            for (var col = 1; col <= width; col++)
            {
                for (var row = 1; row <= height; row++)
                {
                    var fromX = (col - 1) * blockWidth + 1;
                    var fromY = (row - 1) * blockHeight + 1;
                    for (var blockCol = 1; blockCol <= blockWidth; blockCol++)
                    {
                        for (var blockRow = 1; blockRow <= blockHeight; blockRow++)
                        {
                            items[fromX + blockCol - 1, fromY + blockRow - 1] =
                                blocks[col, row].GetItem(blockCol, blockRow);
                            bonusItems[fromX + blockCol - 1, fromY + blockRow - 1] =
                                blocks[col, row].GetBonusItem(blockCol, blockRow);
                        }
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Sets army item by cell.
        /// </summary>
        public void SetItem(Cell cell, BoardStorageItem item)
        {
            //Find the block that contains the given cell.
            var blockWithCell =
                (from SingleBoardStorage block in blocks
                 where block != null && block.ContainsCell(cell)
                 select block)
                .FirstOrDefault();

            blockWithCell?.SetItem(cell, item);
        }
        private void SetItem(int positionX, int positionY, BoardStorageItem item, BoardStorageItem[,] table)
        {
            table[positionX, positionY] = item;
            var targetButton = GetBoardButton(positionX, positionY);

            if (item != null && table[positionX, positionY].StoredObject != null)
            {
                table[positionX, positionY].StoredObject.transform.position =
                    targetButton.transform.position;
            }
        }
 /// <summary>
 /// Fills given arrays from storing table
 /// </summary>
 /// <param name="items"> Fills from table with army items </param>
 /// <param name="bonusItems"> Fills from table with bonus items </param>
 public void ConvertToArrays(out BoardStorageItem[,] items, out BoardStorageItem[,] bonusItems)
 {
     items      = new BoardStorageItem[width + 1, height + 1];
     bonusItems = new BoardStorageItem[width + 1, height + 1];
     for (var col = 1; col <= width; col++)
     {
         for (var row = 1; row <= height; row++)
         {
             items[col, row]      = boardTable[col, row];
             bonusItems[col, row] = bonusItems[col, row];
         }
     }
 }
Exemple #5
0
 /// <summary>
 /// Sets an item by the given position in the current block.
 /// </summary>
 public void SetItem(IntVector2 position, BoardStorageItem item)
 {
     currentBlock.SetItem(position, item);
 }
Exemple #6
0
 /// <summary>
 /// Sets an item by the given position in the current block.
 /// </summary>
 public void SetItem(int col, int row, BoardStorageItem item)
 {
     SetItem(new IntVector2(col, row), item);
 }
 /// <summary>
 /// Creates tables of army and bonus layers for the whole board.
 /// Tables are 1-indexed.
 /// </summary>
 private void CreateGlobalTables(out BoardStorageItem[,] boardTable, out BoardStorageItem[,] bonusTable)
 {
     boardTable = new BoardStorageItem[blockWidth * blocksHorizontal + 1, blockHeight *blocksVertical + 1];
     bonusTable = new BoardStorageItem[blockWidth * blocksHorizontal + 1, blockHeight *blocksVertical + 1];
 }
 /// <summary>
 /// Sets item to table with army items by cell
 /// </summary>
 public void SetItem(Cell cell, BoardStorageItem item)
 {
     SetItem(indexByCell[cell], item);
 }
 /// <summary>
 /// Sets item to table with army items by given position
 /// </summary>
 public void SetItem(IntVector2 position, BoardStorageItem item)
 {
     SetItem(position.x, position.y, item);
 }
 /// <summary>
 /// Sets item to table with bonus items by given position
 /// </summary>
 public void SetBonusItem(int positionX, int positionY, BoardStorageItem item)
 {
     SetItem(positionX, positionY, item, bonusTable);
 }