微信跳一跳自动脚本C#代码实现

2019-12-30 19:13:39王冬梅

前言

CSDN前阵子推送了篇文章,讲的是微信跳一跳的技术实现,大致浏览,发现难度不高,很适合练手。

思路

C#,微信跳一跳,自动脚本,C#微信跳一跳,C#跳一跳

ADB得到屏幕截图,转换成bitmap逐像素分析图像,得到跳跃起点和终点坐标,最后ADB按压屏幕进行跳跃 

相关知识

ADB创建

·在https://www.easck.com/p>

·通过 Process类 创建进程运行ADB 


 Process p = new Process();
 p.StartInfo = new ProcessStartInfo()
 {
 FileName = @"E:adbadb.exe",
 Arguments = str,//要执行的命令
 UseShellExecute =false,//拒绝使用系统自带的Shell
 RedirectStandardInput =true,//接受输入
 RedirectStandardOutput =true, //接受输出
 RedirectStandardError =true,//接受错误
 CreateNoWindow =true,//不创建窗口
 };
 p.Start();
 string s = p.StandardOutput.ReadToEnd();//读取输出
 p.WaitForExit();

常用ADB指令

·读取手机型号


Cmd("shell getprop ro.product.model"); 


·获取屏幕截图


Cmd(@"shell screencap -p/sdcard/1.png"); //屏幕截图并保存
Cmd(@"pull /sdcard/1.pngE:adb"); //上传文件 


·按压屏幕


 Cmd(String.Format("shellinput swipe {0} {1} {2} {3} {4}", x0, y0, x1, y1, time));
 //从0点点击到1点持续time毫秒

ADB算是搞定了,现在写个界面,获取屏幕截图! 

C#,微信跳一跳,自动脚本,C#微信跳一跳,C#跳一跳

取棋子坐标思路

C#,微信跳一跳,自动脚本,C#微信跳一跳,C#跳一跳观察发现
     ·棋子的颜色为固定值,逐取出棋子底部颜色为 RGB(55, 52,92)
     ·棋子的底部y轴坐标在区间[1000,1250] 

实例化Gitmap对象,写一个遍历像素点的循环


Bitmap bitmap =new Bitmap(@"E:adb1.png");
 Pointchess =newPoint();
 //棋子颜色 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;
 }