zoukankan      html  css  js  c++  java
  • 用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 秃桔子
     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) {
                    
                }
            }
        }
        
    }
  • 相关阅读:
    剑指Offer-11.二进制中1的个数(C++/Java)
    剑指Offer-10.矩形覆盖(C++/Java)
    剑指Offer-9.变态跳台阶(C++/Java)
    UVA 1608 Non-boring sequence 不无聊的序列(分治,中途相遇)
    UVA1607 Gates 与非门电路 (二分)
    UVA 1451 Average平均值 (数形结合,斜率优化)
    UVA 1471 Defense Lines 防线 (LIS变形)
    UVA 1606 Amphiphilic Carbon Molecules 两亲性分子 (极角排序或叉积,扫描法)
    UVA 11134 FabledRooks 传说中的车 (问题分解)
    UVA 1152 4 Values Whose Sum is Zero 和为0的4个值 (中途相遇)
  • 原文地址:https://www.cnblogs.com/godoforange/p/10995196.html
Copyright © 2011-2022 走看看