Пример #1
0
 public CachedPathFinder(HexagonManager hexagonManager, StructureManager structureManager, GameplaySettings gameplaySettings)
 {
     PathFinding      = new PathFinding <HexagonNode, float>((i, j) => i + j, h => h.GetAccessibleAdjacentHexagonNodes(HexagonManager).Where(a => StructureManager[a] != null), CalculateHeuristik, (c, n) => gameplaySettings.DefaultResourceTimeBetweenNodes);
     HexagonManager   = hexagonManager;
     StructureManager = structureManager;
     GameplaySettings = gameplaySettings;
     StructureManager.StructureAdded   += StructureAdded;
     StructureManager.StructureRemoved += StructureRemoved;
 }
Пример #2
0
        public void Update(float dt)
        {
            if (!IsInitialized || IsStopped)
            {
                return;
            }
            var gameSpeed = (float)GameSpeed / 10;

            dt *= gameSpeed;
            HexagonManager.Update(dt);
            ResourceManager.Update(dt);
            StructureManager.Update(dt);
        }
Пример #3
0
 public World(GameSettings gameSettings)
 {
     GameSettings                        = gameSettings;
     StructureManager                    = new StructureManager();
     GlobalResourceManager               = new GlobalResourceManager(GameSettings.GameplaySettings);
     HexagonManager                      = new HexagonManager(GameSettings.GameplaySettings);
     ButtonManager                       = new ButtonManager(GameSettings.LayoutSettings);
     UnlockManager                       = new UnlockManager(GlobalResourceManager, gameSettings.BuildingDescriptionDatabase);
     PathFinder                          = new CachedPathFinder(HexagonManager, StructureManager, GameSettings.GameplaySettings);
     ResourceManager                     = new ResourceManager(this);
     StructureManager.StructureAdded    += StructureAdded;
     StructureManager.StructureRemoved  += StructureRemoved;
     GlobalResourceManager.OutOfOxygen  += grm => OnDefeat();
     GlobalResourceManager.ValueChanged += CheckWinCondition;
 }
Пример #4
0
        public IEnumerable <HexagonNode> GetAccessibleAdjacentHexagonNodes(HexagonManager hexagonManager)
        {
            var hexPos   = new[] { Position1, Position2, Position3 };
            var adjacent = GetAdjacentHexagonNodes();

            foreach (var hexagonNode in adjacent)
            {
                var otherPos         = new[] { hexagonNode.Position1, hexagonNode.Position2, hexagonNode.Position3 };
                var hexagonPositions = hexPos.Intersect(otherPos).ToArray();
                if (hexagonManager.CanReachThrough(hexagonPositions[0], hexagonPositions[1]))
                {
                    yield return(hexagonNode);
                }
            }
        }
Пример #5
0
        public void Initialize()
        {
            var p1 = HexagonPosition.Zero;
            var p2 = new HexagonPosition(0, 1, -1);
            var p3 = new HexagonPosition(1, 0, -1);

            HexagonManager.RevealHexagonAt(p1);
            HexagonManager.RevealHexagonAt(p2);
            HexagonManager.RevealHexagonAt(p3);

            StructureManager.CreateStrucuture(new Building(new HexagonNode(p1, p2, p3), this, GameSettings.BuildingDescriptionDatabase.ByNameKey("diamondExtractorName")));
            StructureManager.CreateStrucuture(new Building(new HexagonNode(new HexagonPosition(1, 1, -2), p2, p3), this, GameSettings.BuildingDescriptionDatabase.ByNameKey("haborName")));
            StructureManager.CreateStrucuture(new Building(new HexagonNode(new HexagonPosition(1, 1, -2), new HexagonPosition(2, 0, -2), p3), this, GameSettings.BuildingDescriptionDatabase.ByNameKey("coalPowerPlantName")));

            IsInitialized = true;
        }
Пример #6
0
        private void StructureAdded(StructureManager manager, Structure structure)
        {
            if (ButtonManager[structure.Position] != null)
            {
                ButtonManager.RemoveButton(ButtonManager[structure.Position]);
            }
            ButtonManager.AddButton(new StructureButton(GameSettings, structure), structure.Position);
            if (!(structure is Construction))
            {
                foreach (var adjacentHexagonNode in structure.Position.GetAccessibleAdjacentHexagonNodes(HexagonManager))
                {
                    var p1 = adjacentHexagonNode.Position1;
                    var p2 = adjacentHexagonNode.Position2;
                    var p3 = adjacentHexagonNode.Position3;
                    if (HexagonManager.GetHexagonAtPosition(p1) == null)
                    {
                        HexagonManager.RevealHexagonAt(p1);
                    }
                    if (HexagonManager.GetHexagonAtPosition(p2) == null)
                    {
                        HexagonManager.RevealHexagonAt(p2);
                    }
                    if (HexagonManager.GetHexagonAtPosition(p3) == null)
                    {
                        HexagonManager.RevealHexagonAt(p3);
                    }

                    if (StructureManager[adjacentHexagonNode] == null && ButtonManager[adjacentHexagonNode] == null)
                    {
                        var button = new BuildButton(GameSettings, adjacentHexagonNode);
                        ButtonManager.AddButton(button, adjacentHexagonNode);
                    }

                    /*if (!EdgeManager.ContainsEdge(structure.Position, adjacentHexagonNode))
                     *  EdgeManager.AddEdge(structure.Position, adjacentHexagonNode);*/
                }
            }
        }
Пример #7
0
 public HexagonRevealer(HexagonManager hexagonManager, GameplaySettings gameplaySettings)
 {
     HexagonManager   = hexagonManager;
     GameplaySettings = gameplaySettings;
 }