养成系列合成算法

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

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值