Exemplo n.º 1
0
 void gkh_KeyDown(object sender, KeyEventArgs e)
 {
     //lstLog.Items.Add("Down\t" + e.KeyCode.ToString());
     if (e.KeyCode.ToString().Equals("B"))
     {
         Ball = Cursor.Position;
         //To make sure the Ball position is set
         flag_ball = true;
         //set textboxes
         textBox1.Text = Ball.X.ToString();
         textBox2.Text = Ball.Y.ToString();
     }
     if (e.KeyCode.ToString().Equals("T"))
     {
         trigger_target(Cursor.Position);
     }
     if (e.KeyCode.ToString().Equals("A"))
     {
         //#D3C05B - DARK Yellow
         //#F7E16A - BRIGHT Yellow
         //if upper left and down right points are defined by user then
         if (!textBox7.Text.Equals("") && !textBox8.Text.Equals("") && !textBox9.Text.Equals("") && !textBox10.Text.Equals(""))
         {
             Color   _color = System.Drawing.ColorTranslator.FromHtml("#D3C05B");
             Point[] points = DetectRect.FindColorRectCoord(_color, TopLeft, DownRight);
             trigger_target(RectMethods.FindLeftCenter(points));
         }
         else
         {
             MessageBox.Show("Enter UpperLeft and DownRight points.");
         }
     }
     if (e.KeyCode.ToString().Equals("M"))
     {
         if (!textBox7.Text.Equals("") && !textBox8.Text.Equals("") && !textBox9.Text.Equals("") && !textBox10.Text.Equals(""))
         {
             start_timer();
         }
         else
         {
             MessageBox.Show("Enter UpperLeft and DownRight points.");
         }
     }
     if (e.KeyCode.ToString().Equals("U"))
     {
         TopLeft = Cursor.Position;
         //set textboxes
         textBox8.Text = TopLeft.X.ToString();
         textBox7.Text = TopLeft.Y.ToString();
     }
     if (e.KeyCode.ToString().Equals("I"))
     {
         DownRight = Cursor.Position;
         //set textboxes
         textBox10.Text = DownRight.X.ToString();
         textBox9.Text  = DownRight.Y.ToString();
     }
     e.Handled = true;
 }
Exemplo n.º 2
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            Color _color = System.Drawing.ColorTranslator.FromHtml("#D3C05B");

            Point[] points = DetectRect.FindColorRectCoord(_color, TopLeft, DownRight);
            Point   tmp    = RectMethods.FindRightCenter(points);
            //agar y payeentar bood bayad zoodtar raha beshe: yani be constant hatman Y ezafe beshe
            int constant = 45;

            switch ((tmp.Y - TopLeft.Y) / 35) //Difference of Y is nearly 380: so in order to have 5 division we need to divide by 78 or sth
            {
            case 1:
                constant += 7;
                break;

            case 2:
                constant += 8;
                break;

            case 3:
                constant += 8;
                break;

            case 4:
                constant += 9;
                break;

            case 5:
                constant += 9;
                break;

            case 6:
                constant += 10;
                break;

            case 7:
                constant += 11;
                break;

            case 8:
                constant += 12;
                break;

            case 9:
                constant += 13;
                break;

            case 10:
                constant += 14;
                break;
            }
            if ((Ball.X - tmp.X) >= 1 && (Ball.X - tmp.X) <= constant)
            {
                Point middle = new Point(Ball.X, tmp.Y);
                trigger_target(middle);
                timer1.Enabled = false;
            }
        }