Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 11 of 11

Thread: Nothing really wrong but i cant seem to get past a stone wall

  1. #1
    Member
    Join Date
    Jan 2012
    Posts
    67
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Nothing really wrong but i cant seem to get past a stone wall

    <
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.Robot;
    import java.awt.AWTException;
    import java.awt.Rectangle;
    import java.awt.Color;
    import java.awt.Toolkit;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    import javax.imageio.ImageIO;
     
    public class GunningBot{
      public static void main(String[] args) throws Exception{
     
        Robot robot = new Robot();
    	Color color1 = new Color(196, 195, 181);
    	Color color2 = new Color(95, 118, 127);
    	Color color3 = new Color(114, 46, 33);
    	Color color4 = new Color(252, 200, 111);
     
    	{
    	Rectangle rectangle = new Rectangle(0, 0, 1365, 770);
     
        {
            BufferedImage image = robot.createScreenCapture(rectangle);
            search: for(int x = 0; x < rectangle.getWidth(); x++)
            {
                for(int y = 0; y < rectangle.getHeight(); y++)
                {
                    if(image.getRGB(x, y) == color1.getRGB())
                    {
                        robot.mouseMove(x, y);
    					    robot.mousePress(InputEvent.BUTTON1_MASK);
    						robot.delay(150);
    						robot.mouseRelease(InputEvent.BUTTON1_MASK);
                        break search;
                    }
                }
            }
        }
        {
            BufferedImage image = robot.createScreenCapture(rectangle);
            search: for(int x = 0; x < rectangle.getWidth(); x++)
            {
                for(int y = 0; y < rectangle.getHeight(); y++)
                {
                    if(image.getRGB(x, y) == color2.getRGB())
                    {
                        robot.mouseMove(x, y);
    					    robot.mousePress(InputEvent.BUTTON1_MASK);
    						robot.delay(150);
    						robot.mouseRelease(InputEvent.BUTTON1_MASK);
                        break search;
                    }
                }
            }
        }
    	{
            BufferedImage image = robot.createScreenCapture(rectangle);
            search: for(int x = 0; x < rectangle.getWidth(); x++)
            {
                for(int y = 0; y < rectangle.getHeight(); y++)
                {
                    if(image.getRGB(x, y) == color3.getRGB())
                    {
     
                        break search;
                    }
                }
            }
        }
     
    	}     
      }
    }
    >
    that's my code and whats wrong is before i can expand on it any more i need to do a check, let me explain what the code does:
    1. finds the Pixel with the indicated color
    2. clicks on it
    3. repeats step 1 for i different pixel
    4. repeats step 2 for a different pixel
    this is all to open a game, well a panel in the game

    read my bottom post for the question because i couldn't type last night so the above is mostly gibberish.
    Last edited by Lurie1; February 1st, 2012 at 10:20 AM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Nothing really wrong but i cant seem to get past a stone wall

    cant seem to do is code a check into the above code that will do as the methods above it do
    Please explain what the problem is. What does that statement mean?
    What is the "check" and what is the "do as the methods"?

    Which of the listed steps does the program do correctly and which does it not do?

    Please Edit your post and wrap your code with[code=java]<YOUR CODE HERE>[/code] to get highlighting

  3. #3
    Member
    Join Date
    Jan 2012
    Posts
    67
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Nothing really wrong but i cant seem to get past a stone wall

    ok sorry on reading it does seem quite badly written.

    what i want the program to do is:

    get the screenshot search it for a pixel, and move the mouse to that pixel, if it cant find the pixel i want it to go through the steps again, it could probably be done with a simple if/else statement but im new to java and don't really know how to set one up correctly or even which variable to check if the return is true.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Nothing really wrong but i cant seem to get past a stone wall

    What part of the problem is not working?
    Can you find the pixel with the color?
    Can you move the mouse to that location?

    If it can't find the pixel on the first pass over the image, what changes so that you expect it to find the pixel on a later pass?

    Please Edit your post and wrap your code with[code=java]<YOUR CODE HERE>[/code] to get highlighting

  5. #5
    Member
    Join Date
    Jan 2012
    Posts
    67
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Nothing really wrong but i cant seem to get past a stone wall

    ok so i can find the pixel and i can move the mouse, however the trouble is that after it finds the first pixel and clicks on it then finds the second pixel and clicks on it, the game updates and loads a new board so what i need is to have the program check and see if the third specified pixel is active and if it is then move on if its not i need it to take a new screenshot and try to find the pixel again because as it is now the program quits when it cant continue because the game is not loaded yet.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Nothing really wrong but i cant seem to get past a stone wall

    That sounds like you need to work out the logic for all the different cases and program them using if statements etc.
    There are many techniques for working out logic. I use flowcharts. Some use pseudo code.
    Do you have a technique for working out program logic?
    Bottom line, you need to work out the logic before you try to code it.

    What you just posted is close to pseudo code, try writing the logic making a list of the steps that need to be decided and the marking the loop back points for re starting the search.

  7. #7
    Member
    Join Date
    Jan 2012
    Posts
    67
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Nothing really wrong but i cant seem to get past a stone wall

    i do have the logic of the program:

    1. opens the game
    2. checks if game is open (the problem step)
    3. move mouse to center game screen
    4. do beginning game moves
    5. ect.

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Nothing really wrong but i cant seem to get past a stone wall

    Ok, which step of the logic are you having trouble coding?

  9. #9
    Member
    Join Date
    Jan 2012
    Posts
    67
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Nothing really wrong but i cant seem to get past a stone wall

    ok i can open the game, the screen dose not update until after i click on color2, however after color2 is clicked the screen is updated, or rather it stays the same until the new screen is drawn and populated with images, however i cant have my code clicking anything until the new screen is drawn. so i have color3, color3 is a color only seen on the game board and if i find it the game is loaded, if not the game hasn't loaded, what i need the program to do is take the screenshot and try to find color3 if it cannot find color3 then i need it to take another screenshot and try to find color3, and continue taking screenshots and looking for color3 until it finds color3 at which time i can move on to making the beginning game moves.

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Nothing really wrong but i cant seem to get past a stone wall

    I'm confused by who is doing what.
    screen does not update until after i click on color2
    Where does the program listen for and know about your clicks? How does that relate to the Robot class's clicks?
    What program updates the screen?
    i cant have my code clicking anything until the new screen is drawn.
    What screen? What code draws the new screen? How does your program know when a new screen is drawn?

    Are there other programs involved here? Is this a timing problem between when your program does something and the other program responds?

  11. #11
    Member
    Join Date
    Jan 2012
    Posts
    67
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Nothing really wrong but i cant seem to get past a stone wall

    ok sorry this is really confusing but don't worry this code was a total dud.

Similar Threads

  1. Please help not sure how to get past the Syntax error
    By KnightC in forum Other Programming Languages
    Replies: 2
    Last Post: December 23rd, 2011, 10:09 AM
  2. Raycasting Wall Texturing
    By SkyAphid in forum Java Theory & Questions
    Replies: 6
    Last Post: November 30th, 2011, 06:55 AM
  3. Make brick wall using BlueJ
    By boumasmoud in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 3rd, 2011, 04:32 PM
  4. problems getting past the out of bounds error
    By dbdny in forum What's Wrong With My Code?
    Replies: 4
    Last Post: April 28th, 2011, 05:57 PM
  5. Having Issues Past this
    By baGoGoodies111 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 12th, 2009, 08:19 PM