Exemple #1
0
        public void FireShot()
        {
            if (_playerShots.Count < MaximumPlayerShots)
            {
                var  location = new Point(_player.Location.X + _player.Area.Width / 2, _player.Location.Y);
                Shot shot;
                //TODO: Add more kinds of shots
                switch (CurrentShotType)
                {
                case ShotType.BasicShot:
                    shot = new BasicShot(location, Direction.Up);
                    break;

                case ShotType.LazerShot:
                    shot = new LazerShot(location, Direction.Up);
                    break;

                case ShotType.HomingShot:
                    shot = new HomingShot(location, Direction.Up);
                    break;

                default:
                    throw new ArgumentException(nameof(CurrentShotType));
                }

                _playerShots.Add(shot);
                OnShotMoved(shot, false);
            }
        }
Exemple #2
0
        private void ReturnFire()
        {
            if (_invaders.Count <= 0)
            {
                return;
            }
            var invaderShots =
                from shot in _invaderShots
                select shot;

            if (invaderShots.Count() > Waves + 1 || _random.Next(10) < 10 - Waves)
            {
                return;
            }
            var avaliableInvaderGroups =
                from invader in _invaders
                group invader by invader.Location.X
                into invaderGroup
                orderby invaderGroup.Key descending
                select invaderGroup;

            var avaiInvaderGroupsList = avaliableInvaderGroups.ToList();
            var randomGroup           = avaiInvaderGroupsList[_random.Next(avaiInvaderGroupsList.Count)];
            var bottomInvader         = randomGroup.Last();

            var shotLocation = new Point(bottomInvader.Area.X + bottomInvader.Area.Width / 2,
                                         bottomInvader.Area.Bottom + 2);
            Shot newShot;

            switch (bottomInvader.InvaderType)
            {
            case InvaderType.Spaceship:
                newShot = new HomingShot(shotLocation, Direction.Down, _player);
                break;

            case InvaderType.Bug:
                newShot = new LazerShot(shotLocation, Direction.Down);
                break;

            case InvaderType.Saucer:
                newShot = new LazerShot(shotLocation, Direction.Down);
                break;

            case InvaderType.Satellite:
                newShot = new BasicShot(shotLocation, Direction.Down);
                break;

            case InvaderType.Star:
                newShot = new BasicShot(shotLocation, Direction.Down);
                break;

            default:
                throw new ArgumentException(nameof(bottomInvader));
            }

            _invaderShots.Add(newShot);
            OnShotMoved(newShot, false);
        }