public void InitGame() { float roadThicknes = 30; float upOffset = 10; game = new Game(20) { Money = 10, Life = 50 }; Level level = new Level() { Count = 10, Money = 5, Speed = 0.6F, Points = 1, SpawnDelayMilis = 1000, Width = 10, Height = 10, HitPoints = 40, Ground = true, Active = true }; game.Levels.Add(level); level = new Level() { Count = 10, Money = 10, Speed = 0.6F, Points = 1, SpawnDelayMilis = 1500, Width = 10, Height = 10, HitPoints = 40, Ground = false, Active = false }; game.Levels.Add(level); level = new Level() { Count = 10, Money = 5, Speed = 0.5F, Points = 1, SpawnDelayMilis = 1000, Width = 10, Height = 10, HitPoints = 60, Ground = true, Active = false }; game.Levels.Add(level); Map map = new Map() { Start = new PointF(0, 10), End = new PointF(450, 170), RoadThickness = 20 }; game.Map = map; map.AddRoad(100, Directions.Right); map.AddRoad(50, Directions.Down); map.AddRoad(50, Directions.Left); map.AddRoad(50, Directions.Down); map.AddRoad(150, Directions.Right); map.AddRoad(100, Directions.Up); map.AddRoad(90, Directions.Right); map.AddRoad(50, Directions.Down); map.AddRoad(130, Directions.Right); map.FlyMiddles.Add(new PointF(200, 30)); map.FlyMiddles.Add(new PointF(200, 50)); map.FlyMiddles.Add(new PointF(200, 70)); // buy towers SimpleTower tower = new SimpleTower() { Center = new PointF(200, 300), Price = 10, Range = 100, TargetType = TargetTypes.All, Active = false, Dummy = true }; game.Towers.Add(tower); SonicTower sonicTower = new SonicTower() { Center = new PointF(250, 300), Price = 50, Range = 100, TargetType = TargetTypes.All, Active = false, Dummy = true }; game.Towers.Add(sonicTower); HeavyTower heavyTower = new HeavyTower() { Center = new PointF(300, 300), Price = 20, Range = 100, SlowDuration = 50, SlowPercent = 50, TargetType = TargetTypes.Ground, Active = false, Dummy = true }; game.Towers.Add(heavyTower); TeslaTower teslaTower = new TeslaTower() { Center = new PointF(350, 300), Price = 20, Range = 150, TargetType = TargetTypes.All, Active = false, Dummy = true }; game.Towers.Add(teslaTower); // active towers tower = new SimpleTower() { Center = new PointF(150, 80), Range = 100, TargetType = TargetTypes.All, Active = true, Placed = true }; game.Towers.Add(tower); sonicTower = new SonicTower() { Center = new PointF(150, 120), Range = 100, TargetType = TargetTypes.All, Active = true, Placed = true }; game.Towers.Add(sonicTower); heavyTower = new HeavyTower() { Center = new PointF(150, 100), Range = 100, SlowDuration = 10, SlowPercent = 50, TargetType = TargetTypes.Ground, Active = true, Placed = true }; game.Towers.Add(heavyTower); teslaTower = new TeslaTower() { Center = new PointF(150, 50), Range = 200, TargetType = TargetTypes.All, Active = true, Placed = true }; game.Towers.Add(teslaTower); game.Running = true; }
public void Can_Not_Find_Target_If_Out_Of_Range() { //arrange var range = 100; var tower = new SimpleTower() { Center = new PointF(0, 0), Range = range, Active = true }; var enemy = new GroundEnemy(1.3F, 100, 100, null) { Center = new PointF(0, range + 1) }; //act var target = tower.FindTarget(new List<BaseEnemy>() { enemy }); //assert Assert.IsNull(target, "Tower found a target that is out of its range."); }
public void Can_Find_Target_In_Range() { //arrange var range = 100; var tower = new SimpleTower() { Center = new PointF(0, 0), Range = range, Active = true }; var enemy = new GroundEnemy(1.3F, 100, 100, null) { Center = new PointF(0, range) }; //act var target = tower.FindTarget(new List<BaseEnemy>() { enemy }); //assert Assert.IsNotNull(target, "Tower failed to find target that is within range."); }
public void Can_Only_Fire_On_Valid_TargetType() { //arrange var range = 100; var tower = new SimpleTower() { FireDelayMilis = 1000, Range = 100, TargetType = TargetTypes.Ground, Active = true }; var ground = new GroundEnemy(1.3F, 100, 100, null) { Center = new PointF(0, range) }; var flying = new FlyingEnemy(1.3F, 100, 100, null) { Center = new PointF(100, range) }; //act var targets = tower.FindTargets(new List<BaseEnemy>() { ground, flying }); //assert Assert.AreEqual(ground, targets.First(), "Tower found flying target but can only fire on ground targets."); }
public void Can_Not_Fire_Faster_Than_FileDelay() { //arrange var range = 100; var tower = new SimpleTower() { FireDelayMilis = 1000, Placed = true, Active = true }; var enemy = new GroundEnemy(1.3F, 100, 100, null) { Center = new PointF(0, range + 1) }; //act var bullet1 = tower.Fire(enemy); var canFire = tower.CanFire(); //assert Assert.IsFalse(canFire, "Tower fires faster that its fire rate."); }