示例#1
0
        private void UpdateCounter(int iCrashedCnt, c_AirSpace airSpace, int timeLine)
        {
            if (!InvokeRequired)
            {
                TimeLineCounter.Value = timeLine;
                TimeLineCounter.Update();
                numericUpDownX.Value = Convert.ToInt32(airSpace.bees[1].getCurrentLoc().getX());
                numericUpDownY.Value = Convert.ToInt32(airSpace.bees[1].getCurrentLoc().getY());
                numericUpDownH.Value = Convert.ToInt32(airSpace.bees[1].getCurrentLoc().getH());
                numericUpDownX.Update();
                numericUpDownY.Update();
                numericUpDownH.Update();
                numericUpDownX1.Value = Convert.ToInt32(airSpace.bees[2].getCurrentLoc().getX());
                numericUpDownY1.Value = Convert.ToInt32(airSpace.bees[2].getCurrentLoc().getY());
                numericUpDownH1.Value = Convert.ToInt32(airSpace.bees[2].getCurrentLoc().getH());
                numericUpDownX1.Update();
                numericUpDownY1.Update();
                numericUpDownH1.Update();

                // update Crashed counter
                numericUpDown_CrashedCnt.Value = iCrashedCnt;
                numericUpDown_CrashedCnt.Update();
            }
            else
            {
                BeginInvoke(new Action <int, c_AirSpace, int>(UpdateCounter), iCrashedCnt, airSpace, timeLine);
            }
        }
示例#2
0
        }//end: updateBeesDisplay()

        public void updateBeesDisplay(c_AirSpace airSpace)
        {
            if (InvokeRequired) //alon
            {
                BeginInvoke(new Action <c_AirSpace>(updateBeesDisplay), airSpace);
            }
            else //alon
            {
                double zeroPointX = 0;
                double zeroPointY = 0 + pictureBox1.Size.Height;
                double dispScaleX = (pictureBox1.Size.Width) / airSpace.maxLimits.getX();
                double dispScaleY = (pictureBox1.Size.Height) / airSpace.maxLimits.getY();
                double x          = 0.0;
                double y          = 0.0;

                Graphics g       = pictureBox1.CreateGraphics();
                int      X_point = 0;
                int      Y_point = 0;

                // System.Drawing.Point beeDispPoint = new System.Drawing.Point(X_point, Y_point);

                // update all bees in the air space
                this.pictureBox1.BringToFront();
                this.pictureBox1.Refresh();

                for (int i = 0; i < airSpace.beesNum; i++)
                {
                    x = airSpace.bees[i].getCurrentLoc().getX();
                    y = airSpace.bees[i].getCurrentLoc().getY();

                    X_point = Convert.ToInt32(zeroPointX + x * dispScaleX);
                    Y_point = Convert.ToInt32(zeroPointY - y * dispScaleY);

                    rect.X = X_point;
                    rect.Y = Y_point;
                    //this.pictureBox1.CreateGraphics().DrawRectangle(penRed, rect);
                    if (airSpace.bees[i].getCollisionState())
                    {
                        g.DrawRectangle(penRed, rect);
                    }
                    else
                    {
                        g.DrawRectangle(penBlack, rect);
                    }



                    //this.Controls[3].Location = beeDispPoint; //airSpace.bees[beeNum].beeBox.Location = beeDispPoint;
                    //this.Controls[3].Update();// airSpace.bees[beeNum].beeBox.Update();
                    //m_bees[beeNum].Location = beeDispPoint;
                    //m_bees[beeNum].Update();
                    //m_bees[beeNum].BringToFront();
                }
                g.Dispose();
                //this.pictureBox1.Update();
            }
        }//end: updateBeesDisplay()
