示例#1
0
        public BaseEnemy(float speed, int hitPoints, double moveDelayMilis, Map map)
        {
            Speed = speed;
            HitPoints = hitPoints;
            MoveDelayMilis = moveDelayMilis;
            MoveDelayMilis = 0;
            _lastMoveTime = DateTime.Now;
            //MoveDelayMilis = 20;

            Shooted = false;
            MoveCount = 0;

            SlowDuration = 0;
            SlowPercent = 0;
            _slowed = false;

            _designatedSpeed = Speed;
            Destroy = false;

            if (map != null)
            {
                Center = map.Start;
            }
            EndReached = false;
        }
示例#2
0
        public FlyingEnemy(float speed, int hitPoints, double moveDelayMilis, Map map)
            : base(speed, hitPoints, moveDelayMilis, map)
        {
            if (map != null)
            {
                Middle = map.FlyMiddles[new Random().Next(map.FlyMiddles.Count)];
                Center = map.Start;
                End = map.End;
            }

            MiddleReached = false;
        }
示例#3
0
        public void Road_With_Only_Two_Directions_Has_One_Junction()
        {
            //arrange
            Map map = new Map();

            //act
            map.AddRoad(100, Directions.Right);
            map.AddRoad(50, Directions.Down);

            //assert
            Assert.AreEqual(1, map.Junctions.Count, "Map road has invalid number od junctions.");
        }
示例#4
0
        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;
        }
示例#5
0
        public GroundEnemy(float speed, int hitPoints, double moveDelayMilis, Map map)
            : base(speed, hitPoints, moveDelayMilis, map)
        {
            if (map != null)
            {
                angleShift = 0;

                Road r = map.FindRoad(Center);
                Angle = r != null ? r.GetDefaultAngle() : 0;

                Center = map.Start;
                End = map.End;
            }
        }
示例#6
0
        public void New_Enemy_Added_To_Map_Gets_Positioned_On_Road_Start()
        {
            //arrange
            var start = new PointF(10, 20);
            Map map = new Map() { Start = start };
            map.AddRoad(100, Directions.Right);
            BaseEnemy enemy = new GroundEnemy(1.3F, 1, 1, null);

            //act
            map.PositionEnemyForStart(enemy);

            //assert
            Assert.AreEqual(new PointF(10.1f, 20), enemy.Center, "Failed to position new ground enemy to map road start.");
        }
示例#7
0
        public void Map_End_Road_Position_Is_Equal_To_Sum_Of_Added_Roads()
        {
            //arrange
            Map map = new Map() { RoadThickness = 20, Start = new PointF(0, 0)};

            //act
            map.AddRoad(100, Directions.Right);
            map.AddRoad(50, Directions.Down);

            //assert
            var endX = 100 + 20 / 2;
            var endY = 50 + 20;
            Assert.AreEqual(new PointF(endX, endY), map.End, "Road end position is not valid.");
        }
示例#8
0
        public BaseEnemy SpawnOne(Map map)
        {
            LastTimeSpawn = DateTime.Now;
            Count--;

            BaseEnemy enemy = null;
            if (Ground)
                enemy = new GroundEnemy(Speed, HitPoints, 100, map) { Height = Height, Width = Width, Money = Money, Points = Points };
            else
                enemy = new FlyingEnemy(Speed, HitPoints, 100, map) { Height = Height, Width = Width, Money = Money, Points = Points };

            enemy.PositionEnemyForStart(map);

            return enemy;
        }
示例#9
0
        public Game(int nextWaveCounterSec)
        {
            _designatedNextLevelCounterSeconds = nextWaveCounterSec;
            NextLevelCounterSeconds = nextWaveCounterSec;

            Clock.Interval = 1000;
            Clock.Start();
            Clock.Tick += new EventHandler(Timer_Tick);

            Map = new Map();

            Enemies = new List<BaseEnemy>();
            Bullets = new List<BaseBullet>();
            Towers = new List<BaseTower>();
            TowersToAdd = new List<BaseTower>();
            Levels = new List<Level>();
        }
