Ejemplo n.º 1
0
        /// <summary>
        /// The Play Method creates and displays all enemies and the player on
        /// the Canvas (screen).
        /// </summary>
        public async void Play()
        {
            Player.ColdDown = 0;

            DisplayLevel();
            await Task.Delay(2000);

            this.canvas.Children.Remove(lv1Pic);


            lv1Pic        = new Image();
            lv1Pic.Height = 40;
            lv1Pic.Width  = 100;
            this.canvas.Children.Add(lv1Pic);
            lv1Pic.Source = UtilityMethods.LoadImage("pics/level1.png");

            //bee creation
            BitmapImage[] beeImages = { UtilityMethods.LoadImage("pics/bee0.png"),
                                        UtilityMethods.LoadImage("pics/bee1.png") };
            Image[]       beesPic = new Image[8];
            //int spaceX = 0;
            bool isDive = false;

            Bug[] bees = new Bug[beesPic.Length];
            for (int i = 0; i < beesPic.Length; i++)
            {
                beesPic[i]        = new Image();
                beesPic[i].Width  = 34;
                beesPic[i].Height = 26;
                canvas.Children.Add(beesPic[i]);
                Canvas.SetLeft(beesPic[i], 181 + spaceX);
                Canvas.SetTop(beesPic[i], 185);
                spaceX += 60;

                Point beePos = new Point();
                beePos.X = Canvas.GetLeft(beesPic[i]);
                beePos.Y = Canvas.GetTop(beesPic[i]);
                Animation beeAnimation = new Animation(beesPic[i], beeImages, true);
                Bug       bee          = new Bug(beePos, beesPic[i], canvas, beeAnimation);
                bees[i] = bee;
                enemies.Add(bees[i]);
                bees[i].setTarget(player);
                bees[i].setDive(isDive);

                if (isDive)
                {
                    isDive = false;
                }
                else
                {
                    isDive = true;
                }

                bees[i].Fly(300);
            }

            //---------------------------------------------------------------------------
            //red bugs creation
            BitmapImage[] bugImages = { UtilityMethods.LoadImage("pics/redBug0.png"),
                                        UtilityMethods.LoadImage("pics/redBug1.png") };
            Image[]       bugsPic = new Image[9];
            isDive = false;
            Bug[] redbugs = new Bug[bugsPic.Length];
            spaceX = 0;
            for (int i = 0; i < bugsPic.Length; i++)
            {
                bugsPic[i]        = new Image();
                bugsPic[i].Width  = 34;
                bugsPic[i].Height = 26;
                canvas.Children.Add(bugsPic[i]);
                Canvas.SetLeft(bugsPic[i], 154 + spaceX);
                Canvas.SetTop(bugsPic[i], 145);
                spaceX += 60;

                Point bugPos = new Point();
                bugPos.X = Canvas.GetLeft(bugsPic[i]);
                bugPos.Y = Canvas.GetTop(bugsPic[i]);
                Animation bugAnimation = new Animation(bugsPic[i], bugImages, true);
                Bug       bug          = new Bug(bugPos, bugsPic[i], canvas, bugAnimation);
                redbugs[i] = bug;
                enemies.Add(redbugs[i]);
                redbugs[i].setTarget(player);
                redbugs[i].setDive(isDive);

                if (isDive)
                {
                    isDive = false;
                }
                else
                {
                    isDive = true;
                }

                redbugs[i].Fly(300);
            }

            //---------------------------------------------------------------------------
            //spaceships creation
            Image[] shipsPic = new Image[8];
            ships  = new SpaceShip[shipsPic.Length];
            spaceX = 0;
            for (int i = 0; i < ships.Length; i++)
            {
                shipsPic[i]        = new Image();
                shipsPic[i].Source = UtilityMethods.LoadImage("pics/spaceShip.png");
                shipsPic[i].Width  = 34;
                shipsPic[i].Height = 26;
                canvas.Children.Add(shipsPic[i]);
                Canvas.SetLeft(shipsPic[i], 181 + spaceX);
                Canvas.SetTop(shipsPic[i], 105);
                spaceX += 60;

                Point shipPos = new Point();
                shipPos.X = Canvas.GetLeft(shipsPic[i]);
                shipPos.Y = Canvas.GetTop(shipsPic[i]);

                SpaceShip ship = new SpaceShip(shipPos, shipsPic[i], canvas);
                ships[i] = ship;
                enemies.Add(ships[i]);
                ships[i].setTarget(player);
                ships[i].Fly(300);
            }

            //----------------------------------------------------------------------------
            //commanders creation
            BitmapImage[] commanderImages = { UtilityMethods.LoadImage("pics/commander.png"),
                                              UtilityMethods.LoadImage("pics/commander2.png") };
            Image[]       commanderPic = new Image[4];
            commanders = new Commander[commanderPic.Length];
            spaceX     = 0;
            for (int i = 0; i < commanderPic.Length; i++)
            {
                commanderPic[i]        = new Image();
                commanderPic[i].Width  = 34;
                commanderPic[i].Height = 26;
                canvas.Children.Add(commanderPic[i]);
                Canvas.SetLeft(commanderPic[i], 260 + spaceX);
                Canvas.SetTop(commanderPic[i], 65);
                spaceX += 90;

                Point commanderPos = new Point();
                commanderPos.X = Canvas.GetLeft(commanderPic[i]);
                commanderPos.Y = Canvas.GetTop(commanderPic[i]);
                Animation commanderAnimation = new Animation(commanderPic[i], commanderImages, true);
                Commander commander          = new Commander(commanderPos, commanderPic[i], canvas, commanderAnimation);
                commanders[i] = commander;
                enemies.Add(commanders[i]);
                commanders[i].setTarget(player);
                commanders[i].Fly(300);
            }

            player.SetEnemyTarget(enemies);
            StartGame();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// The Play Method creates and displays all enemies and the player on
        /// the Canvas (screen).
        /// </summary>
        public async void Play()
        {
            Player.ColdDown = 0;

            if (this.round == 1)
            {
                DisplayLevel();
                await Task.Delay(2000);

                this.canvas.Children.Remove(lv3Pic);
            }
            else
            {
                this.shipsNum = new List <int>()
                {
                    0, 1, 2, 3, 4, 5, 6, 7
                };
                this.commandersNum = new List <int>()
                {
                    0, 1, 2, 3
                };
                this.ufosNum = new List <int>()
                {
                    0, 1, 2, 3, 4
                };
                this.exists1 = false;
                this.exists2 = false;
                this.exists3 = false;
                this.spaceX  = 0;

                await Task.Delay(1500);
            }


            lv3Pic        = new Image();
            lv3Pic.Height = 40;
            lv3Pic.Width  = 100;
            this.canvas.Children.Add(lv3Pic);
            lv3Pic.Source = UtilityMethods.LoadImage("pics/level3.png");

            //bee creation
            BitmapImage[] beeImages = { UtilityMethods.LoadImage("pics/bee0.png"),
                                        UtilityMethods.LoadImage("pics/bee1.png") };
            Image[]       beesPic = new Image[8];
            //int spaceX = 0;
            bool isDive = false;

            Bug[] bees = new Bug[beesPic.Length];
            for (int i = 0; i < beesPic.Length; i++)
            {
                beesPic[i]        = new Image();
                beesPic[i].Width  = 34;
                beesPic[i].Height = 26;
                canvas.Children.Add(beesPic[i]);
                Canvas.SetLeft(beesPic[i], 181 + spaceX);
                Canvas.SetTop(beesPic[i], 185);
                spaceX += 60;

                Point beePos = new Point();
                beePos.X = Canvas.GetLeft(beesPic[i]);
                beePos.Y = Canvas.GetTop(beesPic[i]);
                Animation beeAnimation = new Animation(beesPic[i], beeImages, true);
                Bug       bee          = new Bug(beePos, beesPic[i], canvas, beeAnimation);
                bees[i] = bee;
                enemies.Add(bees[i]);
                bees[i].setTarget(player);
                bees[i].setDive(isDive);

                if (isDive)
                {
                    isDive = false;
                }
                else
                {
                    isDive = true;
                }

                bees[i].setDiveFrequency(10);
                bees[i].setMoveDownFrequency(45);
                bees[i].Fly(130);
            }

            //---------------------------------------------------------------------------
            //redbugs creation
            BitmapImage[] bugImages = { UtilityMethods.LoadImage("pics/redBug0.png"),
                                        UtilityMethods.LoadImage("pics/redBug1.png") };
            Image[]       bugsPic = new Image[9];
            Bug[]         redbugs = new Bug[bugsPic.Length];
            spaceX = 0;
            isDive = false;
            for (int i = 0; i < bugsPic.Length; i++)
            {
                bugsPic[i]        = new Image();
                bugsPic[i].Width  = 34;
                bugsPic[i].Height = 26;
                canvas.Children.Add(bugsPic[i]);
                Canvas.SetLeft(bugsPic[i], 154 + spaceX);
                Canvas.SetTop(bugsPic[i], 145);
                spaceX += 60;

                Point bugPos = new Point();
                bugPos.X = Canvas.GetLeft(bugsPic[i]);
                bugPos.Y = Canvas.GetTop(bugsPic[i]);
                Animation bugAnimation = new Animation(bugsPic[i], bugImages, true);
                Bug       bug          = new Bug(bugPos, bugsPic[i], canvas, bugAnimation);
                redbugs[i] = bug;
                enemies.Add(redbugs[i]);
                redbugs[i].setTarget(player);
                redbugs[i].setDive(isDive);

                if (isDive)
                {
                    isDive = false;
                }
                else
                {
                    isDive = true;
                }

                redbugs[i].setDiveFrequency(10);
                redbugs[i].setMoveDownFrequency(45);
                redbugs[i].setMoveCounter(2);
                redbugs[i].Fly(130);
            }

            //---------------------------------------------------------------------------
            //ships creation
            Image[] shipsPic = new Image[8];
            ships  = new SpaceShip[shipsPic.Length];
            isDive = false;
            spaceX = 0;
            for (int i = 0; i < ships.Length; i++)
            {
                shipsPic[i]        = new Image();
                shipsPic[i].Source = UtilityMethods.LoadImage("pics/spaceShip.png");
                shipsPic[i].Width  = 34;
                shipsPic[i].Height = 26;
                canvas.Children.Add(shipsPic[i]);
                Canvas.SetLeft(shipsPic[i], 181 + spaceX);
                Canvas.SetTop(shipsPic[i], 105);
                spaceX += 60;

                Point shipPos = new Point();
                shipPos.X = Canvas.GetLeft(shipsPic[i]);
                shipPos.Y = Canvas.GetTop(shipsPic[i]);

                SpaceShip ship = new SpaceShip(shipPos, shipsPic[i], canvas);
                ships[i] = ship;
                enemies.Add(ships[i]);
                ships[i].setTarget(player);
                ships[i].setDive(isDive);

                if (isDive)
                {
                    isDive = false;
                }
                else
                {
                    isDive = true;
                }

                ships[i].setDiveFrequency(10);
                ships[i].setMoveDownFrequency(45);
                ships[i].Fly(130);
            }

            //---------------------------------------------------------------------------
            //UFO creation
            Image[] ufoPics = new Image[5];
            this.ufos = new SpaceShip[ufoPics.Length];
            isDive    = false;
            spaceX    = 0;
            for (int i = 0; i < ufoPics.Length; i++)
            {
                ufoPics[i]        = new Image();
                ufoPics[i].Source = UtilityMethods.LoadImage("pics/UFO.png");
                ufoPics[i].Width  = 34;
                ufoPics[i].Height = 26;
                canvas.Children.Add(ufoPics[i]);
                Canvas.SetLeft(ufoPics[i], 200 + spaceX);
                Canvas.SetTop(ufoPics[i], 65);
                spaceX += 60;

                Point ufoPos = new Point();
                ufoPos.X = Canvas.GetLeft(ufoPics[i]);
                ufoPos.Y = Canvas.GetTop(ufoPics[i]);

                SpaceShip ufo = new SpaceShip(ufoPos, ufoPics[i], canvas);
                ufos[i] = ufo;
                enemies.Add(ufos[i]);
                ufos[i].setTarget(player);
                ufos[i].setMoveCounter(2);
                ufos[i].setDive(isDive);

                if (isDive)
                {
                    isDive = false;
                }
                else
                {
                    isDive = true;
                }

                ufos[i].setDiveFrequency(10);
                ufos[i].setMoveDownFrequency(45);
                ufos[i].Fly(130);
            }

            //---------------------------------------------------------------------------
            //commanders creation
            BitmapImage[] commanderImages = { UtilityMethods.LoadImage("pics/commander.png"),
                                              UtilityMethods.LoadImage("pics/commander2.png") };
            Image[]       commanderPic = new Image[4];
            commanders = new Commander[commanderPic.Length];
            spaceX     = 0;
            for (int i = 0; i < commanderPic.Length; i++)
            {
                commanderPic[i] = new Image();
                //commanderPic[i].Source = UtilityMethods.LoadImage("pics/spaceShip.png");
                commanderPic[i].Width  = 34;
                commanderPic[i].Height = 26;
                canvas.Children.Add(commanderPic[i]);
                Canvas.SetLeft(commanderPic[i], 260 + spaceX);
                Canvas.SetTop(commanderPic[i], 30);
                spaceX += 90;

                Point commanderPos = new Point();
                commanderPos.X = Canvas.GetLeft(commanderPic[i]);
                commanderPos.Y = Canvas.GetTop(commanderPic[i]);
                Animation commanderAnimation = new Animation(commanderPic[i], commanderImages, true);
                Commander commander          = new Commander(commanderPos, commanderPic[i], canvas, commanderAnimation);
                commanders[i] = commander;
                enemies.Add(commanders[i]);
                commanders[i].setTarget(player);
                commanders[i].setMoveDownFrequency(45);
                commanders[i].Fly(130);
            }
            player.SetEnemyTarget(enemies);
            StartGame();
        }