我正在使用 java 尝试在 Pinball FX3 上重复击中交替的斜坡,游戏鱼的故事。我的策略是使用通常为绿色的像素,当它变为另一种颜色(银色)时,我可以使用计时器等待在最佳时间翻转。返回是如此一致,以至于一旦拨入该值,它就永远不会错过,也没有失败的机会。我正在尝试在左侧车道上使用一个像素,但我认为我没有得到正确的像素,因为它从来都不是绿色的。
package pinballReallyBadFishTales;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.ArrayList;
public class main {
public static void main(String[] args) throws AWTException, InterruptedException {
// TODO Auto-generated method stub
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
while(1==1) {
Robot r = new Robot();
ArrayList<Color> c = new ArrayList<Color>();
for(int i=0; i<1; i++) {
for(int j=0; j<1; j++) {
System.out.println(r.getPixelColor(565+i, 521+j));
c.add(r.getPixelColor(611+i, 535+j));
}
}
int counter = 0;
for(int i=0; i<c.size(); i++) {
if(isWithin(c.get(i).getRed(), c.get(i).getBlue(), 30)) {
if(isWithin(c.get(i).getRed(), c.get(i).getGreen(), 30)) {
if(isWithin(c.get(i).getGreen(), c.get(i).getBlue(), 30)) {
counter++;
}
}
}
}
//for(int i=0; i<c.size(); i++) {
//Color temp = c.get(i);
//if(temp.getGreen() > 200) {
//counter++;
// }
// }
if(counter > 20) {
r.keyPress(KeyEvent.VK_F);
r.keyPress(KeyEvent.VK_J);
Thread.sleep(300);
r.keyRelease(KeyEvent.VK_F);
r.keyRelease(KeyEvent.VK_J);
System.out.println("Shoot");
}
PointerInfo a = MouseInfo.getPointerInfo();
Point b = a.getLocation();
int x = (int) b.getX();
int y = (int) b.getY();
System.out.print(y + "jjjjjjjjj");
System.out.println(x);
}
}
public static boolean isWithin(int a, int b, int howMany) {
if(a>b) {
int difference = a-b;
if(difference < howMany) {
return true;
}
} else {
int difference = b-a;
if(difference < howMany) {
return true;
}
}
return false;
}
public void mouseClicked(MouseEvent e) {
PointerInfo a = MouseInfo.getPointerInfo();
Point point = new Point(a.getLocation());
SwingUtilities.convertPointFromScreen(point, e.getComponent());
int x=(int) point.getX();
int y=(int) point.getY();
System.out.println(x);
System.out.println(y);
}
}
我试过绕着这个点移动,看看它是否关闭,当我在这样的页面上时,它可以正确识别白色和黑色。但是当我进入游戏时,我似乎无法得到它看看正确的像素。