public OverlayController(UiStateModel uiState,
                                 ISimulationManager simulationManager,
                                 ISimulationState simulationState,
                                 IIndicatorProvider indicatorProvider,
                                 StatusBar statusBar)
        {
            _uiState = uiState ?? throw new ArgumentNullException(nameof(uiState));
            if (simulationManager == null)
            {
                throw new ArgumentNullException(nameof(simulationManager));
            }
            if (simulationState == null)
            {
                throw new ArgumentNullException(nameof(simulationState));
            }
            if (indicatorProvider == null)
            {
                throw new ArgumentNullException(nameof(indicatorProvider));
            }
            _statusBar = statusBar ?? throw new ArgumentNullException(nameof(statusBar));

            _executeEventArgs = new ExecuteEventArgs()
            {
                Manager = simulationManager,
                Sim     = simulationState,
            };

            _updateReadinessEventArgs = new UpdateReadinessEventArgs
            {
                Sim = simulationState,
            };

            _lastHover          = HexCoords.CreateFromOffset(-1, -1);
            _hoverTileIndicator = indicatorProvider.GetIndicator("HoverTileIndicator");
        }
Exemple #2
0
        public void TestGetCoordsAreValid()
        {
            var hgc = new HexGridCollectionAdapter(3, 3);

            Assert.IsTrue(hgc.HasHex(HexCoords.CreateFromOffset(0, 0)));
            Assert.IsTrue(hgc.HasHex(HexCoords.CreateFromOffset(1, 0)));
            Assert.IsTrue(hgc.HasHex(HexCoords.CreateFromOffset(2, 0)));
            Assert.IsTrue(hgc.HasHex(HexCoords.CreateFromOffset(0, 1)));
            Assert.IsTrue(hgc.HasHex(HexCoords.CreateFromOffset(1, 1)));
            Assert.IsTrue(hgc.HasHex(HexCoords.CreateFromOffset(2, 1)));
            Assert.IsTrue(hgc.HasHex(HexCoords.CreateFromOffset(0, 2)));
            Assert.IsTrue(hgc.HasHex(HexCoords.CreateFromOffset(1, 2)));
            Assert.IsTrue(hgc.HasHex(HexCoords.CreateFromOffset(2, 2)));

            Assert.IsFalse(hgc.HasHex(HexCoords.CreateFromOffset(-1, 0)));
            Assert.IsFalse(hgc.HasHex(HexCoords.CreateFromOffset(0, -1)));

            // everything in row 3 is out of bounds
            Assert.IsFalse(hgc.HasHex(HexCoords.CreateFromOffset(3, 0)));
            Assert.IsFalse(hgc.HasHex(HexCoords.CreateFromOffset(3, 1)));
            Assert.IsFalse(hgc.HasHex(HexCoords.CreateFromOffset(3, 2)));
            Assert.IsFalse(hgc.HasHex(HexCoords.CreateFromOffset(3, 3)));

            // everything in column 3 is out of bounds
            Assert.IsFalse(hgc.HasHex(HexCoords.CreateFromOffset(0, 3)));
            Assert.IsFalse(hgc.HasHex(HexCoords.CreateFromOffset(1, 3)));
            Assert.IsFalse(hgc.HasHex(HexCoords.CreateFromOffset(2, 3)));
            Assert.IsFalse(hgc.HasHex(HexCoords.CreateFromOffset(3, 3)));
        }
