c语言跳一跳自动跳代码,微信跳一跳自动脚本C#代码实现

前言

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

思路

5a67461d3e921bee5e830cc1d377afb2.png

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

相关知识

ADB创建

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

Process p = new Process();

p.StartInfo = new ProcessStartInfo()

{

FileName = @"E:\adb\adb.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算是搞定了,现在写个界面,获取屏幕截图!

420e7925ec8cd1adbffddd877614c4e8.png

取棋子坐标思路

f313922d212c76865384cf47ae1d89f5.png观察发现

·棋子的颜色为固定值,逐取出棋子底部颜色为 RGB(55, 52,92)

·棋子的底部y轴坐标在区间[1000,1250]

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

Bitmap bitmap =new Bitmap(@"E:\adb\1.png");

Pointchess =newPoint();

//棋子颜色 Color.FromArgb(55, 52, 92))

for (int y = 1000; y < 1250;y++)

{

for (int x = 0; 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;

}

底部坐标被正确的取了出来

c0e09a8b55b2b7d6eee46b94d5b08b5c.png

完美!现在取出顶点和底部坐标!

7c74eaa86dfef41a8399ebd7b22d6b0e.png观察发现

·背景颜色为渐变色,所以横向比较,与前一个点差别最大的点就是顶点

·平面颜色一般为纯色,也可能是渐变色,所以得到顶点后作竖向比较,最后一个与前点      差别最大的点就是底部坐标

·顶点的y轴坐标在区间[650-1050]

首先写一个判断颜色相似度的方法

bool ColorAbout(Colorcolor0, Color color1)

{

int i = 20; //颜色差值

int r =Math.Max(color0.R,color1.R)- Math.Min(color0.R, color1.R);

int g = Math.Max(color0.G,color1.G) - Math.Min(color0.G, color1.G);

int b = Math.Max(color0.B,color1.B) - Math.Min(color0.B, color1.B);

return!((Math.Max(Math.Max(r,g),b) + Math.Min(Math.Min(r, g), b)) > i);

}

还是写一个遍历点的循环,调用颜色相似度方法作横向比较取出顶点坐标和底部坐标

Point rectVertex = new Point();

Point rectEnd = new Point();

for (int y = 650; y < 1050;y++)

{

for (int x = 1; x

{

boolisColorAbout = !ColorAbout(bitmap.GetPixel(x - 1, y), bitmap.GetPixel(x, y));

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;

}

ColorrectColor = bitmap.GetPixel(rectVertex.X,rectVertex.Y+1);

if (rectEnd == new Point())

{

for (int y = rectVertex.Y; y< 1200; y++)

{

boolisColorAbout = ColorAbout(rectColor, bitmap.GetPixel(rectVertex.X, y));

if(isColorAbout)

{

rectEnd.X = rectVertex.X;

rectEnd.Y = y;

}

}

}

OK!取出了坐标剩下的就是计算距离(正好前几天才学的两点距离公式)和跳跃了!开始循环!

抛砖引玉 仅供学习!

更多内容大家可以参考专题《微信跳一跳》进行学习。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值