Beispiel #1
0
 //constructor: same name as the class
 public Swarm(Form f)
 {
     for (int i = 0; i < swa.Length; ++i)
     {
         swa[i] = new Invader(f, 10 + (i * 130), 10); //this has created an array of invaders for the game
     }
     Form1.InvadersC += 1;
 } // end of the constructor
Beispiel #2
0
 private void SetUpGame()
 {
     gameOverImage = Image.FromFile("Images/gameover.png");
     player        = new Player(this.ClientRectangle.Width, this.ClientRectangle.Height); //Pass width and height of form to create Player object
     playerBullet  = new Bullet();                                                        //set up bullet object
     noOfInvaders  = 5;
     for (int i = 0; i < noOfInvaders; i++)
     {
         invaders[i] = new Invader(this.ClientRectangle.Width, this.ClientRectangle.Height, i); //create enemy objects
     }
     lblScore.Text      = "" + player.Score;                                                    //reset label that displays the score
     lblLives.Text      = "" + player.Lives;
     level              = StartLevel;
     lblLevel.Text      = "" + level;
     invaderFrameTimer  = 0;
     gameOver           = false;
     btnRestart.Enabled = false;
     btnRestart.Visible = false;
 }
Beispiel #3
0
        private void CheckAllInvadersDead()
        //checks if all the invaders are dead and if they are then reset their position and increase the level and difficulty
        {
            bool allInvadersDead = true; //only reset when all invaders are dead and this is true

            for (int i = 0; i < noOfInvaders; i++)
            {
                if (invaders[i].Alive == true)
                {
                    allInvadersDead = false;
                    break;          //no need to continue looping cause one is true and their position is only reset if none are true
                }
                else
                {
                    allInvadersDead = true;
                }
            }

            if (allInvadersDead) //if all of the invaders are dead
            {
                if (level <= 10)
                {
                    level++;           //increase the level
                    noOfInvaders += 5; //increase how many invaders there are by 5
                }
                else if (level > 10)
                {
                    level++; //increase the level but dont add anymore invaders
                }
                lblLevel.Text = "" + level;
                for (int i = 0; i < noOfInvaders; i++)
                {
                    invaders[i] = new Invader(this.ClientRectangle.Width, this.ClientRectangle.Height, i); //create new enemy objects with default values
                }
            }
        }