Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.AWTException;
- import java.awt.Color;
- import java.awt.Rectangle;
- import java.awt.Robot;
- import java.awt.event.InputEvent;
- import java.awt.image.BufferedImage;
- import java.io.IOException;
- public class MiscPrimary {
- private static Color startPathNodeColor = new Color( 76, 178, 161 );
- private static Color nextPathNodeColor = new Color( 220, 126, 99 );
- private static Rectangle screenRect = new Rectangle( 670, 140, 630, 432 );
- private static Robot robot;
- public static void main(String[] args) throws IOException, AWTException {
- try {
- robot = new Robot();
- for (int i = 0; i < 3; i++) {
- while( doNextPathStart() ) {
- i = 0;
- Thread.sleep( 250 );
- while( doNextPathNode() ) {
- Thread.sleep( 100 );
- }
- System.out.println( "That path is done." );
- Thread.sleep( 500 );
- }
- System.out.println( "There are no more paths." );
- }
- Thread.sleep( 100 );
- System.out.println( "We're really sure there are no paths" );
- } catch (Exception e) {}
- }
- public static boolean doNextPathNode() {
- BufferedImage img = robot.createScreenCapture( screenRect );
- Vector nextClickPos = getNextPathNode( img );
- if( nextClickPos.x == -1 && nextClickPos.y == -1 ) {
- return false;
- }
- moveMouseto( nextClickPos );
- return true;
- }
- public static boolean doNextPathStart() {
- BufferedImage img = robot.createScreenCapture( screenRect );
- Vector startNodePos = getNextStartNode( img );
- if( startNodePos.x == -1 && startNodePos.y == -1 ) {
- return false;
- }
- click( startNodePos );
- return true;
- }
- public static void moveMouseto( Vector pos ) {
- robot.mouseMove(screenRect.x + pos.x, screenRect.y + pos.y);
- }
- public static void click( Vector pos ) {
- moveMouseto( pos );
- robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
- try {
- Thread.sleep( 100 );
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
- }
- public static Vector getNextStartNode( BufferedImage img ) {
- for (int x = 0; x < img.getWidth(); x++) {
- for (int y = 0; y < img.getHeight(); y++) {
- Color pixelColor = new Color( img.getRGB(x, y) );
- if( pixelColor.equals( startPathNodeColor ) ) {
- return new Vector( x, y );
- }
- }
- }
- return new Vector( -1, -1 );
- }
- public static Vector getNextPathNode( BufferedImage img ) {
- for (int x = 0; x < img.getWidth(); x++) {
- for (int y = 0; y < img.getHeight(); y++) {
- Color pixelColor = new Color( img.getRGB(x, y) );
- if( pixelColor.equals( nextPathNodeColor ) ) {
- return new Vector( x, y );
- }
- }
- }
- return new Vector( -1, -1 );
- }
- }
- public class Vector {
- int x, y;
- public Vector( int x, int y ) {
- this.x = x;
- this.y = y;
- }
- public String toString() {
- return "Vector( " + x + ", " + y + " )";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement