Beispiel #1
0
        public Game(Graphics g, Rectangle boundaries)
        {
            //Initialize the stars to plot a black background and to be able to add the stars to the
            //Canvas;
            this.g                 = g;
            this.boundaries.X      = 0;
            this.boundaries.Y      = 0;
            this.boundaries.Height = boundaries.Y;
            this.boundaries.Width  = boundaries.X;



            this.random = new Random();



            //Initializes two collections that keeps track of the shots fired respectively
            this.playerShots = new Shots();
            this.enemyShots  = new Shots();


            this.stars = new Stars(boundaries);
            Point initialPosition = new Point(boundaries.X / 2, boundaries.Y);

            this.playerShip = new PlayerShip(initialPosition, boundaries, playerShots, enemyShots, livesLeft);


            this.invaders = new Invaders(boundaries, playerShots, enemyShots, random, display);
            invaders.MoveInvaders();

            this.display = new Display(boundaries);



            //Plays the music for the life force
            System.Media.SoundPlayer player = new System.Media.SoundPlayer();
            player.SoundLocation = @"C:\GameMusic\LifeForce.wav";
            player.Load();
            player.Play();



            this.initialScreen = DateTime.Now;
            this.initialImage  = (Bitmap)Properties.Resources.ResourceManager.GetObject("LifeForce1");
        }
Beispiel #2
0
        public PlayerShip(Point location, Rectangle boundaries, Shots playerShots, Shots enemyShots, int livesLeft)
        {
            //Initialize the image
            this.image = (Bitmap)Properties.Resources.ResourceManager.GetObject("SpaceShip");
            //Initialize the location of the ship
            this.location.X = location.X;
            this.location.Y = location.Y - 30;// -image.Height;
            //Set the ship boolean to true for being alive
            this.Alive = true;


            //Initialize the original height
            deadShipHeight = image.Size.Height;


            this.boundaries = boundaries;


            //Shots fired

            this.playerShots = playerShots;
            this.enemyShots  = enemyShots;
            this.timeOfDeath = timeOfDeath;
        }
        //Constructor for the Invaders class taken the boundaries and the list of shots to be fired
        public Invaders(Rectangle boundaries, Shots playerShots, Shots enemyShots, Random random, Display scoreBoard)
        {
            //Initializing the distribution of the invaders to centralize them in
            //starting in the middle
            this.xMax = boundaries.Right;
            this.xMin = boundaries.Left;
            this.yMax = boundaries.Top;
            this.yMin = boundaries.Bottom;

            this.invaders = new List <Invader>();

            //Initializing the shots
            this.playerShots = playerShots;
            this.enemyShots  = enemyShots;


            this.random       = random;
            this.boundaries   = boundaries;
            this.invadersLeft = 30;



            for (int i = 0; i < 6; i++)
            {
                // int xcoordinate=(xMax+xMin)/2-(3+i)*(HorizontalInterval+pictureWidth);
                int xcoordinate = 200 + (i) * (HorizontalInterval + pictureWidth);



                invaders.Add(new Invader("bug", new Point(xcoordinate, 0), 10));
                invaders.Add(new Invader("flyingsaucer", new Point(xcoordinate, pictureHeight + 10), 20));
                invaders.Add(new Invader("satellite", new Point(xcoordinate, pictureHeight + 70), 30));
                invaders.Add(new Invader("watchit", new Point(xcoordinate, pictureHeight + 130), 40));
                invaders.Add(new Invader("star", new Point(xcoordinate, pictureHeight + 190), 50));
            }
        }