当前位置: 首页 > news >正文

Java实现碧蓝航线连续作战

目录

        • 一.实现功能
        • 二.主要思路
        • 三.代码实现
        • 四.用exe4j生成.exe程序
        • 五.最终效果
        • 六.代码开源

一.实现功能

主线图作战结束到结算页自动点击再次前往

二.主要思路

  • 判断是否进入了结算界面:记录结算界面某个像素点的RGB值,每隔3秒对这个像素点进行比对
  • 移动鼠标点击再次前往:Java提供的Robot类

三.代码实现

  • MainFrame.java
    主要实现系统托盘的图标,右键菜单栏,菜单项的响应事件
package com.simple.azurlane.view;import com.simple.azurlane.auto.MainLine;import javax.imageio.ImageIO;
import java.awt.*;
import java.io.IOException;
import java.util.Objects;public class MainFrame {public MainFrame() {//系统托盘SystemTray systemTray = SystemTray.getSystemTray();//菜单栏PopupMenu pop = new PopupMenu();MenuItem control = new MenuItem("start");MenuItem exit = new MenuItem("exit");pop.add(control);pop.addSeparator();pop.add(exit);control.addActionListener(e -> {if (control.getLabel().equals("start")) {MainLine.start();control.setLabel("stop");} else {MainLine.stop();control.setLabel("start");}});exit.addActionListener(e -> System.exit(0));try {TrayIcon trayIcon = new TrayIcon(ImageIO.read(Objects.requireNonNull(MainFrame.class.getClassLoader().getResourceAsStream("azurlane.jpg"))), "碧蓝航线", pop);trayIcon.setImageAutoSize(true);trayIcon.setToolTip("碧蓝航线");systemTray.add(trayIcon);} catch (IOException | AWTException e) {e.printStackTrace();}}public static void main(String[] args) {new MainFrame();}
}
  • MainLine.java
    主要实现像素点的比对,自动移动鼠标点击
package com.simple.azurlane.auto;import java.awt.*;
import java.awt.event.KeyEvent;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;public class MainLine {private static ScheduledExecutorService scheduledService;private static final Properties properties = new Properties();private static Robot robot;static {try {robot = new Robot();properties.load(MainLine.class.getClassLoader().getResourceAsStream("config.properties"));} catch (AWTException | IOException e) {e.printStackTrace();}}static int z = Integer.parseInt(properties.getProperty("z"));static int x1 = Integer.parseInt(properties.getProperty("x1"));static int y1 = Integer.parseInt(properties.getProperty("y1"));static int x2 = Integer.parseInt(properties.getProperty("x2")) / z;static int y2 = Integer.parseInt(properties.getProperty("y2")) / z;static List<String> rl = Arrays.asList(properties.getProperty("r").split(","));static List<String> gl = Arrays.asList(properties.getProperty("g").split(","));static List<String> bl = Arrays.asList(properties.getProperty("b").split(","));private static void autoWork() {Color pixelColor = robot.getPixelColor(x1, y1);if (validatePixelColor(rl, gl, bl, pixelColor)) {robot.mouseMove(x2, y2);robot.mousePress(KeyEvent.BUTTON1_MASK);robot.delay(200);robot.mouseRelease(KeyEvent.BUTTON1_MASK);robot.delay(200);robot.mouseMove(0, 0);}}/*** 校验一组颜色是否与之指定像素点颜色匹配* @param pixelColor 像素点颜色* @return true/false*/private static boolean validatePixelColor(List<String> rl, List<String> gl, List<String> bl, Color pixelColor) {for (int i = 0; i < rl.size(); i++) {if (String.valueOf(pixelColor.getRed()).equals(rl.get(i)) && String.valueOf(pixelColor.getGreen()).equals(gl.get(i)) && String.valueOf(pixelColor.getBlue()).equals(bl.get(i))) {return true;}}return false;}public static void start() {scheduledService = Executors.newScheduledThreadPool(1);scheduledService.scheduleAtFixedRate(MainLine::autoWork, 0, 3, TimeUnit.SECONDS);}public static void stop() {scheduledService.shutdownNow();scheduledService = null;System.gc();}
}
  • config.properties
#识别的像素点位置
x1=1600
y1=276
#鼠标点击位置
x2=1740
y2=1294
#匹配的rgb颜色
r=99,90,90
g=130,134,121
b=189,198,198
#分辨率-缩放比例
z=2

四.用exe4j生成.exe程序

具体参考我的这篇文章exe4j将jar包打成exe程序

五.最终效果

在这里插入图片描述

在这里插入图片描述

六.代码开源

所有代码已上传我的github仓库

http://www.lryc.cn/news/6465.html

相关文章:

  • Docker笔记
  • 情人节使用AI TOOL来创建一个甜言蜜语的女伴
  • G-GhostNet(IJCV 2022)原理与代码解析
  • Ethercat系列(5)TWcat3激活过程的协议分析(续1)
  • QT入门Input Widgets之QScrollBar
  • 【ML】基于机器学习的心脏病预测研究(附代码和数据集,多层感知机模型)
  • 工序排序问题--约翰逊法精讲
  • WebDAV之葫芦儿·派盘+网盘精灵
  • 计算机网络期末知识点总结
  • 【Vue3 组件封装】vue3 轮播图组件封装
  • 电力国家(行业)标准目录
  • 如何实现倒序输出
  • 遗留系统的自动化测试策略和实践方法
  • 【Android】系统源码下载及编译
  • 基于HTML实现浪漫情人节表白代码(附源代码)
  • PCL 平面拟合——RANSAC
  • 【Linux之Shell脚本实战】监控系统的磁盘空间使用率
  • 【Python安全编程】Python实现网络主机和端口扫描
  • 四大垃圾回收算法七大垃圾回收器
  • P1217 [USACO1.5]回文质数 Prime Palindromes
  • 用大白话给你科普,到底什么是 API(应用程序编程接口)?
  • 企业电子招采系统源码——信息数智化招采系统
  • 【vnc】Ubuntu20.04+vnc安装和配置(中文输入法)
  • 【排序算法】数据结构排序详解
  • 【docker知识】DockerFile语法 1:注释指令、解释器指令
  • [失业前端恶补算法]JavaScript leetcode刷题top100(一)
  • HTTP协议
  • javafx学习教程
  • 百度百科创建词条教程合集分享,赶紧收藏起来
  • 镜像恒流源电路分析