//internal CMap(MapRepresent_ProD representMap) //{ // colCount = representMap.ColCount; // rowCount = representMap.RowCount; // mx = new CCell[colCount, rowCount]; // for (int i = 0; i < colCount; i++) // for (int j = 0; j < rowCount; j++) // { // var cell = new CCell(i, j, representMap[i, j]); // mx[i, j] = cell; // if (cell.IsWall) wall.Add(cell); // else // switch (cell.Type) // { // case CellType.Entrance: // entranceCell = cell; // break; // case CellType.Exit: // exitCell = cell; // break; // case CellType.Door: // doorCells.Add(cell); // break; // } // } //} internal CMap(CellType[,] cellMatrix) { colCount = cellMatrix.GetLength(0); rowCount = cellMatrix.GetLength(1); mx = new CCell[colCount, rowCount]; for (int i = 0; i < colCount; i++) for (int j = 0; j < rowCount; j++) { var cell = new CCell(i, j, cellMatrix[i, j]); mx[i, j] = cell; if (cell.IsWall) wall.Add(cell); else switch (cell.Type) { case CellType.Entrance: entranceCell = cell; break; case CellType.Exit: exitCell = cell; break; case CellType.Door: doorCells.Add(cell); break; } } }
private void FindAdjacentCell(CCell cell, List<CCell> adjancentCells) { var near = GetNear(cell); byte sideN = 1; foreach (var c in near) { if (c != null) { if (c.flag) { c.flag = false; adjancentCells.Add(c); if (cell != c) FindAdjacentCell(c, adjancentCells); } } else cell.AddSide(sideN); sideN++; } }
private CCell[,] GetNear(CCell cell) { var cells = new CCell[3, 3]; int x = cell.x; int y = cell.y; int col = 0; for (int i = x - 1; i <= x + 1; i++) { int row = 0; for (int j = y - 1; j <= y + 1; j++) { if (i >= 0 && j >= 0 && i < colCount && j < rowCount) { var c = mx[i, j]; if (c.IsWall && (isDiagonal || col == 1 || row == 1)) cells[col, row] = c; } row++; } col++; } return cells; }
internal bool IsAdjacentWith(CCell cell) { return Math.Abs(x - cell.x) <= 1 && Math.Abs(y - cell.y) <= 1; }