public void MapModel_CalculateDistance_Valid_Should_Pass() { // Arrange var map = new MapModel(); map.MapXAxiesCount = 3; map.MapYAxiesCount = 3; map.MapGridLocation = new MapModelLocation[map.MapXAxiesCount, map.MapYAxiesCount]; var PlayerList = new List <PlayerInfoModel>(); var Character = new CharacterModel(); PlayerList.Add(new PlayerInfoModel(Character)); PlayerList.Add(new PlayerInfoModel(Character)); PlayerList.Add(new PlayerInfoModel(Character)); var Monster = new MonsterModel(); PlayerList.Add(new PlayerInfoModel(Monster)); PlayerList.Add(new PlayerInfoModel(Monster)); PlayerList.Add(new PlayerInfoModel(Monster)); map.PopulateMapModel(PlayerList); var start = map.GetPlayerAtLocation(0, 0); var end = map.GetPlayerAtLocation(2, 2); // Act var result = map.CalculateDistance(map.GetLocationForPlayer(start), map.GetLocationForPlayer(end)); // Reset // Assert Assert.AreEqual(2, result); }
public void MapModel_CalculateDistance_InValid_End_Null_Should_Fail() { // Arrange var map = new MapModel(); // Act var result = map.CalculateDistance(new MapModelLocation(), null); // Reset // Assert Assert.AreEqual(int.MaxValue, result); }
/// <summary> /// Pick the Monster to Attack /// </summary> /// <returns></returns> public BattleEntityModel SelectMonsterToAttack() { if (MonsterList == null) { return(null); } if (MonsterList.Count < 1) { return(null); } // Select closest monster to attack // Break ties on lowest current health, then highest level var Defender = EntityList .Where(m => m.Alive && m.EntityType == EntityTypeEnum.Monster) .OrderBy(m => MapModel.CalculateDistance(MapModel.GetLocationForPlayer(CurrentAttacker), MapModel.GetLocationForPlayer(m))) .ThenBy(m => m.CurrentHealth) .ThenByDescending(m => m.Level) .FirstOrDefault(); return(Defender); }