public void TestBaseFunctionality() { Fraction testFraction = new Fraction("test"); Point testPosition = new Point(1, 1); TerritoryChangeEvent territoryChangeEvent = new TerritoryChangeEvent(testPosition, testFraction); JEventBus.GetDefault().Post(territoryChangeEvent); FindTerritoryOwnerEvent checkTestPositionOwner = new FindTerritoryOwnerEvent(testPosition); JEventBus.GetDefault().Post(checkTestPositionOwner); Assert.IsTrue(checkTestPositionOwner.Success); Assert.IsNotNull(checkTestPositionOwner.Owner); Assert.IsTrue(testFraction == checkTestPositionOwner.Owner); Assert.AreEqual(1, TerritoryApi.GetTerritoryCellsAmount(testFraction)); foreach (var utp in new SquareRadiusForeach(testPosition, 1, 8, 8, true).LikePointList()) { FindTerritoryOwnerEvent findTerritoryOwnerEvent = new FindTerritoryOwnerEvent(utp); JEventBus.GetDefault().Post(findTerritoryOwnerEvent); Assert.IsTrue(findTerritoryOwnerEvent.Success); Assert.IsNull(findTerritoryOwnerEvent.Owner); } }
public static void ChangeTerritoryOwner(Point tilePosition, Fraction newOwner, JEventBus eventBus = null) { if (eventBus == null) { eventBus = JEventBus.GetDefault(); } TerritoryChangeEvent territoryChangeEvent = new TerritoryChangeEvent(tilePosition, newOwner); BaseApi.SendEvent(eventBus, territoryChangeEvent); }
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 TerritoryChangeListener(TerritoryChangeEvent territoryChangeEvent) { Fraction oldOwner = _territoryLinker.GetValue(territoryChangeEvent.Position); Fraction newOwner = territoryChangeEvent.NewOwner; ChangeOwner(territoryChangeEvent.Position, oldOwner, newOwner); if (oldOwner != null && newOwner != null && !oldOwner.Equals(newOwner)) { Debug($"Territory {territoryChangeEvent.Position} switch from {oldOwner} to {newOwner}"); } else if (oldOwner != null && !oldOwner.Equals(newOwner)) { Debug($"Territory {territoryChangeEvent.Position} lost from {oldOwner}"); } else if (newOwner != null && !newOwner.Equals(oldOwner)) { Debug($"Territory {territoryChangeEvent.Position} gain to {newOwner}"); } UpdateBorder(territoryChangeEvent.Position, newOwner); }