Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. import java.awt.AWTException;
  2. import java.awt.Color;
  3. import java.awt.Rectangle;
  4. import java.awt.Robot;
  5. import java.awt.event.InputEvent;
  6. import java.awt.image.BufferedImage;
  7. import java.io.IOException;
  8.  
  9. public class MiscPrimary {
  10.  
  11. private static Color startPathNodeColor = new Color( 76, 178, 161 );
  12. private static Color nextPathNodeColor = new Color( 220, 126, 99 );
  13. private static Rectangle screenRect = new Rectangle( 670, 140, 630, 432 );
  14.  
  15. private static Robot robot;
  16.  
  17. public static void main(String[] args) throws IOException, AWTException {
  18. try {
  19.  
  20. robot = new Robot();
  21.  
  22. for (int i = 0; i < 3; i++) {
  23. while( doNextPathStart() ) {
  24. i = 0;
  25. Thread.sleep( 250 );
  26. while( doNextPathNode() ) {
  27. Thread.sleep( 100 );
  28. }
  29. System.out.println( "That path is done." );
  30. Thread.sleep( 500 );
  31. }
  32. System.out.println( "There are no more paths." );
  33. }
  34. Thread.sleep( 100 );
  35. System.out.println( "We're really sure there are no paths" );
  36.  
  37.  
  38.  
  39. } catch (Exception e) {}
  40. }
  41.  
  42. public static boolean doNextPathNode() {
  43. BufferedImage img = robot.createScreenCapture( screenRect );
  44. Vector nextClickPos = getNextPathNode( img );
  45. if( nextClickPos.x == -1 && nextClickPos.y == -1 ) {
  46. return false;
  47. }
  48. moveMouseto( nextClickPos );
  49. return true;
  50. }
  51.  
  52. public static boolean doNextPathStart() {
  53. BufferedImage img = robot.createScreenCapture( screenRect );
  54. Vector startNodePos = getNextStartNode( img );
  55. if( startNodePos.x == -1 && startNodePos.y == -1 ) {
  56. return false;
  57. }
  58. click( startNodePos );
  59. return true;
  60. }
  61.  
  62. public static void moveMouseto( Vector pos ) {
  63. robot.mouseMove(screenRect.x + pos.x, screenRect.y + pos.y);
  64. }
  65.  
  66. public static void click( Vector pos ) {
  67. moveMouseto( pos );
  68. robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
  69. try {
  70. Thread.sleep( 100 );
  71. } catch (InterruptedException e) {
  72. // TODO Auto-generated catch block
  73. e.printStackTrace();
  74. }
  75. robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
  76. }
  77.  
  78. public static Vector getNextStartNode( BufferedImage img ) {
  79. for (int x = 0; x < img.getWidth(); x++) {
  80. for (int y = 0; y < img.getHeight(); y++) {
  81. Color pixelColor = new Color( img.getRGB(x, y) );
  82.  
  83. if( pixelColor.equals( startPathNodeColor ) ) {
  84.  
  85. return new Vector( x, y );
  86. }
  87.  
  88. }
  89. }
  90. return new Vector( -1, -1 );
  91. }
  92.  
  93. public static Vector getNextPathNode( BufferedImage img ) {
  94. for (int x = 0; x < img.getWidth(); x++) {
  95. for (int y = 0; y < img.getHeight(); y++) {
  96. Color pixelColor = new Color( img.getRGB(x, y) );
  97.  
  98. if( pixelColor.equals( nextPathNodeColor ) ) {
  99.  
  100. return new Vector( x, y );
  101. }
  102.  
  103. }
  104. }
  105. return new Vector( -1, -1 );
  106. }
  107.  
  108. }
  109.  
  110.  
  111. public class Vector {
  112. int x, y;
  113.  
  114. public Vector( int x, int y ) {
  115. this.x = x;
  116. this.y = y;
  117. }
  118.  
  119. public String toString() {
  120. return "Vector( " + x + ", " + y + " )";
  121. }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement