public void TestTwoFractionFunctionality() { Fraction testFraction1 = new Fraction("test1"); Fraction testFraction2 = new Fraction("test2"); Point testPosition1 = new Point(1, 1); Point testPosition2 = new Point(1, 2); TerritoryChangeEvent territoryChangeEvent = new TerritoryChangeEvent(testPosition1, testFraction1); JEventBus.GetDefault().Post(territoryChangeEvent); territoryChangeEvent = new TerritoryChangeEvent(testPosition2, testFraction2); JEventBus.GetDefault().Post(territoryChangeEvent); FindTerritoryOwnerEvent checkTestPositionOwner = new FindTerritoryOwnerEvent(testPosition1); JEventBus.GetDefault().Post(checkTestPositionOwner); Assert.IsTrue(checkTestPositionOwner.Success); Assert.IsNotNull(checkTestPositionOwner.Owner); Assert.IsTrue(testFraction1 == checkTestPositionOwner.Owner); checkTestPositionOwner = new FindTerritoryOwnerEvent(testPosition2); JEventBus.GetDefault().Post(checkTestPositionOwner); Assert.IsTrue(checkTestPositionOwner.Success); Assert.IsNotNull(checkTestPositionOwner.Owner); Assert.IsTrue(testFraction2 == checkTestPositionOwner.Owner); foreach (var utp in new SquareRadiusForeach(testPosition1, 1, 8, 8, true).LikePointList()) { FindTerritoryOwnerEvent findTerritoryOwnerEvent = new FindTerritoryOwnerEvent(utp); JEventBus.GetDefault().Post(findTerritoryOwnerEvent); Assert.IsTrue(findTerritoryOwnerEvent.Success); if (!utp.Equals(testPosition2)) { Assert.IsNull(findTerritoryOwnerEvent.Owner); } } FindNeighboredEvent findNeighbored = new FindNeighboredEvent(testPosition1); JEventBus.GetDefault().Post(findNeighbored); Assert.IsTrue(findNeighbored.Success); Assert.IsNotNull(findNeighbored.NeighborFractions); Assert.IsNotNull(findNeighbored.Neighbors); Assert.AreEqual(2, findNeighbored.NeighborFractions.Count); Assert.AreEqual(8, findNeighbored.Neighbors.Count); }
public void FindNeighboredListener(FindNeighboredEvent findNeighbored) { HashSet <Fraction> _neighboredFraction = new HashSet <Fraction>(); List <Point> _neighbors = new List <Point>(); SquareRadiusForeach rectangleForeach = new SquareRadiusForeach(findNeighbored.Center, 1, _grid.Width, _grid.Height, true); rectangleForeach.ForEach((x, y, data) => { Point point = new Point(x, y); Fraction compareFraction = null; if (_territoryLinker.ContainsKey(point)) { compareFraction = _territoryLinker[point]; } _neighboredFraction.Add(compareFraction); _neighbors.Add(point); }); findNeighbored.Neighbors = _neighbors; findNeighbored.NeighborFractions = _neighboredFraction; findNeighbored.Success = true; }