Ejemplo n.º 1
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 && currentLevel == 1)
            {
                timerRandomShoot.Stop();

                Level2 lv2 = new Level2(this.window, this.canvas, this.player);
                lv2.setLoad(true);
                lv2.Play();
            }
            else if (this.enemies.Count == 0 && currentLevel == 2)
            {
                if (round < 3)
                {
                    round++;
                    Level2 lv2 = new Level2(this.window, this.canvas, this.player);
                    lv2.setRound(round);
                    lv2.setLoad(true);
                    lv2.Play();
                }
                else
                {
                    if (round == 3)
                    {
                        Level3 lv3 = new Level3(this.window, this.canvas, this.player);
                        lv3.Play();
                    }
                }
            }
        }