public void SetCell(int x, int y, Cell cell) { if (x >= Cells.GetLength(0) && y >= Cells.GetLength(1)) throw new IndexOutOfRangeException(string.Format("Ячейка в позиции {0},{1} не найдена", x, y)); Cells[x, y] = cell; }
private Cell[,] GetCells(int x, int y, int width, int height) { if (x + width <= Cells.GetLength(0) && y + height <= Cells.GetLength(1)) { Cell[,] temp = new Cell[width, height]; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { temp[i, j] = Cells[x + i, y + j]; } } return temp; } throw new IndexOutOfRangeException(string.Format("Заданное поле выходит за пределы слоя")); }
private Cell[,] CreateLayerModelfromBitmap(Bitmap bmp, Dictionary<string, byte> mapInfo) { var cells = new Cell[bmp.Width, bmp.Height]; for (int i = 0; i < bmp.Width; i++) { for (int j = 0; j < bmp.Height; j++) { Color color = bmp.GetPixel(i, j); string strCol = string.Format("#FF{0:X2}{1:X2}{2:X2}", color.R, color.G, color.B).ToUpper(); if(mapInfo.ContainsKey(strCol)) { cells[i, j] = new Cell(mapInfo[strCol]); } else { cells[i, j] = new Cell(0x00); } } } return cells; }