private List <T> GetNearCells <T>(BaseConsoleCell cellToRemove) where T : BaseConsoleCell { var nearCells = new List <BaseConsoleCell>(); nearCells.Add(labirint[cellToRemove.X + 1, cellToRemove.Y]); nearCells.Add(labirint[cellToRemove.X - 1, cellToRemove.Y]); nearCells.Add(labirint[cellToRemove.X, cellToRemove.Y + 1]); nearCells.Add(labirint[cellToRemove.X, cellToRemove.Y - 1]); return(nearCells.Where(cell => cell != null).OfType <T>().ToList()); }
private void TryToStepInCurrentCell(Labirint lab, BaseConsoleCell currCell) { if (currCell != null && currCell.TryToStep) { if (currCell is Coin) { lab.Cells = lab.Cells.Select(cell => cell.X == currCell.X && cell.Y == currCell.Y ? new Ground(currCell.X, currCell.Y) : cell).ToList(); } _hero.X = currCell.X; _hero.Y = currCell.Y; } }
private void GetReadyLabirint(BaseConsoleCell cell) { do { labirint[cell.X, cell.Y] = new Ground(cell.X, cell.Y); WallsToRemove.Remove(cell); var nearWalls = GetNearCells <Wall>(cell); var nearWallsNotToRemove = nearWalls.Where(wall => !CanRemove(wall)); WallsToRemove.RemoveAll(wallToRemove => nearWallsNotToRemove.Any(wallNotToRemove => wallToRemove.X == wallNotToRemove.X && wallToRemove.Y == wallNotToRemove.Y)); WallsToRemove.AddRange(nearWalls.Where(wall => CanRemove(wall))); if (WallsToRemove.Any()) { cell = GetRandomCell(WallsToRemove); } } while (WallsToRemove.Any()); }