Esempio n. 1
0
        /// <summary>
        /// 显示截图,因为截图速度慢,所以会来不及加载就获取下一张了
        /// </summary>
        /// <param name="value"></param>
        private void ShowImage_Tick(object value)
        {
            if (isConnetion)
            {
                var filePath = ADBHelper.GetScreen();
                if (File.Exists(filePath))
                {
                    using (var fs = new FileStream(filePath, FileMode.Open))
                    {
                        var bitmap = new Bitmap(fs);

                        var g = Graphics.FromImage(bitmap);

                        g.DrawString(DateTime.Now.ToString(), new Font("宋体", 30f), Brushes.Red, 0, 0);
                        g.Dispose();

                        this.Invoke(new Action(() =>
                        {
                            picImage.Image = bitmap;
                        }));
                        //bitmap.Dispose();
                    }
                    File.Delete(filePath);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 加载手机截图
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnLoad_Click(object sender, EventArgs e)
        {
            ADBHelper.SavePath = string.Format("D:\\{0}\\", DateTime.Now.ToString("yyyyMMddhhmmss"));
            count = 0;

            var filePath = ADBHelper.GetScreen();

            if (File.Exists(filePath))
            {
                using (var fs = new FileStream(filePath, FileMode.Open))
                {
                    var bitmap = new Bitmap(fs);

                    var g = Graphics.FromImage(bitmap);

                    g.DrawString(DateTime.Now.ToString(), new Font("宋体", 30f), Brushes.Red, 0, 0);
                    g.Dispose();

                    lblResoPo.Text    = bitmap.Width + "x" + bitmap.Height;
                    picImage.Width    = (int)(bitmap.Width * 0.4);
                    picImage.Height   = (int)(bitmap.Height * 0.4);
                    picImage.SizeMode = PictureBoxSizeMode.StretchImage;
                    picImage.Image    = bitmap;
                    //bitmap.Dispose();
                }
                File.Delete(filePath);

                btnAuto.Enabled = true;
                btnJump.Enabled = true;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 检测是否有手机连接
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ConnTimer_Tick(object sender)
        {
            AddMsg("正在加载手机...");
            var model = ADBHelper.GetPhoneModel();

            if (model != "")
            {
                AddMsg(string.Format("加载手机成功:{0}!", model));
                lblPhoneModel.Invoke(new Action(() =>
                {
                    lblPhoneModel.Text = model;
                    btnLoad.Enabled    = true;
                }));

                isConnetion = true;
                ((System.Threading.Timer)sender).Dispose();
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 跳一步
        /// </summary>
        private void JumpOne()
        {
            var sw = new Stopwatch();

            sw.Start();
            //截图并保存到电脑
            AddMsg("\r\n正在获取手机截图...");
            var filePath = ADBHelper.GetScreen();

            if (File.Exists(filePath))
            {
                AddMsg("手机截图获取成功,正在加载图片...");
                using (var fs = new FileStream(filePath, FileMode.Open))
                {
                    var bitmap = new Bitmap(fs);

                    var g = Graphics.FromImage(bitmap);

                    g.DrawString(DateTime.Now.ToString(), new Font("宋体", 30f), Brushes.Red, 0, 0);
                    g.Dispose();

                    this.Invoke(new Action(() =>
                    {
                        picImage.Image = bitmap;
                    }));
                    AddMsg("加载图片成功!");
                }
                //File.Delete(filePath);
                //AddMsg("删除图片成功!");
                File.Move(filePath, ADBHelper.SavePath + count.ToString() + ".png");
                ++count;

                sw.Stop();
                AddMsg(string.Format("获取耗时:{0}ms", sw.ElapsedMilliseconds));

                AddMsg("开始获取距离!");
                var img      = new Bitmap(picImage.Image);
                var distance = GameHelper.GetDistance(img, SumTime, lblBox, lblPerson);
                this.Invoke(new Action(() =>
                {
                    picImage.Image   = img;
                    lblDistance.Text = distance.ToString();
                }));
                AddMsg(string.Format("距离为:{0}", distance));

                var k = 0d;
                this.Invoke(new Action(() => { double.TryParse(txtJumpK.Text, out k); }));
                var jumpTime = (int)(distance * k);
                AddMsg(string.Format("发送跳跃指令!跳跃时间:{0}!", jumpTime));
                //ADBHelper.ClickScreen(300, 300, 301, 301, jumpTime);
                var random = new Random();
                var x1     = random.Next(300, 500);
                var y1     = random.Next(300, 500);
                var x2     = x1 + random.Next(0, 30);
                var y2     = y1 + random.Next(0, 30);
                ADBHelper.ClickScreen(x1, y1, x2, y2, jumpTime);

                //延时按压时间+跳跃时间+下一个盒子落地时间
                int jumpS = 0, dowsS = 0;
                this.Invoke(new Action(() =>
                {
                    int.TryParse(txtJump.Text, out jumpS);
                    int.TryParse(txtDown.Text, out dowsS);
                }));
                var sleepTime = jumpTime + jumpS + dowsS;
                AddMsg(string.Format("发送跳跃指令成功,并延时:{0}!", sleepTime));
                Thread.Sleep(sleepTime);
                AddMsg("结束跳跃");
            }
            else
            {
                AddMsg("加载截图失败!");
            }
        }