コード例 #1
0
ファイル: Playfield.cs プロジェクト: huuuskyyy/Teamworks
        /// <summary>
        /// Two-dimensional playfield array is cloned as zero-based array for the needs of XML serialization.
        /// XML Serializator cannot serialize multi-dimensional arrays. 
        /// XML Serializator cannot work with interfaces, that's why is used Cell.cs, but not ICell interface
        /// </summary>
        /// <param name="fieldToCopy"></param>
        /// <returns></returns>
        private Cell[] CloneToZeroBasedArray(Cell[,] fieldToCopy)
        {
            int backupArrayLength = fieldToCopy.GetLength(0) * fieldToCopy.GetLength(0);

            Cell[] copy = new Cell[backupArrayLength];

            int index = 0;
            foreach (Cell item in this)
            {
                copy[index] = item.Clone() as Cell;
                index++;
            }

            return copy;
        }
コード例 #2
0
ファイル: Playfield.cs プロジェクト: huuuskyyy/Teamworks
        /// <summary>
        /// Restores the multidimensional array from the zero-based one comming from the serialization.
        /// </summary>
        /// <param name="zeroBasedArray"></param>
        /// <param name="fieldDimensions"></param>
        /// <returns></returns>
        private Cell[,] CloneToMultiDimArray(Cell[] zeroBasedArray, int fieldDimensions)
        {
            Cell[,] copy = new Cell[fieldDimensions, fieldDimensions];
            int index = 0;

            for (int i = 0; i < fieldDimensions; i++)
            {
                for (int j = 0; j < fieldDimensions; j++)
                {
                    copy[i, j] = zeroBasedArray[index].Clone() as Cell;
                    index++;
                }
            }

            return copy;
        }