Exemplo n.º 1
0
        public Map(int columns, int rows, MapCellInitializer initializer)
        {
            if (initializer == default)
            {
                throw new ArgumentNullException(nameof(initializer));
            }

            if (columns <= 0)
            {
                throw new ArgumentException("Columns cannot be <= 0", nameof(columns));
            }

            if (rows <= 0)
            {
                throw new ArgumentException("Rows cannot be <= 0", nameof(rows));
            }

            _rowSize = columns;

            Columns     = columns;
            HalfColumns = columns / 2;
            Rows        = rows;
            HalfRows    = rows / 2;
            _cells      = new MapCell[columns * rows];

            for (int row = 0; row < rows; row++)
            {
                for (int column = 0; column < columns; column++)
                {
                    int         index = (row * _rowSize) + column;
                    ref MapCell cell  = ref _cells[index];
                    cell.Column = (short)column;
                    cell.Row    = (short)row;
                    cell.Index  = index;

                    initializer(ref cell);
                }
            }
Exemplo n.º 2
0
 IMap IMapFactory.Create(int columns, int rows, MapCellInitializer initializer)
 {
     return(new Map(columns, rows, initializer));
 }