示例#1
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (pictureBox1.Image != null)
     {
         pictureBox1.Image.Dispose();
         pictureBox1.Image = null;
     }
     button1.Enabled = false;
     Adb.ScreencapNow();
     pictureBox1.Image = Image.FromFile(@"E:\adb\1.png");
     button1.Enabled   = true;
 }
示例#2
0
        private void Form2_Load(object sender, EventArgs e)
        {
            string s = Text;

            Text = Adb.GetPhone();
            if (Text == "")
            {
                MessageBox.Show("请用数据线连接手机,并打开开发者选项中的ADB调试!", "未检测到手机连接!");
                Dispose();
            }
            else
            {
                Adb.ScreencapNow();
                pictureBox1.Image = Image.FromFile(@"E:\adb\1.png");
                timer1.Enabled    = true;
            }
        }
示例#3
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            //刷新连接设备,并刷新页面
            string s = Text;

            Text = Adb.GetPhone();
            if (Text == "")
            {
                Text            = "未连接";
                button1.Enabled = false;
                button2.Enabled = false;
                button3.Enabled = false;
                button4.Enabled = false;
            }
            else
            {
                button1.Enabled = true;
                button2.Enabled = true;
                button4.Enabled = true;
            }
        }
示例#4
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");
        }
示例#5
0
        private void button2_Click(object sender, EventArgs e)
        {
            //初始化
            //if (Adb.IsWeChatApp())
            if (true)
            {
                #region 禁用UI
                button1.Enabled = false;
                button2.Enabled = false;
                button3.Enabled = false;
                button4.Enabled = false;
                #endregion

                //截图并读取
                if (pictureBox1.Image != null)
                {
                    pictureBox1.Image.Dispose();
                    pictureBox1.Image = null;
                }
                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())
                {
                    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;
                         * }
                         */
                        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())
                {
                    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;
                #endregion

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

                Console.WriteLine(string.Format("length:{0} ; start:[{1},{2}] ; to[{3},{4}]", length, chess.X, chess.Y, rectCenter.X, rectCenter.Y));

                #region 画十字坐标
                for (int i = 0; i < 130; i++)
                {
                    bitmap.SetPixel(chess.X + i - 65, chess.Y, Color.Red);
                    bitmap.SetPixel(chess.X + i - 65, chess.Y - 1, Color.Red);
                    bitmap.SetPixel(chess.X + i - 65, chess.Y + 1, Color.Red);
                    bitmap.SetPixel(chess.X, chess.Y + i - 65, Color.Red);
                    bitmap.SetPixel(chess.X - 1, chess.Y + i - 65, Color.Red);
                    bitmap.SetPixel(chess.X + 1, chess.Y + i - 65, Color.Red);

                    bitmap.SetPixel(rectVertex.X + i - 65, rectVertex.Y, Color.Red);
                    bitmap.SetPixel(rectVertex.X + i - 65, rectVertex.Y - 1, Color.Red);
                    bitmap.SetPixel(rectVertex.X + i - 65, rectVertex.Y + 1, Color.Red);
                    bitmap.SetPixel(rectVertex.X, rectVertex.Y + i - 65, Color.Red);
                    bitmap.SetPixel(rectVertex.X - 1, rectVertex.Y + i - 65, Color.Red);
                    bitmap.SetPixel(rectVertex.X + 1, rectVertex.Y + i - 65, Color.Red);

                    bitmap.SetPixel(rectEnd.X + i - 65, rectEnd.Y, Color.Red);
                    bitmap.SetPixel(rectEnd.X + i - 65, rectEnd.Y - 1, Color.Red);
                    bitmap.SetPixel(rectEnd.X + i - 65, rectEnd.Y + 1, Color.Red);
                    bitmap.SetPixel(rectEnd.X, rectEnd.Y + i - 65, Color.Red);
                    bitmap.SetPixel(rectEnd.X - 1, rectEnd.Y + i - 65, Color.Red);
                    bitmap.SetPixel(rectEnd.X + 1, rectEnd.Y + i - 65, Color.Red);
                }
                #endregion

                pictureBox1.Image = null;
                pictureBox1.Image = (Image)bitmap.Clone();
                bitmap.Dispose();

                #region 恢复UI
                button1.Enabled = true;
                button2.Enabled = true;
                button3.Enabled = true;
                button4.Enabled = true;
                #endregion
            }
            else
            {
                MessageBox.Show("请打开微信跳一跳再进行初始化!");
            }
        }
示例#6
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
        }