Example #1
0
 public LoadLevels(int coins, int lives, int level)
 {
     if (level == 4)
     {
         Level4 lv4 = new Level4(window, canvas, player);
     }
 }
Example #2
0
        public LoadLevels(List <int> shipInt, List <Point> shipPoint, List <String> shipPath,
                          List <int> commanderInt, List <Point> commanderPoint, List <String> commanderPath,
                          List <int> bugInt, List <Point> bugPoint, List <String> bugPath,
                          Canvas canvas, Window window, List <double> minXShip,
                          List <double> maxXShip,
                          List <double> minXCom,
                          List <double> maxXCom,
                          List <double> minXBug,
                          List <double> maxXBug, int coins, int lives, int level)
        {
            this.canvas = canvas;
            this.lives  = lives;
            this.coins  = coins;
            this.level  = level;
            this.window = window;


            Image playerPic = new Image();

            playerPic.Source = UtilityMethods.LoadImage("pics/galaga_ship.png");
            playerPic.Width  = 42;
            playerPic.Height = 46;
            canvas.Children.Add(playerPic);
            Canvas.SetLeft(playerPic, 405);
            Canvas.SetTop(playerPic, 500);
            Point playerPoint = new Point(27, 490);

            player = new Player(playerPoint, playerPic, canvas, 15, lives, coins);

            staticPlayer = player;
            player.setCurrentLevel(level);
            player.setCoins(coins);
            player.setLives(lives);
            staticPlayer.setCurrentLevel(level);
            staticPlayer.setCoins(coins);
            staticPlayer.setLives(lives);

            if (level < 4)
            {
                this.commanderPic = new Image[commanderPath.Count];
                loadCommanders(commanderInt, commanderPoint, commanderPath, minXCom, maxXCom, player);
                loadShip(shipInt, shipPoint, shipPath, maxXShip, minXShip, player);
                loadBug(bugInt, bugPoint, bugPath, maxXBug, minXBug, player);

                player.SetEnemyTarget(enemies);


                newPlayer = new Player(player);
                StartGame();
            }
            else
            {
                Level4 lv4 = new Level4(window, canvas, player);
                lv4.Play();
            }
        }
Example #3
0
 private void saveBtn_Click(object sender, RoutedEventArgs e)
 {
     // MessageBox.Show(""+LoadLevels.getStaticPlayer().getCurrentLevel());
     //MessageBox.Show("" + player.getCurrentLevel());
     if (loaded)
     {
         if (LoadLevels.getStaticPlayer().getCurrentLevel() == 1)
         {
             lv1.saveLevel1();
         }
         else if (LoadLevels.getStaticPlayer().getCurrentLevel() == 2)
         {
             Level2.saveLevel2(this.player, true);
         }
         else if (LoadLevels.getStaticPlayer().getCurrentLevel() == 3)
         {
             Level3.saveLevel3(this.player, true);
         }
         else if (LoadLevels.getStaticPlayer().getCurrentLevel() == 4)
         {
             Level4.saveLevel4(this.player, true);
         }
     }
     else
     {
         if (player.getCurrentLevel() == 1)
         {
             lv1.saveLevel1();
         }
         else if (player.getCurrentLevel() == 2)
         {
             Level2.saveLevel2(this.player, false);
         }
         else if (player.getCurrentLevel() == 3)
         {
             Level3.saveLevel3(this.player, false);
         }
         else if (player.getCurrentLevel() == 4)
         {
             Level4.saveLevel4(this.player, false);
         }
     }
 }