Exemple #3
0
        public void TestIndexing()
        {
            var hgc = new HexGridCollectionAdapter(3, 3);

            var allHexes = hgc.ToList();

            // this assumes that hexagons are generated column by column
            var i = 0;

            Assert.AreEqual(allHexes[i++], hgc.GetHex(HexCoords.CreateFromOffset(0, 0)));
            Assert.AreEqual(allHexes[i++], hgc.GetHex(HexCoords.CreateFromOffset(1, 0)));
            Assert.AreEqual(allHexes[i++], hgc.GetHex(HexCoords.CreateFromOffset(2, 0)));

            Assert.AreEqual(allHexes[i++], hgc.GetHex(HexCoords.CreateFromOffset(0, 1)));
            Assert.AreEqual(allHexes[i++], hgc.GetHex(HexCoords.CreateFromOffset(1, 1)));
            Assert.AreEqual(allHexes[i++], hgc.GetHex(HexCoords.CreateFromOffset(2, 1)));

            Assert.AreEqual(allHexes[i++], hgc.GetHex(HexCoords.CreateFromOffset(0, 2)));
            Assert.AreEqual(allHexes[i++], hgc.GetHex(HexCoords.CreateFromOffset(1, 2)));
            Assert.AreEqual(allHexes[i], hgc.GetHex(HexCoords.CreateFromOffset(2, 2)));

            Assert.ThrowsException <IndexOutOfRangeException>(() => hgc.GetHex(HexCoords.CreateFromOffset(-1, 0)));
            Assert.ThrowsException <IndexOutOfRangeException>(() => hgc.GetHex(HexCoords.CreateFromOffset(0, -1)));
            Assert.ThrowsException <IndexOutOfRangeException>(() => hgc.GetHex(HexCoords.CreateFromOffset(3, 0)));
            Assert.ThrowsException <IndexOutOfRangeException>(() => hgc.GetHex(HexCoords.CreateFromOffset(3, 2)));
            Assert.ThrowsException <IndexOutOfRangeException>(() => hgc.GetHex(HexCoords.CreateFromOffset(0, 3)));
        }
Exemple #4
0
        public void TestDirection()
        {
            var hgc = new HexGridCollectionAdapter(6, 6);

            var coords = HexCoords.CreateFromOffset(4, 3);

            coords = hgc.GetNeighbourCoords(coords, HexDirection.North);
            Assert.AreEqual(5, coords.Row);
            Assert.AreEqual(3, coords.Column);

            coords = hgc.GetNeighbourCoords(coords, HexDirection.SouthEast);
            Assert.AreEqual(4, coords.Row);
            Assert.AreEqual(4, coords.Column);

            coords = hgc.GetNeighbourCoords(coords, HexDirection.South);
            Assert.AreEqual(3, coords.Row);
            Assert.AreEqual(4, coords.Column);

            coords = hgc.GetNeighbourCoords(coords, HexDirection.SouthWest);
            Assert.AreEqual(3, coords.Row);
            Assert.AreEqual(3, coords.Column);

            coords = hgc.GetNeighbourCoords(coords, HexDirection.NorthWest);
            Assert.AreEqual(3, coords.Row);
            Assert.AreEqual(2, coords.Column);

            coords = hgc.GetNeighbourCoords(coords, HexDirection.North);
            Assert.AreEqual(4, coords.Row);
            Assert.AreEqual(2, coords.Column);

            coords = hgc.GetNeighbourCoords(coords, HexDirection.NorthEast);
            Assert.AreEqual(5, coords.Row);
            Assert.AreEqual(3, coords.Column);
        }
Exemple #5
0
        public void TestRadius2Neighbours()
        {
            var map = new HexGridCollectionAdapter(10, 10);

            var center = HexCoords.CreateFromOffset(5, 5);

            var neighbours = map.GetNeighbours(center, 2);

            Assert.AreEqual(12, neighbours.Count);

            Assert.IsTrue(neighbours.Contains(map.GetHex(HexCoords.CreateFromOffset(7, 5))));
            Assert.IsTrue(neighbours.Contains(map.GetHex(HexCoords.CreateFromOffset(6, 6))));
            Assert.IsTrue(neighbours.Contains(map.GetHex(HexCoords.CreateFromOffset(6, 7))));

            Assert.IsTrue(neighbours.Contains(map.GetHex(HexCoords.CreateFromOffset(5, 7))));
            Assert.IsTrue(neighbours.Contains(map.GetHex(HexCoords.CreateFromOffset(4, 7))));
            Assert.IsTrue(neighbours.Contains(map.GetHex(HexCoords.CreateFromOffset(3, 6))));

            Assert.IsTrue(neighbours.Contains(map.GetHex(HexCoords.CreateFromOffset(3, 5))));
            Assert.IsTrue(neighbours.Contains(map.GetHex(HexCoords.CreateFromOffset(3, 4))));
            Assert.IsTrue(neighbours.Contains(map.GetHex(HexCoords.CreateFromOffset(4, 3))));

            Assert.IsTrue(neighbours.Contains(map.GetHex(HexCoords.CreateFromOffset(5, 3))));
            Assert.IsTrue(neighbours.Contains(map.GetHex(HexCoords.CreateFromOffset(6, 3))));
            Assert.IsTrue(neighbours.Contains(map.GetHex(HexCoords.CreateFromOffset(6, 4))));
        }
