java做辅助_用Java做一个跳一跳辅助

Java跳一跳辅助

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

19408ed303424ddd056da1f0f735954c.gif

由于是闲着没事写的。也懒得看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) {

}

}

}

}

作者:秃桔子

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值