Example #4
0
        /// <summary>
        /// The shootUpdate method controls randomly the
        /// shooting of the enemies.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ShootUpdate(object sender, EventArgs e)
        {
            //-------------------------------
            for (int i = 0; i < ships.Length; i++)
            {
                if (ships[i].IsDead() == true)
                {
                    shipsNum.Remove(i);
                }
            }

            for (int i = 0; i < commanders.Length; i++)
            {
                if (commanders[i].IsDead() == true)
                {
                    commandersNum.Remove(i);
                }
            }

            for (int i = 0; i < ufos.Length; i++)
            {
                if (ufos[i].IsDead() == true)
                {
                    ufosNum.Remove(i);
                }
            }

            //--------------------------------
            Random rand = new Random();
            int    num1 = rand.Next(ships.Length);

            if (shipsNum.Contains(num1))
            {
                shipsNum.Remove(num1);
                exists1 = true;
            }
            if (exists1 == true)
            {
                if (ships[num1].IsDead() == true)
                {
                    shipsNum.Remove(num1);
                }
                else
                {
                    if (ships[num1].isShoot() == false)
                    {
                        ships[num1].Shoot(6);
                    }
                }

                exists1 = false;
            }

            //------------------------------------
            int num2 = rand.Next(commanders.Length);

            if (commandersNum.Contains(num2))
            {
                exists2 = true;
                commandersNum.Remove(num2);
            }
            if (exists2 == true)
            {
                if (commanders[num2].IsDead() == true)
                {
                    commandersNum.Remove(num2);
                }
                else
                {
                    if (commanders[num2].isShoot() == false)
                    {
                        commanders[num2].Shoot(11);
                    }
                }
                exists2 = false;
            }

            //------------------------------------
            int num3 = rand.Next(ufos.Length);

            if (ufosNum.Contains(num3))
            {
                exists3 = true;
                ufosNum.Remove(num3);
            }
            if (exists3 == true)
            {
                if (ufos[num3].IsDead() == true)
                {
                    ufosNum.Remove(num3);
                }
                else
                {
                    if (ufos[num3].isShoot() == false)
                    {
                        ufos[num3].Shoot(3);
                    }
                }
                exists3 = false;
            }

            //----------------------------------------
            if (this.enemies.Count == 0)
            {
                this.canvas.Children.Remove(lv3Pic);

                timerRandomShoot.Stop();
                if (this.round == 1 || this.round == 2)
                {
                    round++;
                    Play();
                }
                else
                {
                    Level4 lv4 = new Level4(this.window, this.canvas, this.player);
                    lv4.Play();
                }
            }
        }
Example #5
0
        private void ShootUpdate(object sender, EventArgs e)
        {
            BackToMainWindown();
            //-------------------------------
            for (int i = 0; i < ships.Count; i++)
            {
                if (ships[i].IsDead() == true)
                {
                    arr1.Remove(i);
                }
            }

            for (int i = 0; i < commanders.Count; i++)
            {
                if (commanders[i].IsDead() == true)
                {
                    arr2.Remove(i);
                }
            }

            //--------------------------------
            Random rand = new Random();
            int    num1 = rand.Next(ships.Count);//8

            if (arr1.Contains(num1))
            {
                arr1.Remove(num1);
                exists1 = true;
            }
            if (exists1 == true)
            {
                if (ships[num1].IsDead() == true)
                {
                    arr1.Remove(num1);
                }
                else
                {
                    if (ships[num1].isShoot() == false)
                    {
                        ships[num1].Shoot(10);
                    }
                }

                exists1 = false;
            }

            //------------------------------------
            int num2 = rand.Next(4);

            if (arr2.Contains(num2))
            {
                exists2 = true;
                arr2.Remove(num2);
            }
            if (exists2 == true)
            {
                if (commanders[num2].IsDead() == true)
                {
                    arr2.Remove(num2);
                }
                else
                {
                    if (commanders[num2].isShoot() == false)
                    {
                        commanders[num2].Shoot(20);
                    }
                }
                exists2 = false;
            }

            //----------------------------------------
            if (enemies.Count == 0 && level == 1)
            {
                timerRandomShoot.Stop();

                Level2 lv2 = new Level2(this.window, this.canvas, this.player);
                lv2.setLoad(true);
                staticPlayer.updateCurrentLevel(2);
                lv2.Play();
            }
            else if (this.enemies.Count == 0 && level == 2)
            {
                if (round < 2)
                {
                    timerRandomShoot.Stop();

                    round++;
                    Level2 lv2 = new Level2(this.window, this.canvas, this.player);
                    lv2.setRound(round);
                    lv2.setLoad(true);
                    lv2.Play();
                }
                else
                {
                    if (round == 2)
                    {
                        timerRandomShoot.Stop();

                        Level3 lv3 = new Level3(this.window, this.canvas, this.player);
                        lv3.Play();
                    }
                }
            }
            else if (this.enemies.Count == 0 && level == 3)

            {
                if (round < 3)
                {
                    timerRandomShoot.Stop();

                    round++;
                    Level3 lv3 = new Level3(this.window, this.canvas, this.player);
                    lv3.setRound(round);
                    lv3.setLoad(true);
                    lv3.Play();
                }
                else
                {
                    if (round == 3)
                    {
                        timerRandomShoot.Stop();

                        Level4 lv4 = new Level4(this.window, this.canvas, this.player);
                        lv4.Play();
                    }
                }
            }
        }