Exemple #6
0
        public void TestNoNeighbours()
        {
            var map = new HexGridCollectionAdapter(1, 1);

            var center = HexCoords.CreateFromOffset(0, 0);

            var neighbours = map.GetNeighbours(center);

            Assert.AreEqual(0, neighbours.Count);
        }
Exemple #7
0
        public void TestCornerNeighbours()
        {
            var map = new HexGridCollectionAdapter(6, 6);

            var corner = HexCoords.CreateFromOffset(0, 0);

            var neighbours = map.GetNeighbours(corner);

            Assert.AreEqual(3, neighbours.Count);

            Assert.IsTrue(neighbours.Contains(map.GetHex(HexCoords.CreateFromOffset(1, 0))));
            Assert.IsTrue(neighbours.Contains(map.GetHex(HexCoords.CreateFromOffset(1, 1))));
            Assert.IsTrue(neighbours.Contains(map.GetHex(HexCoords.CreateFromOffset(0, 1))));
        }
Exemple #8
0
        public void TestPerformance()
        {
            const int rows = 100;
            const int cols = 100;
            const int searchRepetitions = 10;

            var list = new List <HexCoords>(rows * cols);
            var dict = new Dictionary <HexCoords, HexCoords>();

            // prep
            for (var row = 0; row < rows; ++row)
            {
                for (var col = 0; col < cols; ++col)
                {
                    list.Add(HexCoords.CreateFromOffset(row, col));
                }
            }

            // add
            var addWatch = System.Diagnostics.Stopwatch.StartNew();

            foreach (var hc in list)
            {
                dict.Add(hc, hc);
            }

            addWatch.Stop();
            System.Diagnostics.Debug.WriteLine($"Elapsed time for adding: {addWatch.ElapsedMilliseconds}ms");

            // search
            var searchWatch = System.Diagnostics.Stopwatch.StartNew();

            var hasKey = true;

            for (var i = 0; i < searchRepetitions; ++i)
            {
                foreach (var hc in list)
                {
                    hasKey = hasKey & dict.ContainsKey(hc);
                }
            }

            searchWatch.Stop();
            System.Diagnostics.Debug.WriteLine($"Elapsed time for searching: {searchWatch.ElapsedMilliseconds}ms");

            // pass test
            Assert.IsTrue(true);
        }
Exemple #9
0
        public void TestListOffset()
        {
            var hgc = new HexGridCollectionAdapter(3, 3);

            Assert.AreEqual(hgc.GetOffset(HexCoords.CreateFromOffset(0, 0)), 0);
            Assert.AreEqual(hgc.GetOffset(HexCoords.CreateFromOffset(1, 0)), 1);
            Assert.AreEqual(hgc.GetOffset(HexCoords.CreateFromOffset(2, 0)), 2);

            Assert.AreEqual(hgc.GetOffset(HexCoords.CreateFromOffset(0, 1)), 3);
            Assert.AreEqual(hgc.GetOffset(HexCoords.CreateFromOffset(1, 1)), 4);
            Assert.AreEqual(hgc.GetOffset(HexCoords.CreateFromOffset(2, 1)), 5);

            Assert.AreEqual(hgc.GetOffset(HexCoords.CreateFromOffset(0, 2)), 6);
            Assert.AreEqual(hgc.GetOffset(HexCoords.CreateFromOffset(1, 2)), 7);
            Assert.AreEqual(hgc.GetOffset(HexCoords.CreateFromOffset(2, 2)), 8);
        }
