Esempio n. 1
0
        public void Initialize(int height, Vector2 firstPos, Vector2 alienSize, float margin)
        {
            aliens = new List<Alien>(height);
              for (int i = 0; i < height; ++i) {
            AlienType type;
            switch (height) {
            case 0:
            case 1:
              type = AlienType.Crab;
              break;
            case 2:
            case 3:
              type = AlienType.Ant;
              break;
            default:
              type = AlienType.Squid;
              break;
            }

            aliens.Add( new Alien(this, type, new Vector2(firstPos.X, firstPos.Y + i * (alienSize.Y + margin)), alienSize) );
              }

              FirstAlien = aliens[0];
              LastAlien = aliens[height - 1];

              UpdateDimensions();
        }
 public Alien(Alien alien)
     : base(alien)
 {
     OnDestroyedEvent += OnDestroy;
     DeltaX = alien.DeltaX;
     DeltaY = alien.DeltaY;
     Command = alien.Command;
 }
        public static Alien CopyAndFlip(Alien alien, CoordinateFlipper flipper, Dictionary<int, Entity> flippedEntities)
        {
            if (flippedEntities.ContainsKey(alien.Id)) return (Alien) flippedEntities[alien.Id];

            var copy = new Alien(alien)
            {
                PlayerNumber = alien.PlayerNumber == 1 ? 2 : 1,
                DeltaX = -alien.DeltaX,
                DeltaY = -alien.DeltaY,
                X = flipper.CalculateFlippedX(alien.X),
                Y = flipper.CalculateFlippedY(alien.Y)
            };

            flippedEntities.Add(copy.Id, copy);
            return copy;
        }
        public static List<Alien> Build(int playerNumber, int waveSize, int startX, int deltaX)
        {
            var map = Match.GetInstance().Map;
            var deltaY = playerNumber == 1 ? -1 : 1;
            var middleHeightOfMap = map.Height / 2;

            // make sure aliens dont go out of map
            while (map.IsOutOfXBounds(startX + 3 * deltaX * (waveSize - 1)))
            {
                startX -= 3 * deltaX;
            }

            // Spawn
            var wave = new List<Alien>();
            var alienY = middleHeightOfMap + deltaY;
            var alienX = startX;
            Alien alien = null;
            for (var i = 0; i < waveSize; i++)
            {
                try
                {
                    alien = new Alien(playerNumber) { X = alienX, Y = alienY };
                    alien.DeltaX = deltaX;

                    map.AddEntity(alien);
                    wave.Add(alien);
                }
                catch (CollisionException ex)
                {
                    ex.Entity.Destroy();

                    if (ex.Entity.GetType() == typeof(Missile))
                    {
                        ((Missile)ex.Entity).ScoreKill(alien);
                    }
                }

                alienX += 3 * deltaX;
            }

            return wave;
        }
        private void IssueShootOrder(Alien alien)
        {
            if (alien == null) return;

            ShotEnergy -= ShotEnergyCost;

            switch (alien.Command)
            {
                case AlienCommand.MoveForward:
                    alien.Command = AlienCommand.MoveForwardAndShoot;
                    break;
                case AlienCommand.MoveSideways:
                    alien.Command = AlienCommand.MoveSidewaysAndShoot;
                    break;
            }
        }
        public Alien TestAddAlien(int x, int y)
        {
            var alien = new Alien(PlayerNumber) {X = x, Y = y};
            Match.GetInstance().Map.AddEntity(alien);

            Waves.Insert(0, new List<Alien> {alien});
            return alien;
        }
Esempio n. 7
0
        public void RemoveAlien(Alien alien)
        {
            aliens.Remove(alien);

              if (alien == FirstAlien || alien == LastAlien) {
            if (aliens.Count == 0) {
              FirstAlien = null;
              LastAlien = null;
            } else {
              FirstAlien = aliens[0];
              LastAlien = aliens[aliens.Count - 1];
            }

            UpdateDimensions();
              }
        }
        public void TestBuildShieldDestroysAlienWithExplosion()
        {
            // Given
            var game = Match.GetInstance();
            game.StartNewGame();
            var map = game.Map;
            var player = game.GetPlayer(1);
            var ship = player.Ship;

            // When
            var alien = new Alien(2) {X = ship.X, Y = ship.Y - 3, DeltaX = 1};
            map.AddEntity(alien);
            ship.Command = ShipCommand.BuildShield;
            game.Update();

            // Then
            Assert.IsFalse(alien.Alive, "Alien was not destroyed");

            Assert.IsNotNull(map.GetEntity(ship.X, ship.Y - 1),
                "Left rear shield tile is missing");
            Assert.IsNotNull(map.GetEntity(ship.X + 1, ship.Y - 1),
                "Center rear shield tile is missing");
            Assert.IsNotNull(map.GetEntity(ship.X + 2, ship.Y - 1),
                "Right rear shield tile is missing");

            Assert.IsNull(map.GetEntity(ship.X, ship.Y - 2),
                "Left middle shield tile was not destroyed");
            Assert.IsNull(map.GetEntity(ship.X + 1, ship.Y - 2),
                "Center middle shield tile was not destroyed");
            Assert.IsNotNull(map.GetEntity(ship.X + 2, ship.Y - 2),
                "Right middle shield tile is missing");

            Assert.IsNull(map.GetEntity(ship.X, ship.Y - 3),
                "Left front shield tile was not destroyed");
            Assert.IsNull(map.GetEntity(ship.X + 1, ship.Y - 3),
                "Center front shield tile was not destroyed");
            Assert.IsNotNull(map.GetEntity(ship.X + 2, ship.Y - 3),
                "Right front shield tile is missing");
        }