예제 #1
0
 public static void MoveAlienBullets(AlienBulletListModel alienBulletsList)
 {
     foreach (var alienBullet in alienBulletsList.AlienBullets)
     {
         alienBullet.ShuntPosition();
     }
 }
예제 #2
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);
                }
            }
        }
예제 #3
0
 public static void CauseAlienToFire(AlienModel alien, AlienBulletListModel alienBulletList, GameSounds gameSounds)      // Quiz:   What future purpose have I catered for by separating this out?  If you can guess, how could that purpose be fulfilled?
 {
     alienBulletList.AlienBullets.Add(new AlienBulletModel(alien.CentrePoint.ShuntedBy(-AlienModel.AlienWidth, 0)));
     gameSounds.EnemyFiringSound.Play();
 }
예제 #4
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);
             }
         });
     }
 }
예제 #5
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));
        }