示例#3
0
        //private System.Windows.Forms.PictureBox spriteBox1;
        //private System.Windows.Forms.PictureBox[] spriteBox1 = new System.Windows.Forms.PictureBox[100];
        //private System.Windows.Forms.PictureBox spriteBox1 = new System.Windows.Forms.PictureBox();

        public void initBeeDisplay(c_AirSpace airSpace)
        {
            // sets the init values of the LIST m_bees.
            //for (int i = 1; i <= airSpace.beesNum; i++)
            //{
            m_bees.Add(spriteBox1);
            m_bees.Add(spriteBox2);
            m_bees.Add(spriteBox3);
            m_bees.Add(spriteBox4);
            m_bees.Add(spriteBox5);
            m_bees.Add(spriteBox6);
            m_bees.Add(spriteBox7);
            m_bees.Add(spriteBox8);
            m_bees.Add(spriteBox9);
            m_bees.Add(spriteBox10);
            //}
            //System.Drawing.Point newPoint = new System.Drawing.Point(345, 300);

            //for (int i = 1; i <= this.getInitValue_Bees(); ++i)
            //{
            //     newPoint.X = 300 + 5 * i;
            //     newPoint.Y = 300;
            //    spriteBox1[i] = new System.Windows.Forms.PictureBox();
            //     spriteBox1[i].Location = newPoint;
            //     //spriteBox1[i].Location.X = 362 + 5 * i;
            //     spriteBox1[i].Name = "spriteBox";
            //     spriteBox1[i].Size = new System.Drawing.Size(10, 10);
            //     spriteBox1[i].TabIndex = 2;
            //     spriteBox1[i].TabStop = false;
            //     Controls.Add(this.spriteBox1[i]);
            //     pictureBox1.Update();
            //     spriteBox1[i].Update();

            //}

            //newPoint.X = 300 + 5;
            //newPoint.Y = 300;
            //spriteBox1 = new System.Windows.Forms.PictureBox();
            //spriteBox1.Location = newPoint;
            //spriteBox1[i].Location.X = 362 + 5 * i;
            //spriteBox1.Name = "spriteBox";
            //spriteBox1.Size = new System.Drawing.Size(10, 10);
            //spriteBox1.TabIndex = 2;
            //spriteBox1.TabStop = false;
            //this.spriteBox.Size = new System.Drawing.Size(10, 10);


            //pictureBox1.Update();
            //spriteBox1.Update();
            //spriteBox2.Update();
        }
示例#4
0
        private void buttonRun_Click(object sender, EventArgs e)
        {
            //alon:
            // creates new instance of m_bees list as a List of type PictureBox
            if (m_bees == null)
            {
                m_bees = new List <PictureBox>(1000);
            }

            // alon:
            // protect from restarting another time if not stopped
            if (simStart)
            {
                return;         //dont run another thread
            }
            //
            simStart = true;
            simStop  = false;
            //int timeLine = 0;
            int startedBees = Convert.ToInt32(numericUpDown_Bees.Value);
            //int spriteX = 0;
            //int spriteY = 0;
            int iCrashedCnt = 0;
            int iMaxSimTime = 0;

            iMaxSimTime = Convert.ToInt32(TimeLineCounter.Value);

            System.Drawing.Point newPoint = new System.Drawing.Point(362, 300);

            c_AirSpace airSpace = new c_AirSpace(getInitValue_X(), getInitValue_Y(), getInitValue_H(), getInitValue_Bees(), getInitValue_CollDist(), getInitValue_commDist(), getInitValue_commMode());
            //MessageBox.Show("Start Simulation!!!");
            // temp initBeeDisplay(airSpace);
            //spriteX = 300;// Convert.ToInt32(getInitValue_X());
            //spriteY = 300;// Convert.ToInt32(getInitValue_Y());
            double scaleX = getInitValue_X() / (pictureBox1.Size.Width - pictureBox1.Location.X);
            double scaleY = getInitValue_Y() / (pictureBox1.Size.Height - pictureBox1.Location.Y);

            //for (int b = 1; b <= startedBees; b++)
            //{
            //this.Controls.Add(new Control airSpace.bees[b].beeBox);
            //    this.Controls.Add(airSpace.bees[b].beeBox);
            // }
            // alon: run the algo thread
            Task.Factory.StartNew(() => RunAlgo(startedBees, iCrashedCnt, iMaxSimTime, airSpace));
        }
