Пример #1
0
        private (int[, ] map, Point?lootCoord) CreateStepsMapToClosestLootBox(WorldActivityCalculator worldCalculator)
        {
            //worldCalculator = new WorldActivityCalculator(startMap);

            CurrentMap = worldCalculator.currentMap;
            stepsMap   = new int[CurrentMap.Size.X, CurrentMap.Size.Y];
            int stepCount = 1;

            stepsMap[CurrentMap.PlayerPosition.X, CurrentMap.PlayerPosition.Y] = 1;

            Point?findedLootBoxCoordinate = null;
            var   lastStepVisitedCells    = new List <Point>()
            {
                CurrentMap.PlayerPosition
            };

            while (lastStepVisitedCells.Count > 0 && findedLootBoxCoordinate == null)
            {
                worldCalculator.Tick();
                stepCount++;
                var currentStepVisitedCells = new List <Point>();
                for (int i = 0; i < lastStepVisitedCells.Count; i++)
                {
                    var visitedCellCoord = lastStepVisitedCells[i];
                    for (var dx = -1; dx < 2; dx++)
                    {
                        for (var dy = -1; dy < 2; dy++)
                        {
                            var currentCellCoord = new Point(visitedCellCoord.X + dx, visitedCellCoord.Y + dy);

                            if (dx * dy != 0 || !CurrentMap.Contains(currentCellCoord))
                            {
                                continue;
                            }

                            var currentCellValue = CurrentMap.Cells[currentCellCoord.X, currentCellCoord.Y];

                            if (stepsMap[currentCellCoord.X, currentCellCoord.Y] == 0)
                            {
                                if (currentCellValue == MapCell.LootBox)
                                {
                                    findedLootBoxCoordinate = currentCellCoord;
                                }

                                if (Map.IsCellPassable(currentCellValue))
                                {
                                    currentStepVisitedCells.Add(currentCellCoord);
                                    stepsMap[currentCellCoord.X, currentCellCoord.Y] = stepCount;
                                }
                            }
                        }
                    }
                }

                lastStepVisitedCells = currentStepVisitedCells;
            }
            return(stepsMap, findedLootBoxCoordinate);
        }
Пример #2
0
 public void Initialize()
 {
     worldCalculator   = new WorldActivityCalculator(map);
     this.map          = worldCalculator.currentMap;
     playerPathManager = new PathManager(map);
     playerPathManager.FindPathToClosestLootBox();
     AcceptGameInfo?.Invoke
         (new GameInfoLog(playerPathManager.GetCoordinatePath(), map.GetLootCoordinates(), map.PlayerPosition));
 }
Пример #3
0
        public void FindPathToClosestLootBox()
        {
            worldCalculator = new WorldActivityCalculator(startMap);
            CurrentMap      = worldCalculator.currentMap;

            Point?lootCoord = null;

            int[,] stepsMap;
            var cellsOrderOfPath = new List <Point>()
            {
                CurrentMap.PlayerPosition
            };

            (stepsMap, lootCoord) = CreateStepsMapToClosestLootBox(worldCalculator);
            while (lootCoord != null)
            {
                CurrentMap.ChangePlayerPosition(lootCoord.Value);
                var swapList = cellsOrderOfPath;
                cellsOrderOfPath = TryToCreateCellsPathFromStepsMap(stepsMap, lootCoord);
                cellsOrderOfPath.RemoveAt(cellsOrderOfPath.Count - 1);
                cellsOrderOfPath.AddRange(swapList);
                (stepsMap, lootCoord) = CreateStepsMapToClosestLootBox(worldCalculator);
            }

            //TryToCreateCellsPathFromStepsMap(stepsMap, lootCoord);  // изменить координату игрока и убрать loot box перед след поиском return path;

            if (cellsOrderOfPath != null && cellsOrderOfPath.Count > 2)
            {
                var previousCell = cellsOrderOfPath[0];
                for (int i = 1; i < cellsOrderOfPath.Count; i++)
                {
                    var currentCell = cellsOrderOfPath[i];
                    path.Push(Map.GetDiretionByPoints(currentCell, previousCell));
                    previousCell = currentCell;
                }
            }
        }