Exemple #1
0
        /********************************************************************
         * DrawingPanel_MouseClick: sets missile destination from user click
         **********************************************************************/
        private void DrawingPanel_MouseClick(object sender, MouseEventArgs e)
        {
            Graphics g = Graphics.FromImage(myCanvas);

            if (e.Y < newBase.get_base_height())//missile cannot fire below base
            {
                //create line from the appropriate starting point to click location
                PointF fire_point = newBase.get_closest_point(e.Location);
                current_missile_line = new Line10C(Color.Blue, 2, fire_point, e.Location);
                for (int i = 0; i < 3; i++)
                {
                    if (fire_point == newBase.get_base_point(i) && newBase.base_disable[i] == false)
                    {
                        missile_list.Add(current_missile_line);
                        newBase.minus_base_missiles(i, 1);
                        mis_player.Play();
                    }
                }
            }
        }
        /**************************************************************************
         * glob_time_Tick: separate timer to set spawning of enemy missiles & bomber
         *                 also handles losing & winning conditions
         **************************************************************************/
        private void glob_time_Tick(object sender, EventArgs e)
        {
            Graphics g = Graphics.FromImage(myCanvas);
            int rand_count = rand1.Next(1, 5);//random count of enemy missiles
            int rand_chance = 0;//enemy target locations
            int cluster_chance = 0;//chance that missile is a cluster bomb
            int rand_bomber = rand1.Next(0, 100);//chance that there's a bomber
            int rand_start = 0;//rand starting location
            PointF start_point = new PointF();
            List<PointF> enemy_order = new List<PointF>();
            enemy_order = generate_enemy_list();
            bool pop_up_once = false;//winning condition

            if (!six_cities.allcitydisabled())//cities still standing
            {   //condition for next level for when level has ended and all missiles reached destination
                if (time_to_next_level > difficulty && wait_for_level_over)
                {
                    time_to_next_level = 0;
                    level++;//update level
                    newgame = true;
                    g.Clear(Color.Black);
                    explosion_list.Clear();
                    enemy_missile_list.Clear();
                    bomber_list.Clear();
                    missile_list.Clear();
                    difficulty++;
                    pop_up_once = true;//for case when user goes over 100 levels
                }
                else if (time_to_next_level > difficulty) end_of_level = true; //level has ended
                else if (wait_for_level_over == false && time_to_next_level <= difficulty)//level not over
                {
                    for (int i = 0; i < rand_count; i++)//random spawns
                    {
                        rand_start = rand1.Next(50, DrawingPanel.Width - 50);
                        rand_chance = rand1.Next(0, 9);//9choices to for enemies to hit
                        cluster_chance = rand1.Next(0, 100);//chance that bomb is a cluster bomb
                        start_point = new PointF((float)rand_start, 0);//random starting location
                        Line10C enemy = new Line10C(Color.Red, 2, start_point, enemy_order[rand_chance]);
                        if (cluster_chance < 10)//10% chance that bomb is a cluster bomb
                        {
                            enemy.set_cluster(true);
                        }
                        enemy_missile_list.Add(enemy);
                    }
                    if (rand_bomber < 20)//add a bomber
                    {
                        bomber_list.Add(new Bomber(new PointF(-5, 100)));
                    }
                    time_to_next_level++;//one round of enemy spawn
                    newgame = false;
                }

            }
            else//player lost
            {
                LosingCondition(g, sender, e);
            }

            //winning conditions for players who go over level 100
            Font myfont = new Font("Courier New", 60, FontStyle.Bold, GraphicsUnit.Pixel);
            if (level > 100 && pop_up_once)
            {
                pop_up_once = false;
                glob_time.Stop();
                missile_timer.Stop();
                explosion_timer.Stop();
                g.Clear(Color.Red);
                g.DrawString("YOU WIN", myfont, new SolidBrush(Color.Blue), DrawingPanel.Width / 2 - 160, DrawingPanel.Height / 2 - 50);
                DrawingPanel.Invalidate();
                DialogResult you_win;
                you_win = MessageBox.Show("Would you like to play another game?", "You Win",
                        MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (you_win == DialogResult.Yes)//start new game
                {//clear lists and restart counters
                    explosion_list.Clear();
                    enemy_missile_list.Clear();
                    bomber_list.Clear();
                    missile_list.Clear();
                    wait_for_level_over = false;
                    end_of_level = false;
                    newgame = false;
                    wait_counter = 0;
                    time_to_next_level = 0;
                    difficulty = 1;
                    mc_Form_Load(sender, e);
                }
                else this.Close();
            }

            enemy_order.Clear();
            glob_time.Interval = 5000;
        }
 /********************************************************************
  * DrawingPanel_MouseClick: sets missile destination from user click
  **********************************************************************/
 private void DrawingPanel_MouseClick(object sender, MouseEventArgs e)
 {
     Graphics g = Graphics.FromImage(myCanvas);
     if (e.Y < newBase.get_base_height())//missile cannot fire below base
     {
         //create line from the appropriate starting point to click location
         PointF fire_point = newBase.get_closest_point(e.Location);
         current_missile_line = new Line10C(Color.Blue, 2, fire_point, e.Location);
         for (int i = 0; i < 3; i++)
         {
             if (fire_point == newBase.get_base_point(i) && newBase.base_disable[i] == false)
             {
                 missile_list.Add(current_missile_line);
                 newBase.minus_base_missiles(i, 1);
                 mis_player.Play();
             }
         }
     }
 }
Exemple #4
0
        /**************************************************************************
        * glob_time_Tick: separate timer to set spawning of enemy missiles & bomber
        *                 also handles losing & winning conditions
        **************************************************************************/
        private void glob_time_Tick(object sender, EventArgs e)
        {
            Graphics      g              = Graphics.FromImage(myCanvas);
            int           rand_count     = rand1.Next(1, 5);   //random count of enemy missiles
            int           rand_chance    = 0;                  //enemy target locations
            int           cluster_chance = 0;                  //chance that missile is a cluster bomb
            int           rand_bomber    = rand1.Next(0, 100); //chance that there's a bomber
            int           rand_start     = 0;                  //rand starting location
            PointF        start_point    = new PointF();
            List <PointF> enemy_order    = new List <PointF>();

            enemy_order = generate_enemy_list();
            bool pop_up_once = false;//winning condition


            if (!six_cities.allcitydisabled()) //cities still standing
            {                                  //condition for next level for when level has ended and all missiles reached destination
                if (time_to_next_level > difficulty && wait_for_level_over)
                {
                    time_to_next_level = 0;
                    level++;//update level
                    newgame = true;
                    g.Clear(Color.Black);
                    explosion_list.Clear();
                    enemy_missile_list.Clear();
                    bomber_list.Clear();
                    missile_list.Clear();
                    difficulty++;
                    pop_up_once = true;//for case when user goes over 100 levels
                }
                else if (time_to_next_level > difficulty)
                {
                    end_of_level = true;                                                   //level has ended
                }
                else if (wait_for_level_over == false && time_to_next_level <= difficulty) //level not over
                {
                    for (int i = 0; i < rand_count; i++)                                   //random spawns
                    {
                        rand_start     = rand1.Next(50, DrawingPanel.Width - 50);
                        rand_chance    = rand1.Next(0, 9);                 //9choices to for enemies to hit
                        cluster_chance = rand1.Next(0, 100);               //chance that bomb is a cluster bomb
                        start_point    = new PointF((float)rand_start, 0); //random starting location
                        Line10C enemy = new Line10C(Color.Red, 2, start_point, enemy_order[rand_chance]);
                        if (cluster_chance < 10)                           //10% chance that bomb is a cluster bomb
                        {
                            enemy.set_cluster(true);
                        }
                        enemy_missile_list.Add(enemy);
                    }
                    if (rand_bomber < 20)//add a bomber
                    {
                        bomber_list.Add(new Bomber(new PointF(-5, 100)));
                    }
                    time_to_next_level++;//one round of enemy spawn
                    newgame = false;
                }
            }
            else//player lost
            {
                LosingCondition(g, sender, e);
            }


            //winning conditions for players who go over level 100
            Font myfont = new Font("Courier New", 60, FontStyle.Bold, GraphicsUnit.Pixel);

            if (level > 100 && pop_up_once)
            {
                pop_up_once = false;
                glob_time.Stop();
                missile_timer.Stop();
                explosion_timer.Stop();
                g.Clear(Color.Red);
                g.DrawString("YOU WIN", myfont, new SolidBrush(Color.Blue), DrawingPanel.Width / 2 - 160, DrawingPanel.Height / 2 - 50);
                DrawingPanel.Invalidate();
                DialogResult you_win;
                you_win = MessageBox.Show("Would you like to play another game?", "You Win",
                                          MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (you_win == DialogResult.Yes) //start new game
                {                                //clear lists and restart counters
                    explosion_list.Clear();
                    enemy_missile_list.Clear();
                    bomber_list.Clear();
                    missile_list.Clear();
                    wait_for_level_over = false;
                    end_of_level        = false;
                    newgame             = false;
                    wait_counter        = 0;
                    time_to_next_level  = 0;
                    difficulty          = 1;
                    mc_Form_Load(sender, e);
                }
                else
                {
                    this.Close();
                }
            }

            enemy_order.Clear();
            glob_time.Interval = 5000;
        }