V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
qinrui
V2EX  ›  PHP

PHP 的跳一跳

  •  
  •   qinrui · 2017-12-31 12:27:11 +08:00 · 6465 次点击
    这是一个创建于 2300 天前的主题,其中的信息可能已经有所发展或是发生改变。
    水平很烂,瞎写的,见笑。

    <?php

    function jump() {
    sleep(2.5);//延迟 2.5 秒,音乐盒、便利店、井盖等站 2 秒加分
    $screenShell = "cd D:\&adb shell /system/bin/screencap -p /sdcard/screenshot.png&adb pull /sdcard/screenshot.png d:jumper/screenshot.png";
    exec($screenShell);//截图

    $i=imagecreatefrompng("d:jumper/screenshot.png");//读取图片
    $point=array();
    for ($y=400;$y<imagesy($i);$y++) {//从第 400 行开始,避开上部内容
    for ($x=0;$x<imagesx($i);$x++) {//横向扫描
    $rgb = imagecolorat($i,$x,$y);//取得颜色
    $point["now"]["r"] = ($rgb>>16) & 0xFF;
    $point["now"]["g"] = ($rgb>>8) & 0xFF;
    $point["now"]["b"] = $rgb & 0xFF;
    if(isset($point["last"]["r"])){
    if(!isset($point["x"]["a"])){
    if( abs($point["now"]["r"]-$point["last"]["r"])>1
    or abs($point["now"]["g"]-$point["last"]["g"])>1
    or abs($point["now"]["b"]-$point["last"]["b"])>1
    ){
    $point["x"]["a"]=$x;
    if(imagesx($i)/2>$x){
    $point["direction"]="left";
    }else{
    $point["direction"]="right";
    }
    $point["a"]=$point["last"];
    }
    }else{
    if($point["now"]==$point["a"]){
    $point["x"]["b"]=$x-1;
    break;
    }
    }
    }
    $point["last"]=$point["now"];
    }
    if(isset($point["x"])){
    break;
    }
    }

    $param["left"] = 3750;
    $param["right"] = 3100;
    $time = pow((abs(imagesx($i)/2-($point["x"]["a"]+$point["x"]["a"])/2)/imagesx($i)),1)*$param[$point["direction"]];

    if($time<400){
    $time+=($param[$point["direction"]]/300);
    }
    $time = round($time,0);
    echo "direction:".$point["direction"];
    echo "\nx.a:".$point["x"]["a"];
    echo "\nx.b:".$point["x"]["b"];
    echo "\ntime:".$time."\n";
    $touchShell = "cd D:\&adb shell input swipe 50 250 250 250 ".$time;
    exec($touchShell);
    imagedestroy($i);
    jump();
    }

    jump();
    2 条回复    2018-01-02 17:42:04 +08:00
    xiaome
        1
    xiaome  
       2017-12-31 13:17:16 +08:00
    城会玩,编程语言补全大赛么。
    medz
        2
    medz  
       2018-01-02 17:42:04 +08:00
    有一个意见给你,能不能把你的代码格式化一下?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1119 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 18:35 · PVG 02:35 · LAX 11:35 · JFK 14:35
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.