Esempio n. 1
0
 /// <summary>
 /// Initializes a new instance of the Game class.
 /// </summary>
 /// <param name="boundaries">The rectangle representing the gaming area.</param>
 /// <param name="random">A Random for use with all inner functions requiring a random.</param>
 public Game(Rectangle boundaries, Random random) {
     /* initialize the two accepted parameters before 
      ANYTHING else.*/
     this.boundaries = boundaries;
     this.random = random;
     this.playerShipStartingLocation = new Point(boundaries.Right - 100, boundaries.Bottom - 50);
     this.mothershipStartingLocation = new Point(boundaries.Left + 40, 90);
     this.motherShipDirection = Direction.Right;
     this.motherShip = null;
     this.motherShipTravelArea = new Rectangle(new Point(boundaries.Left, 90), new Size(boundaries.Width, 40));
     this.playerShip = new PlayerShip(playerShipStartingLocation);
     this.playerShots = new List<Shot>();
     this.playerBombs = new List<Bomb>();
     this.invaderShots = new List<Shot>();
     this.invaders = new List<Invader>();
     this.livesLeftDisplay = new List<Bitmap>();
     this.deadInvaderExplosions = new List<Explosion>();
     this.otherExplosions = new List<Explosion>();
     this.deadInvaderScores = new List<ScoreFlash>();
     this.mothershipHasAppeared = false;
     this.stars = new Stars(boundaries, random);
     for (int i = 0; i < livesLeft; i++)
         livesLeftDisplay.Add(playerShip.GetImage());
     NextWave();
 } // end constructor method Game
Esempio n. 2
0
        } // end method DrawLivesLeft

        /// <summary>
        /// This method progresses to the next wave of invaders while updating the Current Invader Wave and Frames To Skip
        /// and resetting the invader and shot lists.
        /// </summary>
        private void NextWave() {
            if (++currentInvaderWave > maxNumberOfWaves) {
                OnGameOver(new EventArgs());
                return;
            } // end if 
            framesToSkip--;
            //playerShip.Area.Location = playerShipStartingLocation;
            invaders = new List<Invader>();
            invaderDirection = Direction.Right;
            invaderShots = new List<Shot>();
            playerShots = new List<Shot>();
            playerBombs = new List<Bomb>();
            deadInvaderExplosions = new List<Explosion>();
            otherExplosions = new List<Explosion>();
            deadInvaderScores = new List<ScoreFlash>();
            //mothershipStartingLocation = new Point(boundaries.Left + 1, 50);
            //motherShipTravelArea = new Rectangle(new Point(boundaries.Left, 50), new Size(boundaries.Width, 40));
            //motherShipDirection = Direction.Right;
            motherShip = null;
            mothershipHasAppeared = false;
            ResetShields();
            int xMove = 85;
            int yMove = 50;
            int yPosition = 50;
            int xPosition = 50;
            yPosition = AddInvaderRow(ShipType.Satellite, 50, xMove, yMove, xPosition, yPosition);
            yPosition = AddInvaderRow(ShipType.Bug, 40, xMove, yMove, xPosition, yPosition);
            yPosition = AddInvaderRow(ShipType.Saucer, 30, xMove, yMove, xPosition, yPosition);
            yPosition = AddInvaderRow(ShipType.Spaceship, 20, xMove, yMove, xPosition, yPosition);
            yPosition = AddInvaderRow(ShipType.Star, 10, xMove, yMove, xPosition, yPosition);
        } // end method NextWave
Esempio n. 3
0
 /// <summary>
 /// This method removes an invader from the invaders list and 
 /// triggers an explosion where the invader died.
 /// </summary>
 /// <param name="deadInvader"></param>
 private void KillInvader(Invader deadInvader)
 {
     Explosion newDeadInvaderExplosion = new Explosion(deadInvader.Location, random);
     deadInvaderExplosions.Add(newDeadInvaderExplosion);
     ScoreFlash newDeadInvaderScoreFlash = new ScoreFlash(deadInvader.Location, deadInvader.Score);
     deadInvaderScores.Add(newDeadInvaderScoreFlash);
     score += deadInvader.Score;
     if (gotPointsFromShots) bombScore += deadInvader.Score;
     invaders.Remove(deadInvader);
     if (deadInvader is MotherShip) motherShip = null;
 } // end method KillInvader
Esempio n. 4
0
        } // end method MoveInvaderGrunts

        /// <summary>
        /// This method moves the mothership from the 
        /// left side of the screen to the right if it's active.
        /// It'll remove the mothership if it gets from left to right 
        /// with out getting shot.
        /// </summary>
        private void MoveMotherShip()
        {
            if (motherShip != null)
            {
                    motherShip.Move(motherShipDirection);
                    if (IsTouchingBorder(motherShip.Area, motherShipDirection, 20))
                    {
                        Explosion newExplosion = new Explosion(motherShip.Location, random);
                        otherExplosions.Add(newExplosion);
                        invaders.Remove(motherShip);
                        motherShip = null;
                    } // end if 
                } // end else
           // } // end if 
        } // end method MoveMotherShip
Esempio n. 5
0
        } // end method MoveMotherShip

        /// <summary>
        /// This method checks to see if there are no other invader ships in the rectangular area
        /// the mother ship flys by within. If there aren't any, the mothership appears.
        /// </summary>
        private void CheckToAddMotherShip() {
            if (!mothershipHasAppeared)
            {
                List<Invader> invaderGrunts = new List<Invader>();
                foreach (Invader invader in invaders)
                    if (invader is InvaderGrunt)
                        invaderGrunts.Add(invader);

                var invadergruntsOnBorder =
                      from invadergrunt in invaderGrunts
                      where motherShipTravelArea.Contains(invadergrunt.Location)
                      select invadergrunt;
                if (invadergruntsOnBorder.Count() > 0) return;
                else
                {
                    Explosion newExplosion = new Explosion(mothershipStartingLocation, random);
                    otherExplosions.Add(newExplosion);
                    motherShip = new MotherShip(mothershipStartingLocation);
                    invaders.Add(motherShip);
                    mothershipHasAppeared = true;
                } // end else 
            } // end if 
        } // end method CheckToAddMotherShip