Ejemplo n.º 1
0
        /// <summary>
        /// Converts BoardTile list to multidimensional array
        /// </summary>
        /// <returns></returns>
        public BoardTile[,] ConvertTo2DArray()
        {
            List <BoardTile> boardTilesList = BoardTiles.ToList();
            int indexOfLastBoardTile        = boardTilesList.Count - 1;

            BoardTile[,] array = new BoardTile[boardTilesList[indexOfLastBoardTile].BoardLocationX + 1, boardTilesList[indexOfLastBoardTile].BoardLocationY + 1];
            foreach (var boardTile in boardTilesList)
            {
                array[boardTile.BoardLocationX, boardTile.BoardLocationY] = boardTile;
            }
            return(array);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Transposes an array (turns rows to columns and columns to rows).
        /// </summary>
        /// <param name="boardArray">Original untransposed array.</param>
        /// <returns></returns>
        public BoardTile[,] Transpose2DArray(BoardTile[,] boardArray)
        {
            int w = boardArray.GetLength(0);
            int h = boardArray.GetLength(1);

            BoardTile[,] result = new BoardTile[h, w];

            for (int i = 0; i < w; i++)
            {
                for (int j = 0; j < h; j++)
                {
                    result[j, i] = boardArray[i, j];
                }
            }

            return(result);
        }