Exemple #10
0
        public void TestAllNeighbours()
        {
            var map = new HexGridCollectionAdapter(8, 8);

            var center = HexCoords.CreateFromOffset(4, 3);

            var neighbours = map.GetNeighbours(center);

            Assert.AreEqual(6, neighbours.Count);

            Assert.IsTrue(neighbours.Contains(map.GetHex(HexCoords.CreateFromOffset(5, 3))));
            Assert.IsTrue(neighbours.Contains(map.GetHex(HexCoords.CreateFromOffset(4, 4))));
            Assert.IsTrue(neighbours.Contains(map.GetHex(HexCoords.CreateFromOffset(3, 4))));
            Assert.IsTrue(neighbours.Contains(map.GetHex(HexCoords.CreateFromOffset(3, 3))));
            Assert.IsTrue(neighbours.Contains(map.GetHex(HexCoords.CreateFromOffset(3, 2))));
            Assert.IsTrue(neighbours.Contains(map.GetHex(HexCoords.CreateFromOffset(4, 2))));
        }
Exemple #11
0
        public void TestEquality()
        {
            var hc1 = HexCoords.CreateFromOffset(0, 0);
            var hc2 = HexCoords.CreateFromOffset(0, 0);
            var hc3 = HexCoords.CreateFromOffset(0, 1);
            var hc4 = HexCoords.CreateFromOffset(1, 0);

            Assert.AreNotEqual(hc1, null);
            Assert.AreNotEqual(hc1, 5);
            Assert.AreNotEqual(hc1, "string");

            Assert.AreEqual(hc1, hc1);
            Assert.AreEqual(hc1, hc2);
            Assert.AreEqual(hc2, hc1);

            Assert.AreNotEqual(hc1, hc3);
            Assert.AreNotEqual(hc1, hc4);
        }
Exemple #12
0
        private void AddTiles()
        {
            Tiles.Populate((hc, v) => new TileModel {
                Coords = hc, TowerName = "SocketTower", Team = 0
            });

            Tiles.GetHex(HexCoords.CreateFromOffset(4, 5)).TowerName = "GunTower";
            Tiles.GetHex(HexCoords.CreateFromOffset(5, 5)).TowerName = "GunTower";
            Tiles.GetHex(HexCoords.CreateFromOffset(4, 4)).TowerName = "GunTower";
            Tiles.GetHex(HexCoords.CreateFromOffset(6, 5)).TowerName = "GunTower";
            Tiles.GetHex(HexCoords.CreateFromOffset(5, 6)).TowerName = "GunTower";

            Tiles.GetHex(HexCoords.CreateFromOffset(4, 15)).TowerName = "GunTower";
            Tiles.GetHex(HexCoords.CreateFromOffset(5, 15)).TowerName = "GunTower";
            Tiles.GetHex(HexCoords.CreateFromOffset(4, 14)).TowerName = "GunTower";
            Tiles.GetHex(HexCoords.CreateFromOffset(6, 15)).TowerName = "GunTower";
            Tiles.GetHex(HexCoords.CreateFromOffset(5, 16)).TowerName = "GunTower";

            Tiles.GetHex(HexCoords.CreateFromOffset(2, 1)).TowerName = "GunTower";
        }
Exemple #13
0
 public void Populate(Func <HexCoords, MapTileModel, MapTileModel> populator)
 {
     _tiles.Populate(populator);
     _offMapTile = populator(HexCoords.CreateFromOffset(-100, -100), default(MapTileModel));
 }
Exemple #14
0
 public UiStateModel()
 {
     WindowSize     = Vector2.Zero;
     HoverHexCoords = HexCoords.CreateFromOffset(-1, -1);
 }