public void SimpleMapOneAdventurerOneMoveRightOneMoveLeft_Move_DontChangeOrientation() { string initialOrientation = "S"; string expectedIntermediateOrientation = "E"; string expectedFinalOrientation = "S"; string movements = "DG"; MapAdventurerEntry adventurerEntry = new MapAdventurerEntry("A", new[] { "Name", "0", "0", initialOrientation, movements }); Adventurer adventurer = new Adventurer(null, adventurerEntry); adventurer.Move(); Assert.That(adventurer.Orientation, Is.EqualTo(expectedIntermediateOrientation)); adventurer.Move(); Assert.That(adventurer.Orientation, Is.EqualTo(expectedFinalOrientation)); }
/// <summary> /// Move the adventuerer around the map. This method makes sure the user cannot /// go off of the map. /// </summary> /// <param name="dir">Direction the adventurer is expected to move.</param> /// <returns></returns> public bool MoveAdventurer(Actor.Direction dir) { int maxRow = Cells.GetUpperBound(0); int maxCol = Cells.GetUpperBound(1); Adventurer.Move(dir); // move hero back if he has left the board if (Adventurer.PositionX < 0) { Adventurer.Move(Actor.Direction.Right); } if (Adventurer.PositionX > maxCol) { Adventurer.Move(Actor.Direction.Left); } if (Adventurer.PositionY < 0) { Adventurer.Move(Actor.Direction.Down); } if (Adventurer.PositionY > maxRow) { Adventurer.Move(Actor.Direction.Up); } CurrentLocation.HasBeenSeen = true; return(CurrentLocation.HasItem || CurrentLocation.HasMonster); }
/// <summary> /// Moves Actor as long as it wont go off the GameMap. Returns true if the Hero enters a cell occupied by a Monster or Item /// </summary> public bool MoveHero(Actor.Direction dir) { if (dir == Actor.Direction.Up) { if (Adventurer.PositionY > 0) { Adventurer.Move(Actor.Direction.Up); Cells[Adventurer.PositionY, Adventurer.PositionX].HasBeenSeen = true; } } if (dir == Actor.Direction.Down) { if (Adventurer.PositionY < 9) { Adventurer.Move(Actor.Direction.Down); Cells[Adventurer.PositionY, Adventurer.PositionX].HasBeenSeen = true; } } if (dir == Actor.Direction.Left) { if (Adventurer.PositionX > 0) { Adventurer.Move(Actor.Direction.Left); Cells[Adventurer.PositionY, Adventurer.PositionX].HasBeenSeen = true; } } if (dir == Actor.Direction.Right) { if (Adventurer.PositionX < 9) { Adventurer.Move(Actor.Direction.Right); Cells[Adventurer.PositionY, Adventurer.PositionX].HasBeenSeen = true; } } if (Cells[Adventurer.PositionY, Adventurer.PositionX].HasItem) { return(true); } if (Cells[Adventurer.PositionY, Adventurer.PositionX].HasMonster) { return(true); } else { return(false); } }
public void SimpleMapOneAdventurer_Move_ChangeTheOrientationToWest() { string initialOrientation = "N"; string expectedOrientation = "O"; string movements = "D"; MapAdventurerEntry adventurerEntry = new MapAdventurerEntry("A", new[] { "Name", "0", "0", initialOrientation, movements }); Adventurer adventurer = new Adventurer(null, adventurerEntry); adventurer.Move(); Assert.That(adventurer.Orientation, Is.EqualTo(expectedOrientation)); }
public void AdventurerWithOneAction_HasAction_ReturnsFalseAfterOneMoveCall() { MapAdventurerEntry adventurerEntry = new MapAdventurerEntry("A", new[] { "name", "0", "0", "O", "D" }); Adventurer adventurer = new Adventurer(null, adventurerEntry); bool initialHasAction = adventurer.HasAction; adventurer.Move(); bool finalHasAction = adventurer.HasAction; Assert.That(initialHasAction, Is.True); Assert.That(finalHasAction, Is.False); }
public void SimpleMapOneAdventurerValidateLeftCommandOnAllOrientation_Move_RotateToLeft() { string initialOrientation = "N"; string expectedSecondOrientation = "E"; string expectedThirdOrientation = "S"; string expectedFourthOrientation = "O"; string expectedFinalOrientation = "N"; string movements = "GGGG"; MapAdventurerEntry adventurerEntry = new MapAdventurerEntry("A", new[] { "Name", "0", "0", initialOrientation, movements }); Adventurer adventurer = new Adventurer(null, adventurerEntry); adventurer.Move(); Assert.That(adventurer.Orientation, Is.EqualTo(expectedSecondOrientation)); adventurer.Move(); Assert.That(adventurer.Orientation, Is.EqualTo(expectedThirdOrientation)); adventurer.Move(); Assert.That(adventurer.Orientation, Is.EqualTo(expectedFourthOrientation)); adventurer.Move(); Assert.That(adventurer.Orientation, Is.EqualTo(expectedFinalOrientation)); }
public void Move_should_update_position() { // Given : Adventurer adventurer = new Adventurer( "Ismaïl", new Position(0, 0), Orientation.North, new List <Motion> { } ); // When : var positionToMove = new Position(0, 1); adventurer.Move(positionToMove); // Then : adventurer.Position.Should().Be(positionToMove); }
public void SimpleMapOneAdventurerValidateMovingCommand_Move_VerifyThatMapMoveAdventurerIsCalledToWest() { string adventurerName = "adv"; string initialOrientation = "O"; string initialXAdventurer = "1"; string initialYAdventurer = "1"; string adventurerMovements = "A"; int expectedXStep = 1; int expectedYStep = 0; Mock <IMap> mapMock = new Mock <IMap>(); IMap map = mapMock.Object; MapAdventurerEntry adventurerEntry = new MapAdventurerEntry("A", new[] { adventurerName, initialXAdventurer, initialYAdventurer, initialOrientation, adventurerMovements }); Adventurer adventurer = new Adventurer(map, adventurerEntry); mapMock.Setup(m => m.MoveAdventurer(adventurerName, expectedXStep, expectedYStep)); adventurer.Move(); mapMock.Verify(m => m.MoveAdventurer(adventurerName, expectedXStep, expectedYStep), Times.Once); }