示例#10
0
        public override bool Move(Map map)
        {
            if (!base.Move(map)) return false;

            if (MoveCount > 5)
            {
                Vector vector = map.MoveOnRoad(Center, Speed, Angle, 15);
                Angle = vector.Angle;
                Center = vector.Point;
                MoveCount = 0;
            }

            Vector vector1 = map.MoveOnRoad(Center, Speed, Angle, 0);
            Angle = vector1.Angle;
            Center = vector1.Point;

            return true;
        }
示例#11
0
        public override bool Move(Map map)
        {
            if (!base.Move(map)) return false;

            base.Move(map);

            if (MiddleReached)
            {
                Angle = Calc.GetAngle(Center, map.End);
                Center = Calc.GetPoint(Center, Angle, Speed);
            }
            else
            {
                MiddleReached = Calc.Distance(Center, Middle) <= Speed;

                Angle = Calc.GetAngle(Center, Middle);
                Center = Calc.GetPoint(Center, Angle, Speed);
            }

            return true;
        }
示例#12
0
 public void PositionEnemyForStart(Map map)
 {
     Road first = map.Roads.First();
     if (first.Direction == Directions.Right)
         Center = new PointF(map.Start.X + 0.1F, map.Start.Y + map.RoadThickness / 2);
     else if (first.Direction == Directions.Left)
         Center = new PointF(map.Start.X + 0.1F, map.Start.Y + map.RoadThickness / 2);
     else if (first.Direction == Directions.Down)
         Center = new PointF(map.Start.X + map.RoadThickness / 2, Start.Y + 0.1F);
     else if (first.Direction == Directions.Up)
         Center = new PointF(map.Start.X + map.RoadThickness / 2, Start.Y + 0.1F);
 }
示例#13
0
        public virtual bool Move(Map map)
        {
            if (HitPoints < 1)
                return false;

            if (EndReached)
                return false;

            if ((DateTime.Now - _lastMoveTime).TotalMilliseconds < MoveDelayMilis)
                return false;

            _lastMoveTime = DateTime.Now;

            Shooted = false;

            MoveCount++;

            if (!_slowed && SlowPercent > 0)
            {
                Speed = Speed - Speed * SlowPercent / 100;
                _slowed = true;
            }
            SlowDuration = SlowDuration > 0 ? SlowDuration - 1 : 0;
            SlowPercent = SlowDuration > 0 ? SlowPercent : 0;
            if (SlowPercent == 0)
            {
                _slowed = false;
                Speed = _designatedSpeed;
            }

            EndReached = map.EndReached(Center);

            return true;
        }
示例#14
0
        public static bool IsOverlapingRoads(BaseTower tower, Map map)
        {
            foreach (var item in map.Roads)
            {
                if (item.IsInside(new PointF(tower.Center.X - tower.Width / 2, tower.Center.Y)))
                    return true;
                if (item.IsInside(new PointF(tower.Center.X, tower.Center.Y - tower.Height / 2)))
                    return true;
            }

            return false;
        }
示例#15
0
        public bool IsOverlapingRoads(Map map)
        {
            foreach (var item in map.Roads)
            {
                if (item.IsInside(new PointF(Center.X - Width, Center.Y)))
                    return true;
                if (item.IsInside(new PointF(Center.X + Width, Center.Y)))
                    return true;
                if (item.IsInside(new PointF(Center.X, Center.Y - Height)))
                    return true;
                if (item.IsInside(new PointF(Center.X, Center.Y + Height)))
                    return true;
            }

            foreach (var item in map.Junctions)
            {
                if (item.IsInside(new PointF(Center.X - Width, Center.Y)))
                    return true;
                if (item.IsInside(new PointF(Center.X + Width, Center.Y)))
                    return true;
                if (item.IsInside(new PointF(Center.X, Center.Y - Height)))
                    return true;
                if (item.IsInside(new PointF(Center.X, Center.Y + Height)))
                    return true;
            }

            return false;
        }