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? } }
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(); }