用Java做一个跳一跳辅助

Java跳一跳辅助

首先。。让大家看下效果:

由于是闲着没事写的。也懒得看OpenCV的API了。

要用到的工具如下:

adb+jdk

把adb添加到环境变量里就行。很简单。

全部代码如下。就这么多。。。

package A;

import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JFrame;

public class JumpAndJump extends JFrame implements MouseListener,Runnable{
    /**
     * 
     */
    public void Jump(int ms) {
        try {
            int a = (int) (Math.random() * 1000);
            int b = (int) (Math.random() * 1000);
            int c = (int) (Math.random() * 1000);
            int d = (int) (Math.random() * 1000);
            Runtime.getRuntime().exec("adb shell input swipe " + a + " " + b + " " + c + " " + d + " " + ms);
        } catch (IOException e) {

        }
    }

    public void getPNG() {
        try {
            Runtime.getRuntime().exec("adb shell screencap -p /sdcard/1.png");
            Runtime.getRuntime().exec("adb pull /sdcard/1.png");
        } catch (Exception e) {

        }
    }

    public int X1 = 0;
    public int X2 = 0;
    public int Y1 = 0;
    public int Y2 = 0;
    public int sign = 0;
    public int one = 0;
    private static final long serialVersionUID = 1L;
    

    public JumpAndJump(String title) {
        super(title);
        this.setSize(900, 900);
        this.setLocation(600, 100);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);
        this.setResizable(false);
        this.addMouseListener(this);
    }

    @Override
    public void mouseClicked(MouseEvent arg0) {

    }

    @Override
    public void mouseEntered(MouseEvent e) {

    }

    @Override
    public void mouseExited(MouseEvent e) {

    }

    @Override
    public void mousePressed(MouseEvent e) {
        System.out.println(e.getX()+"..."+e.getY());
        if (e.getX() < 550) {
            if (sign == 0) {
                X1 = e.getX();
                Y1 = e.getY();
                sign++;
            } else {
                sign = 0;
                X2 = e.getX();
                Y2 = e.getY();
                int res = (X2 - X1) * (X2 - X1) + (Y2 - Y1) * (Y2 - Y1);
                double b = Math.sqrt(res);
                System.out.println(b);
                Jump((int) b * 3);
            }
        }else if(e.getX()>690&&e.getX()<760&&e.getY()>60&&e.getY()<90) {
            
            System.out.println("获取图片");
            this.repaint();
        }
    }

    @Override
    public void mouseReleased(MouseEvent e) {

    }

    @Override
    public void paint(Graphics g) {
        BufferedImage image = null;
        try {
            File file = new File("1.png");
            image = ImageIO.read(file);
        } catch (Exception e) {

        }
        if (image != null) {
            g.drawImage(image, 10, 10, image.getWidth(this) / 2, image.getHeight(this) / 2, null);
        }
        g.drawString("code by 秃桔子\r\n QQ:1243137612", 700, 100);
    }

    public static void main(String[] args) {
        JumpAndJump w = new JumpAndJump("AAA");
        w.run();
    }

    @Override
    public void run() {
        while(true) {
            getPNG();
            this.repaint();
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                
            }
        }
    }
    
}

 

posted @ 2019-06-09 22:33  秃桔子  阅读(595)  评论(0编辑  收藏  举报

如果您有编程方面或者学术方面的需求请在微信公众号搜索

桔子科研


或者识别下方二维码,第一时间获取编程有趣的知识和最新科研学术成果。