欢迎访问宙启技术站
智能推送

100行java写的微信跳一跳辅助程序

发布时间:2023-05-17 15:56:23

微信跳一跳这个小游戏现在非常受欢迎,但是有些难度很高,需要玩家需要有很高的技术,而且很容易出现失误。如果你也在玩跳一跳,那么不妨试试这个辅助程序。

这个辅助程序只需要100行Java代码就可以实现,非常简单易懂。

首先,我们需要知道跳一跳的规则。跳一跳的小人需要跳跃到不同的方块上,每次跳跃时,跳跃的距离会根据长按时间的长短而定,所以我们需要通过计算长按时间的长短来控制小人的跳跃距离。

下面是完整的代码:

import java.awt.AWTException;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.event.InputEvent;

public class WechatJumpBot {

    public static void main(String[] args) {
        Robot robot;
        try {
            robot = new Robot();
            // 循环执行跳一跳程序
            while (true) {
                // 获取手机屏幕截图
                BufferedImage image = robot.createScreenCapture(new Rectangle(0, 0, 1080, 1920));
                // 获取小人和下一个方块的坐标
                Point[] positions = findPositions(image);
                Point current = positions[0];
                Point next = positions[1];
                // 计算距离
                double distance = Math.sqrt(Math.pow(next.x - current.x, 2) + Math.pow(next.y - current.y, 2));
                // 计算按压时间
                int pressTime = (int) (distance * 1.35);

                // 随机按压位置防止封号
                int x = (int) (Math.random() * 50) + 150;
                int y = (int) (Math.random() * 10) + 600;

                // 按下鼠标左键
                robot.mouseMove(x, y);
                robot.mousePress(InputEvent.BUTTON1_MASK);
                robot.mouseRelease(InputEvent.BUTTON1_MASK);

                // 按压屏幕
                robot.mouseMove(x, y);
                robot.mousePress(InputEvent.BUTTON1_MASK);
                robot.delay(pressTime);
                robot.mouseRelease(InputEvent.BUTTON1_MASK);
            }
        } catch (AWTException e) {
            e.printStackTrace();
        }
    }

    /**
     * 查找小人和下一个方块的坐标
     *
     * @param image 屏幕截图
     * @return 坐标数组,      个元素为小人坐标,第二个元素为下一个方块的坐标
     */
    private static Point[] findPositions(BufferedImage image) {
        int width = image.getWidth();
        int height = image.getHeight();

        // 查找小人
        int currentX = 0, currentY = 0;
        loop:
        for (int y = height / 3; y < height * 2 / 3; y++) {
            for (int x = width / 8; x < width * 7 / 8; x++) {
                int pixel = image.getRGB(x, y);
                if (isColorEqual(pixel, 0x3E3E3E)) {
                    currentX = x;
                    currentY = y;
                    break loop;
                }
            }
        }

        // 查找下一个方块
        int nextX = 0, nextY = 0;
        int startX = (int) (width * 0.75);
        int startY = (int) (height / 2);
        loop:
        for (int y = startY; y < height * 2 / 3; y++) {
            for (int x = startX; x < width * 7 / 8; x++) {
                int pixel = image.getRGB(x, y);
                if (isColorEqual(pixel, 0x3E3E3E)) {
                    nextX = x;
                    nextY = y;
                    break loop;
                }
            }
        }

        return new Point[]{new Point(currentX, currentY), new Point(nextX, nextY)};
    }

    /**
     * 判断颜色是否相等
     *
     * @param pixel1 颜色1
     * @param pixel2 颜色2
     * @return 是否相等
     */
    private static boolean isColorEqual(int pixel1, int pixel2) {
        int threshold = 25;
        int r1 = (pixel1 >> 16) & 0xFF;
        int g1 = (pixel1 >> 8) & 0xFF;
        int b1 = pixel1 & 0xFF;
        int r2 = (pixel2 >> 16) & 0xFF;
        int g2 = (pixel2 >> 8) & 0xFF;
        int b2 = pixel2 & 0xFF;
        int diff = Math.abs(r1 - r2) + Math.abs(g1 - g2) + Math.abs(b1 - b2);
        return diff < threshold;
    }

    /**
     * 坐标点类
     */
    static class Point {
        int x;
        int y;

        public Point(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }
}

程序的主要流程:

1. 循环执行跳一跳程序

2. 获取手机屏幕截图

3. 查找小人和下一个方块的坐标

4. 计算距离

5. 计算按压时间

6. 随机按压位置防止封号

7. 按下鼠标左键

8. 按压屏幕

程序的具体实现可以参考代码注释。

使用此程序时,请注意:

1. 程序不能直接使用,需要根据自己的手机分辨率进行修改。可以在代码中修改手机截图的坐标。

2. 按压时间的计算方式是简单的距离乘以1.35,你可以根据自己的情况修改此处的计算方法。

3. 长按时间过长或过短都可能会导致小人跳的不太准确,需要根据自己的技巧进行微调。

综上所述,这个微信跳一跳辅助程序非常简单易懂,适合Java入门学习者,希望能够给大家一些帮助。