Skip to content

Commit

Permalink
Merge pull request #31 from bambootang/automode-bugfix
Browse files Browse the repository at this point in the history
改进容易让人崩溃的-r参数为程序自动计算
  • Loading branch information
easyworld authored Dec 31, 2017
2 parents 4d000b0 + 5a2df0e commit f7f1eda
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 31 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ adb shell screencap <filename> # 保存截屏到手机
adb pull /sdcard/screen.png # 下载截屏文件到本地
```

## 使用方法
## 使用方法
**当前最新代码版本为0.0.4**
1. 在电脑上下载好adb,并安装JDK7及以上版本以及配置好java环境变量
2. 打开安卓手机的usb调试模式并授权连接的电脑
> 如果是小米手机,在USB调试下方有``USB调试(安全设置)``打开允许模拟点击 感谢[@wotermelon](https://github.com/wotermelon)
Expand All @@ -33,15 +34,14 @@ java -jar playJumpJumpWithMouse.jar -a "C:\Users\Home\Desktop\platform-tools\adb
## 半自动以及全自动模式

```
-m 1: manual-mode , 2: semi-mode , 3: auto-mode
-m 1: manual-mode , 2: semi-mode(default) , 3: auto-mode
```
### 说明
* 手动模式(manual-mode):弹出的窗口中先点击小人底部适当位置,然后再点想要跳的箱子的中心位置即可完成.
* 半自动模式(semi-mode):只需要点击一次鼠标,即只需要点击终点的中心点就可以了.(默认模式)
* 全自动模式(auto-mode):也就是挂机模式,不需要人工操作,启动后既可以自动识别算法自动帮你玩跳一跳.该模式会**忽略** -s 参数,强制使用手机分辨率
* 全自动模式(auto-mode):也就是挂机模式,不需要人工操作,启动后既可以自动识别算法自动帮你玩跳一跳.

## 一些需要注意的点
* 如果在全自动模式发现跳跃不准确,需要自行调整ratio参数。在1080x1920分辨率下,ratio推荐值为1.374
* 有些安卓机并不能很好的使用adb exec-out,导致截屏异常,可以尝试使用[老代码](https://github.com/easyworld/PlayJumpJumpWithMouse/blob/0ba11f1968db2a46660562f1b27d3925eec1b9ce/src/com/company/AdbCaller.java)替换现有方法

## 运行截图
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.company</groupId>
<artifactId>playJumpJumpWithMouse</artifactId>
<version>0.0.3</version>
<version>0.0.4</version>
<packaging>jar</packaging>

<name>playJumpJumpWithMouse</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ public BackgroundImage4Panel() {
/**
* 测试入口
*
* @param args
* 参数列表
* @param args 参数列表
*/
public static void main(String[] args) {

Expand All @@ -65,7 +64,7 @@ public static void main(String[] args) {
options.addOption(opt);

opt = new Option("a", "adb-path", true,
"adb path in system, eg: C:\\Users\\RoyZ\\Desktop\\platform-tools\\adb.exe");
"adb path in system,required, eg: C:\\Users\\RoyZ\\Desktop\\platform-tools\\adb.exe");
opt.setRequired(true);
options.addOption(opt);

Expand All @@ -78,15 +77,11 @@ public static void main(String[] args) {
opt.setRequired(false);
options.addOption(opt);

opt = new Option("r", "ratio", true, "resized distance press time ratio, eg: 2.19");
opt.setRequired(false);
options.addOption(opt);

opt = new Option("t", "interval", true, "screenshot interval, unit millisecond, eg: 2500");
opt.setRequired(false);
options.addOption(opt);

opt = new Option("m", "play-mode", true, "1: manual-mode , 2: semi-mode , 3: auto-mode ");
opt = new Option("m", "play-mode", true, "1: manual-mode , 2: semi-mode(default) , 3: auto-mode ");
opt.setRequired(false);
options.addOption(opt);

Expand Down Expand Up @@ -120,11 +115,6 @@ public static void main(String[] args) {
resizedScreenWidth = Constants.RESIZED_SCREEN_WIDTH;
resizedScreenHeight = Constants.RESIZED_SCREEN_HEIGHT;
}
if (commandLine.getOptionValue('r') != null) {
resizedDistancePressTimeRatio = Double.parseDouble(commandLine.getOptionValue('r'));
} else {
resizedDistancePressTimeRatio = Constants.RESIZED_DISTANCE_PRESS_TIME_RATIO;
}
if (commandLine.getOptionValue('t') != null) {
screenshotInterval = Integer.parseInt(commandLine.getOptionValue('t'));
} else {
Expand All @@ -140,18 +130,19 @@ public static void main(String[] args) {
hf.printHelp("PlayJumpJumpWithMouse", options, true);
return;
}

//去掉了-r参数,改成根据width来进行自动换算.
resizedDistancePressTimeRatio = Constants.RESIZED_DISTANCE_PRESS_TIME_RATIO * Constants.RESIZED_SCREEN_WIDTH / resizedScreenWidth;
if (playMode == Constants.MODE_MANUAL || playMode == Constants.MODE_SEMI_AUTO) {
manualMode(resizedScreenWidth, resizedScreenHeight, resizedDistancePressTimeRatio, screenshotInterval,
screenshotPath);
manualMode(resizedScreenWidth, resizedScreenHeight, resizedDistancePressTimeRatio,
screenshotInterval, screenshotPath);
} else if (playMode == Constants.MODE_AUTO) {
autoJumpMode(resizedDistancePressTimeRatio, screenshotInterval, screenshotPath);
autoJumpMode(screenshotInterval, screenshotPath);
}

}

private static void manualMode(final int resizedScreenWidth, final int resizedScreenHeight,
final double resizedDistancePressTimeRatio, final int screenshotInterval, final String screenshotPath) {
final double resizedDistancePressTimeRatio, final int screenshotInterval, final String screenshotPath) {

AdbCaller.printScreen();
final BackgroundImage4Panel backgroundImage4Panel = new BackgroundImage4Panel();
Expand Down Expand Up @@ -241,21 +232,23 @@ public void mouseExited(MouseEvent e) {
});
}

private static void autoJumpMode(final double resizedDistancePressTimeRatio, final int screenshotInterval,
final String screenshotPath) {
private static void autoJumpMode(final int screenshotInterval,
final String screenshotPath) {
new Thread() {
public void run() {
while (true) {
AdbCaller.printScreen();
try {
BufferedImage bufferedImage = ImageIO.read(new File(screenshotPath));
//自动模式的魔数也改为自动计算
double resizedDistancePressTimeRatio = Constants.RESIZED_DISTANCE_PRESS_TIME_RATIO * Constants.RESIZED_SCREEN_WIDTH / bufferedImage.getWidth();
firstPoint = StartCenterFinder.findStartCenter(bufferedImage);
secondPoint = EndCenterFinder.findEndCenter(bufferedImage, firstPoint);
// System.out.println(firstPoint + " , " + secondPoint);
int distance = secondPoint == null ? 0 : distance(firstPoint, secondPoint);
if (secondPoint == null || secondPoint.getX() == 0 || distance < 75 ||
// true || //放开可改为全部用ColorFilterFinder来做下一个中心点的查找
Math.abs(secondPoint.getX() - firstPoint.getX()) < 38) {
// true || //放开可改为全部用ColorFilterFinder来做下一个中心点的查找
Math.abs(secondPoint.getX() - firstPoint.getX()) < 38) {
secondPoint = ColorFilterFinder.findEndCenter(bufferedImage, firstPoint);
if (secondPoint == null) {
AdbCaller.printScreen();
Expand All @@ -272,10 +265,10 @@ public void run() {
ColorFilterFinder.updateLastShapeMinMax(bufferedImage, firstPoint, secondPoint);
distance = distance(firstPoint, secondPoint);
AdbCaller.longPress(distance * resizedDistancePressTimeRatio);// magic
// number
// number
try {
Thread.sleep(screenshotInterval);// wait for
// screencap
// screencap
} catch (InterruptedException e1) {
e1.printStackTrace();
}
Expand All @@ -291,8 +284,7 @@ public void run() {
/**
* 对图片进行强制放大或缩小
*
* @param originalImage
* 原始图片
* @param originalImage 原始图片
* @return
*/
public static BufferedImage zoomInImage(BufferedImage originalImage, int width, int height) {
Expand Down

0 comments on commit f7f1eda

Please sign in to comment.