public BoardBehavior(Board <T> board, ICellGenerator <T> cellGenerator, ICellBehavior <T> cellBehavior, Action <Dictionary <Cell <T>, Cell <T> > > updated = null) { _updated = updated; _board = board; _cellGenerator = cellGenerator; _cellBehavior = cellBehavior; }
// Vygeneruje mapu, jako parametry přijíma Maze Settings a IWinCondition, jinými slovy pravidla, jak se má mapa generovat, a podmínku pro splnění úrovně public PathfindingNode[] GenerateMaze(MazeSettingsSO mazeSettings, IWinCondition winCondition, out int nodeCount) { _mazeSettings = mazeSettings; _winCondition = winCondition; _generationsRules = _winCondition.SpecialGenerationRules(); // Vygeneruje buňky, pokud jich vygeneruje málo může generaci opakovat ICellGenerator cellGenerator = GetComponent <ICellGenerator>(); _startPoint = new Vector3(_mazeSettings.centerPoint.x - ((float)_mazeSettings.width / 2f) * _mazeSettings.distanceBetweenCells, _mazeSettings.centerPoint.y, _mazeSettings.centerPoint.z - ((float)_mazeSettings.length / 2f) * _mazeSettings.distanceBetweenCells); // RLpos int generationCounter = 0; while (generationCounter < _mazeSettings.triesToGenerateMaze) { _cellData = cellGenerator.GenerateCells(_mazeSettings, _startPoint); if ((float)_cellData.CellCount / (float)(_mazeSettings.length * _mazeSettings.width) >= _mazeSettings.minCellPercentage) { break; } generationCounter++; } // Rozdělí buňky na podbuňky ISubcellGenerator subcellGenerator = GetComponent <ISubcellGenerator>(); _subcellData = subcellGenerator.GenerateSubcells(_mazeSettings, _cellData, _startPoint, 1); // Pokud je u podmínky k zvítězení pravidlo na vedlejší místnost, tak ji vygeneruje if (_generationsRules.Contains(GenerationRule.OuterRoom)) { CreateOuterRoom(); } // Vytvoří na mapě části místností pro všechny podbuňky ITileGenerator tileGenerator = GetComponent <TileGenerator>(); tileGenerator.GenerateTiles(_subcellData, _generationsRules.Contains(GenerationRule.OuterRoom) ? (_subcellData.EmptySpotInArray - 1) : _subcellData.EmptySpotInArray); // Vytvoří vrcholy pro hledání cesty PathfindingNodeGenerator pathfindingNodeGenerator = GetComponent <PathfindingNodeGenerator>(); _pathfindingNodes = pathfindingNodeGenerator.GenerateNodes(_mazeSettings, _subcellData); GetComponent <Spawner>().SpawnReturnPortal(_subcellData.SpawnPoint); GameManager.Instance.Player.transform.position = new Vector3(_subcellData.SpawnPoint.x, _subcellData.SpawnPoint.y + _playerYOffset, _subcellData.SpawnPoint.z); SpawnEnemies(); nodeCount = _pathfindingNodes.Length; return(_pathfindingNodes); }
public Grid(Dimensions2D dimensions, ICellGenerator <T> cellGenerator) { Dimensions = dimensions; CellGenerator = cellGenerator; _elementMatrix = new Cell <T> [dimensions.Width][]; for (var x = 0; x < dimensions.Width; ++x) { _elementMatrix[x] = new Cell <T> [dimensions.Height]; } Regenerate(); }
private static void TestLeft(CommandHandler handler, Painter painter, int boadrDim, CellArray Board, ICellGenerator cellGenerator) { Board[0, 0].Value = 4; Board[1, 0].Value = 8; Board[2, 0].Value = 16; Board[3, 0].Value = 0; Board[0, 1].Value = 4; Board[1, 1].Value = 8; Board[2, 1].Value = 0; Board[3, 1].Value = 32; Board[0, 2].Value = 8; Board[1, 2].Value = 8; Board[2, 2].Value = 0; Board[3, 2].Value = 32; Board[0, 3].Value = 8; Board[1, 3].Value = 8; Board[2, 3].Value = 16; Board[3, 3].Value = 0; handler.HandleCommand(Command.Command.Right); handler.CreateNewCells(cellGenerator); Console.WriteLine(); }
public void CreateNewCells(ICellGenerator generator) { generator.Generate(Board); Painter.Draw(); }