示例#5
0
        // convert the Bee location to display point
        public void updateBeesDisplay(c_AirSpace airSpace, int beeNum)
        {
            if (InvokeRequired) //alon
            {
                BeginInvoke(new Action <c_AirSpace, int> (updateBeesDisplay), airSpace, beeNum);
            }
            else //alon
            {
                double zeroPointX = pictureBox1.Location.X;
                double zeroPointY = pictureBox1.Location.Y + pictureBox1.Size.Height;
                double dispScaleX = (pictureBox1.Size.Width - 10) / airSpace.maxLimits.getX();
                double dispScaleY = (pictureBox1.Size.Height + 10) / airSpace.maxLimits.getY();
                double x          = airSpace.bees[beeNum].getCurrentLoc().getX();
                double y          = airSpace.bees[beeNum].getCurrentLoc().getY();

                int X_point = 0; X_point = Convert.ToInt32(zeroPointX + x * dispScaleX);
                int Y_point = 0; Y_point = Convert.ToInt32(zeroPointY - y * dispScaleY);

                System.Drawing.Point beeDispPoint = new System.Drawing.Point(X_point, Y_point);


                //this.Controls[3].Location = beeDispPoint; //airSpace.bees[beeNum].beeBox.Location = beeDispPoint;
                //this.Controls[3].Update();// airSpace.bees[beeNum].beeBox.Update();
                m_bees[beeNum].Location = beeDispPoint;
                m_bees[beeNum].Update();
                m_bees[beeNum].BringToFront();
                // my code


                //pictureBox1.Update();
                //spriteBox1.Update();
                //spriteBox2.Update();
                //spriteBox3.Update();
                //spriteBox4.Update();
                //spriteBox5.Update();
                //spriteBox6.Update();
                //spriteBox7.Update();
                //spriteBox8.Update();
                //spriteBox9.Update();
                //spriteBox10.Update();
                //pictureBox1.Update();
                //this.airSpace.bees[b].beeBox;
            }
        }//end: updateBeesDisplay()
示例#6
0
        private void RunAlgo(int startedBees, int iCrashedCnt, int iMaxSimTime, c_AirSpace airSpace)
        {
            for (int timeLine = 0; timeLine < iMaxSimTime; timeLine++)
            {
                if (simStop)
                {
                    break;
                }
                // wait for a second
                System.Threading.Thread.Sleep(40);
                //pictureBox1.Update();

                // replace with TImer so the GUI will responsive

                //continue the loop
                //timeLine++;

                // Display the time in the display box
                // alon: collect update counters in a function
                UpdateCounter(iCrashedCnt, airSpace, timeLine);

                //airSpace.updateBees();

                //spriteX = Convert.ToInt32(airSpace.bee1DispPoint.X / scaleX);
                //spriteY = Convert.ToInt32(airSpace.bee1DispPoint.Y / scaleY);
                //newPoint.X = newPoint.X +1;
                //newPoint.Y = newPoint.Y + 1;
                //updateSpriteLocation(newPoint);
                airSpace.updateBees();
                if (timeLine > 10)
                {
                    iCrashedCnt = iCrashedCnt + airSpace.checkCollision();
                }
                updateBeesDisplay(airSpace);
                //<temp>for (int k = 0; k < m_bees.Count; k++)
                //<temp>{
                //<temp>    //updateBeesDisplay(airSpace, airSpace.bees[k]);
                //<temp>    updateBeesDisplay(airSpace, k);
                //<temp>}
            }
            //so another start will be available
            simStart = false;
            simStop  = true;
        }