function add2EmptyLocation() {//往空地上放
/*
var emptyList=findMultiImgMax("empty_location.jpg","空位置",0.7,3,false,true);
if(emptyList.length>=1) {
var chouJiangImg=findImgPosition("chou_jiang.jpg","抽奖",0.7);
if(chouJiangImg) {
var y=chouJiangImg.y;
click(device.width/2,y);
}
}*/
var addCount=4;
while(addCount>0){
var addImg=findImgPosition("add_plane.jpg","添加",0.7);
if(addImg) {
click(device.width/2,addImg.y);
sleep(2000);
addCount--;
}else {
break;
}
}
}
function collectionShou() {//收集手的坐标
if(true) {
return true;
}
var fingerTryCount=0;
while(true) {
var shouImg=findImgPosition("finger_head.jpg","手指",0.7);
if(shouImg) {
fingerList.push(shouImg);
noHandleCount=-20;
}
fingerTryCount++;
if(fingerList.length>=4) {
performCombineAction(fingerList);
break;
}
if(fingerTryCount>10) {
tip("只凑"+fingerList.length+"只手");
if(fingerList.length<=1) {
tip("没有手,加飞机");
add2EmptyLocation();
var redPacketImg=findImgPosition("red_packet.jpg","红包",0.7);
if(redPacketImg) {
click(redPacketImg.x,redPacketImg.y);
}
}
break;
}
//sleep(500);
}
}
function performCombineAction(imgList) {//如果有合成的飞机,就合成
var isSucc=false;
var shouXLeft=device.width;
var shouYLeft=0;
var shouXRight=0;
var shouYRight=0;
var measureCount=0;
var measureCountMax=3;
var xList=[];
var yList=[];
var imgIndex=0;
while(true)
{
var shouView=null;
if(imgIndex<imgList.length) {
shouView=imgList[imgIndex];
}else {
tip("手角标不够了");
break;
}
//var shouView=findImgPosition("finger_head.jpg","手指",0.7);//findImgPositionCustomDiff
if(shouView)
{
shouView.x=shouView.x-shouView.width/2;//校正为小鱼的中心位置
shouView.y=shouView.y-shouView.height/2;
//tip("手纠正坐标后的point = " + shouView);
if(shouView.y<device.height/3) {
tip("应该是分红的手");
click(shouView.x,shouView.y);
continue;
}
xList.push(shouView.x);
yList.push(shouView.y);
imgIndex++;
if(shouView.x<shouXLeft)
{
shouXLeft=shouView.x;
shouYLeft=shouView.y;
}
if(shouView.x>shouXRight)
{
shouXRight=shouView.x;
shouYRight=shouView.y;
}
measureCount++;
tip("已识别"+measureCount+"次");
if(measureCount==measureCountMax)
{
if(Math.abs(xList[0]-xList[1])<20&&Math.abs(xList[0]-xList[2])<20)
{
tip("应该是竖排的手指");
for(var i=0;i<xList.length;i++)
{
var key=xList[i];
var value=yList[i];
if(value<shouYLeft)
{
shouXLeft=key;
shouYLeft=value;
}
if(value>shouYRight)
{
shouXRight=key;
shouYRight=value;
}
tip(i+"("+key+","+value+")");
}
}
else
{
tip("xList[0]="+xList[0]+",xList[1]="+xList[1]);
}
break;
}
}
else
{
break;
}
}
if(measureCount==measureCountMax)
{
var swipeTime=calculateSwipeTime(shouXLeft,shouYLeft,shouXRight,shouYRight);
tip("滑动耗时="+swipeTime);
if(swipeTime>0) {
uiUtil.addPointColor(shouXLeft,shouYLeft,false,"#0000ff");
uiUtil.addPointColor(shouXRight,shouYRight,true,"#0000ff");
if(shouYLeft<shouYRight)//这两种都是不让往上滑,避免飞机被卖出
{
tip("滑动,x1="+shouXLeft+",y1="+shouYLeft+",x2="+shouXRight+",y2="+shouYRight);
swipe(shouXLeft,shouYLeft,shouXRight,shouYRight,swipeTime);//random(400,800));
}
else
{
tip("滑动,x1="+shouXRight+",y1="+shouYRight+",x2="+shouXLeft+",y2="+shouYLeft);
swipe(shouXRight,shouYRight,shouXLeft,shouYLeft,swipeTime);//random(400,800));
}
isSucc=true;
}else {//应该是最底部的手
tip("没有可配对的飞机了");
}
forbidClickRedPacketCount--;
fingerList=[];
}
else {
tip("手的数量不够="+measureCount);
}
return isSucc;
}
function calculateSwipeTime(x1,y1,x2,y2)//计算滑动的合成时间,因为不同的两个距离,最好使用不同的时间,应该能提高成功率吧
{
var diffX=x1-x2;
var diffY=y1-y2;
var tempDistance=Math.sqrt(diffX*diffX+diffY*diffY);
return 400*tempDistance/(device.width/5);
}
养成系列合成算法
最新推荐文章于 2024-04-26 13:40:31 发布