Пример #1
0
        private void draw_it()
        {
            Color clr_clear = this.pictureBox1.BackColor;

            while (this.stop_this)
            {
                // gr.Clear(clr_clear);
                for (int ind = fishka.Count; ind > 0; ind--)
                {
                    try
                    {
                        fish cur_fish = this.fishka[ind - 1];

                        if (cur_fish.live_count <= 0)
                        {
                            //                            this.clear(clr_clear, cur_fish, gr);
                        }
                        else
                        {
                            //  this.clear(clr_clear, cur_fish, gr);
                            cur_fish.x_coord = cur_fish.x_coord_next;
                            cur_fish.y_coord = cur_fish.y_coord_next;
                            Brush br = new SolidBrush(cur_fish.fish_clr);
                            gr.FillEllipse(br, cur_fish.x_coord, cur_fish.y_coord, cur_fish.size, cur_fish.size);
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }
                this.need_2_update = true;
            }
        }
Пример #2
0
        private void trd_st(object f)
        {
            fish fs = f as fish;

            fs.timer++;
            fs.live_count--;
            fs.repl_curr++;
            if (((int)this.x_gl == (int)fs.x_coord) && ((int)this.y_gl == (int)fs.y_coord))
            {
                this.x_gl = rnd.Next((int)fs.max_size, this.pictureBox1.Size.Width - (int)fs.max_size);
                this.y_gl = rnd.Next((int)fs.max_size, this.pictureBox1.Size.Height - (int)fs.max_size);
                if (this.x_gl > (this.pictureBox1.Size.Width - fs.size))
                {
                    this.x_gl = (int)(this.pictureBox1.Size.Width - fs.size);
                }
                if (this.y_gl > (this.pictureBox1.Size.Height - fs.size))
                {
                    this.y_gl = (int)(this.pictureBox1.Size.Height - fs.size);
                }
            }
            if ((fs.predator_lvl == 0) && (Math.Abs((Math.Sqrt((double)(fs.x_dest * fs.x_dest + fs.y_dest * fs.y_dest)) - (Math.Sqrt((double)(fs.x_coord * fs.x_coord + fs.y_coord * fs.y_coord))))) <= fs.speed))
            {
                fs.x_dest = this.x_gl;
                fs.y_dest = this.y_gl;
            }

            // if not target for predator try to random point
            if ((fs.predator_lvl > 0) && (fs.victim_finded == null) && (Math.Sqrt((fs.x_dest - fs.x_coord) * (fs.x_dest - fs.x_coord) + (fs.y_dest - fs.y_coord) * (fs.y_dest - fs.y_coord))) < fs.speed)
            {
                fs.x_dest = rnd.Next((int)fs.max_size, this.pictureBox1.Size.Width - (int)fs.max_size);
                fs.y_dest = rnd.Next((int)fs.max_size, this.pictureBox1.Size.Height - (int)fs.max_size);
            }



            if (((int)fs.x_dest != (int)fs.x_coord) && ((int)fs.y_dest != (int)fs.y_coord))
            {
                fs.mooving(this.pictureBox1.BackColor, Color.Green);
            }
            else
            {
                if (fs.predator_lvl == 0)
                {
                    this.x_gl = rnd.Next((int)fs.max_size, this.pictureBox1.Size.Width - (int)fs.max_size);
                    this.y_gl = rnd.Next((int)fs.max_size, this.pictureBox1.Size.Height - (int)fs.max_size);
                    if (this.x_gl > (this.pictureBox1.Size.Width - fs.size))
                    {
                        this.x_gl = (int)(this.pictureBox1.Size.Width - fs.size);
                    }
                    if (this.y_gl > (this.pictureBox1.Size.Height - fs.size))
                    {
                        this.y_gl = (int)(this.pictureBox1.Size.Height - fs.size);
                    }

                    fs.x_dest = this.x_gl;
                    fs.y_dest = this.y_gl;
                }
            }
        }
Пример #3
0
        private void clear(Color clr, fish crnt_fish, Graphics gr)
        {
            Brush br = new SolidBrush(Color.FromArgb(15, clr.R, clr.G, clr.B));

            //            this.gr.FillRectangle(br, crnt_fish.x_coord, crnt_fish.y_coord, crnt_fish.size, crnt_fish.size);
            this.gr.FillRectangle(br, 0, 0, this.pictureBox1.Width, this.pictureBox1.Height); //, crnt_fish.size, crnt_fish.size);
                                                                                              //            this.gr.Clear(Color.FromArgb(240, clr.R, clr.G, clr.B));
        }
Пример #4
0
 private void main()
 {
     while (this.stop_this)
     {
         Invoke((MethodInvoker) delegate
         {
             this.label1.Text = "Settlers (0)= " + this.fishka.FindAll(fishka => fishka.predator_lvl == 0).Count.ToString() +
                                " (1)= " + this.fishka.FindAll(fishka => fishka.predator_lvl == 1).Count.ToString() + " (2)= " + this.fishka.FindAll(fishka => fishka.predator_lvl == 2).Count.ToString();
             this.label1.Update();
         });
         if (this.fishka.Count == 0)
         {
             this.stop_this = !this.stop_this;
         }
         //                this.pictureBox1.SuspendLayout();
         for (int ind = fishka.Count; ind > 0; ind--)
         {
             fish cur_fish = this.fishka[ind - 1];
             //                   Thread tr = new Thread(trd_st);
             //                    tr.Start(cur_fish);
             trd_st(cur_fish);
             if (cur_fish.repl_curr >= cur_fish.repl_count)
             {
                 if (this.fishka.Count < 5000)
                 {
                     this.fishka.Add(new fish(cur_fish.start_size, cur_fish.start_speed, cur_fish.predator_lvl,
                                              rnd.Next((int)(cur_fish.live_start * 0.99), (int)(cur_fish.live_start * 1.01)),
                                              rnd.Next((int)(cur_fish.start_repl * 0.99), (int)(cur_fish.start_repl * 1.01)),
                                              cur_fish.strenght_start, cur_fish.fld_view, cur_fish.x_coord, cur_fish.y_coord, cur_fish.x_dest, cur_fish.y_dest,
                                              cur_fish.max_size, cur_fish.max_speed, cur_fish.fish_clr));
                 }
                 cur_fish.repl_curr = 0;
             }
             if (cur_fish.live_count < 0)
             {
                 fishka.RemoveAt(ind - 1);
             }
         }
         //                this.pictureBox1.ResumeLayout();
         Thread.Sleep(1);
     }
     Thread.CurrentThread.Abort();
     return;
 }
Пример #5
0
        private void vic_finder()
        {
            while (this.stop_this)
            {
                // trying to find targets
                for (int ind = fishka.Count; ind > 0; ind--)
                {
                    try
                    {
                        fish cur_fish = this.fishka[ind - 1];
                        cur_fish.victim_finded = null;
                        for (int ind2 = fishka.Count; ind2 > 0; ind2--)
                        {
                            fish next_fish = this.fishka[ind2 - 1];

                            float  delta_x = (next_fish.x_coord - cur_fish.x_coord);
                            float  delta_y = (next_fish.y_coord - cur_fish.y_coord);
                            float  range   = (float)Math.Sqrt(delta_x * delta_x + delta_y * delta_y);
                            double angle   = (Math.Atan2(delta_y, delta_x)) + Math.PI;
                            //                            double grangl = angle * 180 / Math.PI;
                            //                            grangl = grangl < 0 ? 360 + grangl : grangl;
                            if (cur_fish.fld_view >= range)
                            {
                                if (cur_fish.victim_finded == null)
                                {
                                    cur_fish.target_range = range;
                                }

                                // find victim
                                if ((cur_fish.predator_lvl > next_fish.predator_lvl) && (cur_fish.victim_finded != false))
                                {
                                    if (cur_fish.target_range >= range)
                                    {
                                        cur_fish.id_victim     = ind2;
                                        cur_fish.target_range  = range;
                                        cur_fish.x_dest        = next_fish.x_coord;
                                        cur_fish.y_dest        = next_fish.y_coord;
                                        cur_fish.victim_finded = true;
                                    }
                                }
                                // if is not victim
                                if (cur_fish.predator_lvl < next_fish.predator_lvl)
                                {
                                    if (cur_fish.target_range <= range)
                                    {
                                        cur_fish.target_range  = range;
                                        cur_fish.victim_finded = false;
                                        float x = (float)(cur_fish.x_coord + cur_fish.max_speed * 5 * (Math.Cos(angle)));
                                        float y = (float)(cur_fish.y_coord + cur_fish.max_speed * 5 * (Math.Sin(angle)));
                                        if (x > (this.pictureBox1.Size.Width - cur_fish.size))
                                        {
                                            x = (int)(this.pictureBox1.Size.Width - cur_fish.size);
                                        }
                                        if (y > (this.pictureBox1.Size.Height - cur_fish.size))
                                        {
                                            y = (int)(this.pictureBox1.Size.Height - cur_fish.size);
                                        }
                                        if (x < cur_fish.size)
                                        {
                                            x = cur_fish.size;
                                        }
                                        if (y < cur_fish.size)
                                        {
                                            y = cur_fish.size;
                                        }
                                        cur_fish.x_dest = x;
                                        cur_fish.y_dest = y;
                                    }
                                }

                                // if catch it
                                if ((range < cur_fish.speed) && (cur_fish.predator_lvl > next_fish.predator_lvl) && (cur_fish.id_victim == ind2))
                                {
                                    cur_fish.repl_curr += cur_fish.strenght;
                                    cur_fish.strenght++;
                                    cur_fish.live_count  += cur_fish.strenght;
                                    next_fish.live_count -= cur_fish.strenght;
                                }
                            }
                        }
                        //                        trd_st(cur_fish);
                    }
                    catch (Exception ex)
                    { }
                }
                Thread.Sleep(1);
            }
            Thread.CurrentThread.Abort();
        }