public void TestCantMove() { // Arrange OpenNorthWall(); OpenEastWall(); OpenWestWall(); OpenSouthWall(); this._repelParameters.StartLocation = new TilePos(20, 13); this._map[this._repelParameters.StartLocation.X - 1, this._repelParameters.StartLocation.Y] = false; this._map[this._repelParameters.StartLocation.X + 1, this._repelParameters.StartLocation.Y] = false; this._map[this._repelParameters.StartLocation.X, this._repelParameters.StartLocation.Y - 1] = false; this._map[this._repelParameters.StartLocation.X, this._repelParameters.StartLocation.Y + 1] = false; this._repelParameters.RepelLocation = new TilePos(20, 15); this._repelParameters.MaximumLengthOfPath = 24; this._repelParameters.MinimumDistanceToMoveAway = 12; RepelObject pathFinder = new RepelObject(this._repelParameters); // Act IList <TilePos> path; var result = pathFinder.TryFindPath(out path); // Assert Assert.IsFalse(result); Assert.IsNull(path); OutputRoute(null); }
private RepelObject InstantiateRepelObject() { var prefab = repelObjectPrefabs[Random.Range(0, repelObjectPrefabs.Length)]; RepelObject repelObj = Instantiate(prefab, transform); //Set Position Camera initialCamera = null; switch (wallOrFloor) { case WallOrFloor.Wall: initialCamera = AbstractImmersiveCamera.CurrentImmersiveCamera.wallCameras[Random.Range(0, AbstractImmersiveCamera.CurrentImmersiveCamera.wallCameras.Count)]; break; case WallOrFloor.Floor: initialCamera = AbstractImmersiveCamera.CurrentImmersiveCamera.floorCamera; break; } var position = initialCamera.ViewportToWorldPoint(new Vector3(Random.value, Random.value, distanceFromCamera)); repelObj.transform.position = position; repelObj.Init(repelSpeed, defaultSpeed, repelDistance, distanceFromCamera, wallOrFloor); return(repelObj); }
private void MoveMonsterToSafeDistance(Monster monster) { var repelParameters = new RepelParameters { StartLocation = monster.TilePosition, RepelLocation = _player.TilePosition, CanBeOccupied = tp => !GlobalServices.GameState.IsImpassableItemOnTile(tp), MaximumLengthOfPath = 24, MinimumDistanceToMoveAway = 16 }; var repeller = new RepelObject(repelParameters); var result = repeller.TryFindPath(out var path); if (result && path.Any()) { monster.ResetPosition(path.Last().ToPosition()); } }
public void TestMaxPathLength() { this._map = new bool[10, 1]; for (int i = 0; i < 10; i++) { this._map[i, 0] = true; } this._repelParameters.MaximumLengthOfPath = 5; this._repelParameters.StartLocation = new TilePos(0, 0); this._repelParameters.MinimumDistanceToMoveAway = 8; RepelObject pathFinder = new RepelObject(this._repelParameters); // Act var result = pathFinder.TryFindPath(out var _); // Assert Assert.IsFalse(result); }
public void TestNoNeedToMove() { // Arrange OpenNorthWall(); this._repelParameters.StartLocation = new TilePos(20, 4); this._repelParameters.RepelLocation = new TilePos(20, 18); this._repelParameters.MaximumLengthOfPath = 24; this._repelParameters.MinimumDistanceToMoveAway = 12; RepelObject pathFinder = new RepelObject(this._repelParameters); // Act IList <TilePos> path; var result = pathFinder.TryFindPath(out path); // Assert Assert.IsTrue(result); Assert.IsFalse(path.Any()); OutputRoute(path); }
public void TestNoExitsAvailableAndMonsterToNorthThenMonsterCannotMoveAway() { // Arrange AddCentralIsland(); this._repelParameters.StartLocation = new TilePos(20, 13); this._repelParameters.RepelLocation = new TilePos(20, 15); this._repelParameters.MaximumLengthOfPath = 24; this._repelParameters.MinimumDistanceToMoveAway = 16; RepelObject pathFinder = new RepelObject(this._repelParameters); // Act IList <TilePos> path; var result = pathFinder.TryFindPath(out path); // Assert Assert.IsFalse(result); Assert.IsNull(path); OutputRoute(null); }
public void TestMoveAroundObstacle() { // Arrange AddCentralIsland(); OpenEastWall(); this._repelParameters.StartLocation = new TilePos(21, 14); this._repelParameters.RepelLocation = new TilePos(20, 14); this._repelParameters.MaximumLengthOfPath = 24; this._repelParameters.MinimumDistanceToMoveAway = 16; RepelObject pathFinder = new RepelObject(this._repelParameters); // Act IList <TilePos> path; var result = pathFinder.TryFindPath(out path); // Assert Assert.IsTrue(result); Assert.IsTrue(path.Any()); OutputRoute(path); }
public void TestOnlyExitIsSouthAndMonsterToNorthThenMonsterMovesDownPastRepelLocation() { // Arrange OpenSouthWall(); AddCentralIsland(); AddTopCentralPairOfIslands(); this._repelParameters.StartLocation = new TilePos(20, 13); this._repelParameters.RepelLocation = new TilePos(20, 15); this._repelParameters.MaximumLengthOfPath = 24; this._repelParameters.MinimumDistanceToMoveAway = 12; RepelObject pathFinder = new RepelObject(this._repelParameters); // Act IList <TilePos> path; var result = pathFinder.TryFindPath(out path); // Assert Assert.IsTrue(result); Assert.IsTrue(path.Any()); OutputRoute(path); }