Time: 4月20日03:47:57 by: MemoryErHero
源码参考案例 (非最优方案,请自行测试优化,仅供学习参考)
1 . 罗盘 - 八向方位模拟 - 自动寻路 1
参数1: 目标坐标X 整数型
参数2: 目标坐标Y 整数型
参数3: 挪动间隔 整数型
Function 自动寻路_八方位向(mbx,mby,tnumber)Dim 识别坐标,坐标,坐标2()Dim 次数 = 0Dim x坐标 = 190Dim y坐标 = 193//(要修改,此处坐标为方向摇杆中点) Do/*识别坐标 = int(SmartOcr(555,1159,579,1279,"CFDCE6-20|B5C0C9-121212|8A939A-121212|9DA7AF-121212"))//(要修改,此处为坐标数字范围/字体颜色/字体边缘颜色)//坐标 = Split(识别坐标, ",")//坐标(0) = CLng(坐标(0))//坐标(1) = CLng(坐标(1)) */坐标(0) = Int(SmartOcr(556, 1175, 581,1220,"CFDCE6-20|B5C0C9-121212|8A939A-121212|9DA7AF-121212"))坐标(1) = int(SmartOcr(556,1175,581,1220,"CFDCE6-20|B5C0C9-121212|8A939A-121212|9DA7AF-121212"))TracePrint 坐标(0),坐标(1)If 坐标2(0) = 坐标(0) and 坐标2(1) = 坐标(1) Then 次数 = 次数 + 1Else 次数=0End If坐标2(0) = 坐标(0)坐标2(1) = 坐标(1)If Abs(坐标(0) - mbx) <= 2 and Abs(坐标(1) - mby) <= 2 Then Exit DoEnd IfTouchDown x坐标, y坐标, 1If 坐标(0) > mbx and 坐标(1) > mby Then '左上TouchMove x坐标 + 150, y坐标 - 150, 1, tnumberElseIf 坐标(0) > mbx and 坐标(1) < mby Then'左下TouchMove x坐标 - 150, y坐标 - 150, 1, tnumberElseIf 坐标(0) < mbx and 坐标(1) > mby Then'右上TouchMove x坐标 + 150, y坐标 + 150, 1, tnumberElseIf 坐标(0) < mbx and 坐标(1) < mby Then'右下TouchMove x坐标 - 150, y坐标 + 150, 1, tnumberElse If Abs(坐标(0) - mbx) > Abs(坐标(1) - mby) Then '左右移动If 次数 > 2 Then If 坐标(1) > mby Then '上TouchMove x坐标 + 150, y坐标, 1, tnumberElse '下TouchMove x坐标 - 150, y坐标, 1, tnumberEnd If次数 = 0Else If 坐标(0) > mbx Then '左TouchMove x坐标, y坐标 - 150, 1, tnumberElse '右TouchMove x坐标, y坐标 + 150, 1, tnumberEnd IfEnd IfElse '上下移动If 次数 > 2 Then If 坐标(0) > mbx Then '左TouchMove x坐标, y坐标 - 150, 1, tnumberElse '右TouchMove x坐标, y坐标 + 150, 1, tnumberEnd If次数 = 0Else If 坐标(1) > mby Then '上TouchMove x坐标 + 150, y坐标, 1, tnumberElse '下TouchMove x坐标 - 150, y坐标, 1, tnumberEnd IfEnd IfEnd IfEnd IfTouchUp 1LoopEnd FunctionCall 自动寻路_八方位向(285,606,300)
1 . 罗盘 - 八向方位模拟 - 自动寻路 2
参数1: 目标坐标X 整数型
参数2: 目标坐标Y 整数型
参数3: 罗盘移动时间 整数型
参数4: 目的坐标误差值 整数型
参数5: 罗盘移动上限 整数型
返回值: 成功返回 true 上限返回 false 逻辑型
//Time:4月20日04:19:10 By:MemoryErHeroFunction moveCompass(data)//函数名: 罗盘移动 传参类型: 数组//例子: dataArr = {"左下", 188, 192, 118, 261, moveTime}//moveCompass(dataArr)TracePrint "罗盘移动:",data(0)Swipe data(1), data(2), data(3), data(4), data(5)End FunctionFunction 自动寻路_八方位向限次(mbx, mby, moveTime, deviation, jobmax)/* 注释 : 精确度误差 +1左右,时间最好控制 500 毫秒以内.** 参数1: 目的坐标x 整数型** 参数2: 目的坐标y 整数型** 参数3: 罗盘移动时间 整数型** 参数4: 目的坐标误差值 整数型** 参数5: 罗盘移动上限 整数型** 返回值: 成功返回 true 上限返回 false 逻辑型*/Dim MoveArr(9)//按键精灵数组从0开始,方便阅读所以选用下表1位起始MoveArr[1] = {"左下", 188, 192, 118, 261, moveTime}MoveArr[2] = {"左上", 188, 192, 263, 118, moveTime}MoveArr[3] = {"右下", 188, 192, 117, 118, moveTime}MoveArr[4] = {"右下", 188, 192, 266, 265, moveTime}MoveArr[5] = {"下", 188, 192, 89, 191, moveTime}MoveArr[6] = {"上", 188, 192, 296, 191, moveTime}MoveArr[7] = {"左", 188, 192, 191, 298, moveTime}MoveArr[8] = {"右", 188, 192, 191, 90, moveTime}Dim nowX,nowY,cx1,xy1,jobNumberDonowX = int(SmartOcr(556,1175,581,1220,"CFDCE6-20|B5C0C9-121212|8A939A-121212|9DA7AF-121212"))nowY = int(SmartOcr(557,1224,578,1271, "CFDCE6-20|B5C0C9-121212|8A939A-121212|9DA7AF-121212"))TracePrint "识别坐标: ",nowX,nowYIf Abs(mbx - nowX) <= deviation and Abs(mby - nowY) <= deviation ThenTracePrint"状态: 到达目的"自动寻路_八方位向限次 = trueExit FunctionElsejobNumber = jobNumber+1TracePrint "已执行: "&jobNumber&" 次"If jobNumber = jobmax Then 自动寻路_八方位向限次 = falseExit FunctionEnd IfEnd If If Abs(mbx - nowX) >= 1 or Abs(mby - nowY) >= 1 ThenIf (mbx - nowX) > 0 and (mby - nowY) > 0 Then //TracePrint "右下"moveCompass(MoveArr[1])ElseIf (mbx - nowX)<0 and (mby - nowY)<0 Then//TracePrint "左上"moveCompass(MoveArr[2])ElseIf (mbx - nowX)<0 and (mby - nowY)>0 Then//TracePrint "右下"moveCompass(MoveArr[3])ElseIf (mbx - nowX)>0 and (mby - nowY)<0 Then//TracePrint "右上"moveCompass(MoveArr[4])ElseIf (mbx - nowX)=0 and (mby - nowY)>0 Then//TracePrint "下"moveCompass(MoveArr[5])ElseIf (mbx - nowX)=0 and (mby - nowY)<0 Then//TracePrint "上" moveCompass(MoveArr[6])ElseIf (mbx - nowX)>0 and (mby - nowY)=0 Then//TracePrint "左"moveCompass(MoveArr[7])ElseIf (mbx - nowX)<0 and (mby - nowY)=0 Then//TracePrint "右" moveCompass(MoveArr[8])End IfEnd IfLoop End FunctionCall 自动寻路_八方位向限次(285, 606, 300, 3, 50)/*Dim MoveArr(9)Dim moveTime = 0MoveArr[1] = {"左下", 188, 192, 118, 261, moveTime}MoveArr[2] = {"左上", 188, 192, 263, 118, moveTime}MoveArr[3] = {"右下", 188, 192, 117, 118, moveTime}MoveArr[4] = {"右下", 188, 192, 266, 265, moveTime}MoveArr[5] = {"下", 188, 192, 89, 191, moveTime}MoveArr[6] = {"上", 188, 192, 296, 191, moveTime}MoveArr[7] = {"左", 188, 192, 191, 298, moveTime}MoveArr[8] = {"右", 188, 192, 191, 90, moveTime}For index = 1 To 8TracePrint "序号: "&indexFor Each a In MoveArr[index]TracePrint a()NextTracePrint "-------------------------------"NextmoveCompass (MoveArr[1])*/