欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

微信跳一跳自動(dòng)腳本C#代碼實(shí)現(xiàn)

 更新時(shí)間:2018年01月08日 08:45:38   作者:C-LanQ  
這篇文章主要為大家詳細(xì)介紹了微信跳一跳自動(dòng)腳本C#代碼實(shí)現(xiàn)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

前言

CSDN前陣子推送了篇文章,講的是微信跳一跳的技術(shù)實(shí)現(xiàn),大致瀏覽,發(fā)現(xiàn)難度不高,很適合練手。

思路

ADB得到屏幕截圖,轉(zhuǎn)換成bitmap逐像素分析圖像,得到跳躍起點(diǎn)和終點(diǎn)坐標(biāo),最后ADB按壓屏幕進(jìn)行跳躍 

相關(guān)知識(shí)

ADB創(chuàng)建

·在https://adb.clockworkmod.com提前下載ADB

·通過 Process類 創(chuàng)建進(jìn)程運(yùn)行ADB 

 Process p = new Process();
 p.StartInfo = new ProcessStartInfo()
 {
 FileName = @"E:\adb\adb.exe",
 Arguments = str,//要執(zhí)行的命令
 UseShellExecute =false,//拒絕使用系統(tǒng)自帶的Shell
 RedirectStandardInput =true,//接受輸入
 RedirectStandardOutput =true, //接受輸出
 RedirectStandardError =true,//接受錯(cuò)誤
 CreateNoWindow =true,//不創(chuàng)建窗口
 };
 p.Start();
 string s = p.StandardOutput.ReadToEnd();//讀取輸出
 p.WaitForExit();

常用ADB指令

·讀取手機(jī)型號(hào)

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點(diǎn)點(diǎn)擊到1點(diǎn)持續(xù)time毫秒

ADB算是搞定了,現(xiàn)在寫個(gè)界面,獲取屏幕截圖! 


取棋子坐標(biāo)思路

觀察發(fā)現(xiàn)
     ·棋子的顏色為固定值,逐取出棋子底部顏色為 RGB(55, 52,92)
     ·棋子的底部y軸坐標(biāo)在區(qū)間[1000,1250] 

實(shí)例化Gitmap對(duì)象,寫一個(gè)遍歷像素點(diǎn)的循環(huán)

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 <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;
 }

底部坐標(biāo)被正確的取了出來

 

完美!現(xiàn)在取出頂點(diǎn)和底部坐標(biāo)!

觀察發(fā)現(xiàn)
·背景顏色為漸變色,所以橫向比較,與前一個(gè)點(diǎn)差別最大的點(diǎn)就是頂點(diǎn)
·平面顏色一般為純色,也可能是漸變色,所以得到頂點(diǎn)后作豎向比較,最后一個(gè)與前點(diǎn)      差別最大的點(diǎn)就是底部坐標(biāo)
·頂點(diǎn)的y軸坐標(biāo)在區(qū)間[650-1050] 

首先寫一個(gè)判斷顏色相似度的方法 

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);
 }

還是寫一個(gè)遍歷點(diǎn)的循環(huán),調(diào)用顏色相似度方法作橫向比較取出頂點(diǎn)坐標(biāo)和底部坐標(biāo)

Point rectVertex = new Point();
 Point rectEnd = new Point();
 
 for (int y = 650; y < 1050;y++)
 {
  for (int x = 1; x <bitmap.Width; x++)
  {
  boolisColorAbout = !ColorAbout(bitmap.GetPixel(x - 1, y), bitmap.GetPixel(x, y));
  if ((x < chess.X - 75 || x > chess.X + 75)&& isColorAbout) //排除棋子坐標(biāo),避免錯(cuò)誤的將棋子作頂點(diǎn)
  {
  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!取出了坐標(biāo)剩下的就是計(jì)算距離(正好前幾天才學(xué)的兩點(diǎn)距離公式)和跳躍了!開始循環(huán)!

LanQ 2017.1.6 GitHub-WeCharJump

拋磚引玉 僅供學(xué)習(xí)!

更多內(nèi)容大家可以參考專題《微信跳一跳》進(jìn)行學(xué)習(xí)。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論