Esempio n. 1
0
 public static void MoveAliens(AlienListModel alienList)
 {
     foreach (var alien in alienList.Aliens)
     {
         alien.ShuntPosition();
     }
 }
Esempio n. 2
0
 public static void CheckIfAlienShot(double gameTimeSeconds, AlienListModel alienList, ShipBulletListModel shipBulletsList, ExplosionListModel explosionsList, ScoreModel Scoring, GameSounds gameSounds)
 {
     CheckIfAlienShotAndThen(
         gameTimeSeconds, alienList, shipBulletsList, alien =>
     {
         AddExplosion(gameTimeSeconds, alien.CentrePoint, explosionsList, gameSounds);
         Scoring.SetScore(Scoring.Score + 1);
     });
 }
Esempio n. 3
0
        public static void RemoveOffScreenObjects(AlienListModel aliensList, ShipBulletListModel shipBulletList, AlienBulletListModel alienBulletList, StarscapeModel starList, ScoreModel scoring)
        {
            shipBulletList.ShipBullets.RemoveAll(b => b.CentrePoint.x > RetroScreen.WidthInPixels);
            alienBulletList.AlienBullets.RemoveAll(b => b.CentrePoint.x < 0);
            starList.Stars.RemoveAll(s => s.CentrePoint.x < 0);
            int numberOfAliensRemoved = aliensList.Aliens.RemoveAll(a => a.CentrePoint.x < 0);

            scoring.SetScore(Math.Max(0, scoring.Score - numberOfAliensRemoved));
        }
Esempio n. 4
0
        public static void CheckIfShipShot(double gameTimeSeconds, ShipModel ship, AlienListModel aliensList, AlienBulletListModel alienBulletList, ExplosionListModel explosions, GameSounds gameSounds)
        {
            if (!ship.IsDestroyed)
            {
                bool shipDestroyed =
                    alienBulletList.AlienBullets.Exists(b => CollisionDetection.Hits(b.CentrePoint, ship.CentrePoint, CollisionDetectRange)) ||
                    aliensList.Aliens.Exists(a => CollisionDetection.Hits(a.CentrePoint, ship.CentrePoint, CollisionDetectRange));

                if (shipDestroyed)
                {
                    DestroyShip(gameTimeSeconds, ship, explosions, gameSounds);
                }
            }
        }
Esempio n. 5
0
        public static void ConsiderAddingAlienAndThen(double gameTimeSeconds, AlienListModel alienList, Random randomGenerator, Action <AlienModel> andThen)
        {
            var elapsedTime = gameTimeSeconds - alienList.LastTimeWeConsideredAddingAnAlien;       // Quiz:  Why work things out in seconds (as given by gameTimeSeconds), compared to the Alien.Speed and Star.Speed technique?   What's the difference, and is one technique best?

            if (elapsedTime > AlienListModel.TimeBetweenAddingAliens)
            {
                if (alienList.Aliens.Count < AlienListModel.MaxAliensOnScreenAtOnce)              // Quiz:  Why limit this?
                {
                    var alienY   = randomGenerator.Next(AlienModel.HighestY, AlienModel.LowestY); // NB: Y axis runs the other way up from normal mathematics!
                    var speed    = randomGenerator.Next(1, 5);
                    var newAlien = new AlienModel(new Point(AlienModel.IntroductionX, alienY), speed);
                    alienList.Aliens.Add(newAlien);
                    andThen(newAlien);
                }
                alienList.LastTimeWeConsideredAddingAnAlien = gameTimeSeconds;  // Quiz:  Why are we doing this here?
            }
        }
Esempio n. 6
0
        public static void CheckIfAlienShotAndThen(double gameTimeSeconds, AlienListModel alienList, ShipBulletListModel shipBulletsList, Action <AlienModel> andThen)
        {
            var bulletsToRemove = new List <ShipBulletModel>();
            var aliensToRemove  = new List <AlienModel>();

            foreach (var bullet in shipBulletsList.ShipBullets)
            {
                foreach (var alien in alienList.Aliens)
                {
                    if (CollisionDetection.Hits(bullet.CentrePoint, alien.CentrePoint, CollisionDetectRange))    // Quiz:  This design means hitting NEAR the centre of the alien!
                    {
                        bulletsToRemove.Add(bullet);
                        aliensToRemove.Add(alien);
                        andThen(alien);
                    }
                }
            }

            alienList.Aliens.RemoveAll(a => aliensToRemove.Contains(a));
            shipBulletsList.ShipBullets.RemoveAll(b => bulletsToRemove.Contains(b));
        }
Esempio n. 7
0
 public static void ConsiderAddingAlien(double gameTimeSeconds, ShipModel ship, AlienListModel alienList, Random randomGenerator, AlienBulletListModel alienBulletList, GameSounds gameSounds)
 {
     if (!ship.IsDestroyed)  // Quiz:  Why not add aliens in the period while the ship is "destroyed"?
     {
         ConsiderAddingAlienAndThen(gameTimeSeconds, alienList, randomGenerator, alien =>
         {
             if (randomGenerator.Next(0, 100) > AlienModel.PercentChangeAlienFiresWhenCreated)    // Quiz:   Does my hard-coded constant really 100 matter here?  Is this bad practice?
             {
                 CauseAlienToFire(alien, alienBulletList, gameSounds);
             }
         });
     }
 }