Esempio n. 1
0
        private void button3_Click(object sender, EventArgs e)
        {
            button1.Enabled = false;
            button2.Enabled = false;
            button3.Enabled = false;
            button4.Enabled = false;

            double i = new double();

            try
            {
                i = Convert.ToDouble(textBox1.Text);
            }
            catch (Exception)
            {
                MessageBox.Show("微调系数必须为数值!");
                return;
            }
            Adb.Touch(lastChess.X, lastChess.Y, lastRect.X, lastRect.Y, (int)(length * i));
            Thread.Sleep(1000);
            pictureBox1.Image.Dispose();
            Adb.ScreencapNow();
            pictureBox1.Image = Image.FromFile(@"E:\adb\1.png");
        }
Esempio n. 2
0
        private void button4_Click(object sender, EventArgs e)
        {
            #region 禁用UI
            if (pictureBox1.Image != null)
            {
                pictureBox1.Image.Dispose();
                pictureBox1.Image = null;
            }
            button1.Enabled = false;
            button2.Enabled = false;
            button3.Enabled = false;
            button4.Enabled = false;
            timer1.Enabled  = false;
            #endregion

            #region 取循环次数
            int count = new int();
            try
            {
                count = Convert.ToInt32(textBox3.Text);
            }
            catch (Exception)
            {
                MessageBox.Show("循环次数只能为整数");
                return;
            }
            #endregion

            for (int ii = 0; ii < count; ii++)
            {
                //if (Adb.IsWeChatApp())
                if (true)
                {
                    //截图
                    Adb.ScreencapNow();
                    Bitmap bitmap = new Bitmap(@"E:\adb\1.png");

                    #region 取棋子坐标
                    Point chess = new Point();
                    //棋子颜色 Color.FromArgb(55, 52, 92))
                    for (int y = 1000; y < 1250; y++)
                    {
                        for (int x = 0; x < bitmap.Width; x++)
                        {
                            if (bitmap.GetPixel(x, y) == Color.FromArgb(57, 58, 102))
                            {
                                chess.X = x;
                                chess.Y = y;
                                break;
                            }
                        }
                        if (chess != new Point())
                        {
                            break;
                        }
                    }
                    if (chess == new Point())
                    {
                        Adb.ScreencapNow();
                        pictureBox1.Image = Image.FromFile(@"E:\adb\1.png");
                        button4.Text      = "JUMP AUTO";
                        timer1.Enabled    = true;
                        MessageBox.Show("找不到棋子!初始化失败!");
                        bitmap.Dispose();
                        return;
                    }
                    #endregion

                    Point rectVertex = new Point(); //顶点坐标
                    Point rectEnd    = new Point(); //底部坐标

                    #region 取物体顶点坐标

                    for (int y = 650; y < 1050; y++)
                    {
                        for (int x = 1; x < bitmap.Width; x++)
                        {
                            //Console.WriteLine(bitmap.GetPixel(x, y).ToArgb());
                            //bitmap.SetPixel(x, y, Color.Red);
                            bool isColorAbout;
                            try
                            {
                                isColorAbout = !ColorAbout(bitmap.GetPixel(x - 1, y), bitmap.GetPixel(x, y));
                            }
                            catch (Exception)
                            {
                                MessageBox.Show("颜色容差只能为整数");
                                return;
                            }

                            /*
                             * if (bitmap.GetPixel(x, y) == Color.FromArgb(255, 238, 97))
                             * {
                             *  //MessageBox.Show("黄色!手动一波!");
                             *
                             *  rectVertex.X = x;
                             *  rectVertex.Y = y;
                             *  rectEnd.X = rectVertex.X;
                             *  rectEnd.Y = rectVertex.Y + 75;
                             *  break;
                             * }
                             * else */
                            if ((x < chess.X - 75 || x > chess.X + 75) && isColorAbout)
                            {
                                rectVertex.X = x;
                                rectVertex.Y = y;
                                break;
                            }
                        }
                        if (rectVertex != new Point())
                        {
                            break;
                        }
                    }
                    if (rectVertex == new Point())
                    {
                        Adb.ScreencapNow();
                        pictureBox1.Image = Image.FromFile(@"E:\adb\1.png");
                        button4.Text      = "JUMP AUTO";
                        timer1.Enabled    = true;
                        MessageBox.Show("未知的物体!初始化失败!");
                        bitmap.Dispose();
                        return;
                    }
                    #endregion

                    #region 取物体尾部坐标
                    Color rectColor = bitmap.GetPixel(rectVertex.X, rectVertex.Y + 1);
                    if (rectEnd == new Point())
                    {
                        for (int y = rectVertex.Y; y < 1200; y++)
                        {
                            //bitmap.SetPixel(rectVertex.X, y, Color.Red);
                            bool isColorAbout;
                            try
                            {
                                isColorAbout = ColorAbout(rectColor, bitmap.GetPixel(rectVertex.X, y));
                            }
                            catch (Exception)
                            {
                                MessageBox.Show("颜色容差只能为整数");
                                return;
                            }
                            if (isColorAbout)
                            {
                                rectEnd.X = rectVertex.X;
                                rectEnd.Y = y;
                            }
                        }
                    }
                    #endregion

                    #region 计算距离
                    Point rectCenter = new Point();
                    rectCenter.X = (rectVertex.X + rectEnd.X) / 2;
                    rectCenter.Y = (rectVertex.Y + rectEnd.Y) / 2;

                    length    = (int)(Math.Sqrt(Math.Pow(rectCenter.X - chess.X, 2) + Math.Pow(rectCenter.Y - chess.Y, 2)));
                    lastChess = chess;
                    lastRect  = rectCenter;
                    #endregion

                    Console.WriteLine(string.Format("length:{0} ; start:[{1},{2}] ; to:[{3},{4}] ; ii = {5}", length, chess.X, chess.Y, rectCenter.X, rectCenter.Y, ii));
                    bitmap.Dispose();
                }
                else
                {
                    MessageBox.Show("请打开微信跳一跳再进行初始化!");
                }
                #region 跳跃
                //1.39
                double i = new int();
                try
                {
                    i = Convert.ToDouble(textBox1.Text);
                }
                catch (Exception)
                {
                    Adb.ScreencapNow();
                    pictureBox1.Image = Image.FromFile(@"E:\adb\1.png");
                    button4.Text      = "JUMP AUTO";
                    timer1.Enabled    = true;
                    MessageBox.Show("微调系数必须为数值!");
                    return;
                }
                Adb.Touch(lastChess.X, lastChess.Y, lastRect.X, lastRect.Y, (int)(length * i));//1.39
                #endregion
                try
                {
                    i = Convert.ToDouble(textBox2.Text);
                }
                catch (Exception)
                {
                    Adb.ScreencapNow();
                    pictureBox1.Image = Image.FromFile(@"E:\adb\1.png");
                    button4.Text      = "JUMP AUTO";
                    timer1.Enabled    = true;
                    MessageBox.Show("延迟时间必须为数值!");
                    return;
                }

                button4.Text = (ii + 1).ToString();
                Thread t = new Thread(o => Thread.Sleep((int)i));
                t.Start(this);
                while (t.IsAlive)
                {
                    Application.DoEvents();
                }
            }
            #region  位UI
            Adb.ScreencapNow();
            pictureBox1.Image = Image.FromFile(@"E:\adb\1.png");
            button4.Text      = "JUMP AUTO";
            timer1.Enabled    = true;

            #endregion
        }