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.

Page 2 of 3 FirstFirst 123 LastLast
Results 26 to 50 of 61

Thread: Making a method to move blocks in a grid

  1. #26
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Making a method to move blocks in a grid

    Again it looks like you are trying to write code. Where are the steps for #4?
    I'd expect something like this:

    begin loop to work on a row
    do things needed for this row
    begin loop to work on the columns for this row
    compute location for next shape
    get color for next shape
    create shape using color and location
    save shape in list
    end loop for columns this row
    end loop for rows
    If you don't understand my answer, don't ignore it, ask a question.

  2. #27
    Member
    Join Date
    May 2012
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Making a method to move blocks in a grid

     
    public static java.util.List<acm.graphics.GRect> createPlayfield()
    {
         Random r = new Random();
         List<GRect> l = null;
         int x = 0;
         int y = ROWZERO - BLOCKHEIGHT;
         Color c = new Color(r.nextInt(256),r.nextInt(256),r.nextInt(256));
     
         for (i = 0; i <= BLOCKROWS; i++) // is this part of grid?
         {
            i = i * ROWSEPARATION + ROWZERO;
              for (j = 0; j <= NBLOCKS; j++) // is this part of grid?
              {
                 j = j * BLOCKWIDTH;
                 addBrick(l,l.getX(),l.getY(),BLOCKWIDTH,BLOCKHEIGHT,l.getColor());
              } 
          }
            return l;
    }

    The problem now is that the i and j are just there, they aren't doing anything because I didn't set anything to it, and there is no grid because I have to put BLOCKROWS x NBLOCK or is that described in the for loop
    Last edited by geforce; May 21st, 2012 at 06:27 PM.

  3. #28
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Making a method to move blocks in a grid

    now is that the i and j are just there, they aren't doing anything
    Do they keep track of the row and column?
    If you don't understand my answer, don't ignore it, ask a question.

  4. #29
    Member
    Join Date
    May 2012
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Making a method to move blocks in a grid

    Yes they do but I didn't make it keep track of the row and column or is that automatic because its a for-loop

  5. #30
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Making a method to move blocks in a grid

    That would be how you would use the loops (see post#26). Outer loop for rows, inner loop for columns.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #31
    Member
    Join Date
    May 2012
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Making a method to move blocks in a grid

    "do things needed for this row", "do things needed for this column" is missing is that a typo? and also for "do things needed for this row" would it be i = i * ROWSEPARATION + ROWZERO; or is there a different way of doing this.

  7. #32
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Making a method to move blocks in a grid

    Can you say in words what the code you posted is supposed to do?

    Sometimes there is nothing to be done. The comment: "do things for this ..." was just a reminder and a place holder in case there was something.
    If you don't understand my answer, don't ignore it, ask a question.

  8. #33
    Member
    Join Date
    May 2012
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Making a method to move blocks in a grid

    for i
    do i = i * ROWSEPARATION + ROWZERO

    for j
    do j = j * BLOCKWIDTH

  9. #34
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Making a method to move blocks in a grid

    What is the purpose of that code?

    You're mixing two things together. One variable needs to keep track of the row (or column) and the other needs to be used to locate the shape's x (and y) location on the grid. The x and y values are computed using the row and column values.
    Last edited by Norm; May 21st, 2012 at 07:03 PM.
    If you don't understand my answer, don't ignore it, ask a question.

  10. #35
    Member
    Join Date
    May 2012
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Making a method to move blocks in a grid

    Thats exactly where I'm lost, have no Idea about what to do with that code i just know i*ROWSEPARATION + ROWZERO is supposed to be implemented, I have no idea where though, same with j'th column.

  11. #36
    Member
    Join Date
    May 2012
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Making a method to move blocks in a grid

    Maybe that is iterated through every i and put into the block same with j'th column.

  12. #37
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Making a method to move blocks in a grid

    I'm lost, have no Idea about what to do with that code
    Finish the steps in the design first before working on the code.
    Take a piece of paper and draw the shapes on it as they are supposed to go in the grid.
    Label the locations of each shape using the values/variables given in the assignment statement.

    Where is ROWZERO? How is ROWSEPARATION used.
    If you don't understand my answer, don't ignore it, ask a question.

  13. #38
    Member
    Join Date
    May 2012
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Making a method to move blocks in a grid

    ROWZERO is the vertical offset, in pixels from the top of the screen to the top of the first row of
    blocks

    ROWSEPARATION is the vertical separation between rows.

    So for every i on the upper edge, the row is seperated and then thrown to the top of the screen from its position.

    For every j on the left edge j is multipled by the BLOCKWEIGHT so for every j the weight of the block is fit to j? not sure.

  14. #39
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Making a method to move blocks in a grid

    Again you are mixing the row and column values with the x and y locations for the shapes.
    If you don't understand my answer, don't ignore it, ask a question.

  15. #40
    Member
    Join Date
    May 2012
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Making a method to move blocks in a grid

    Quote Originally Posted by Norm View Post
    Again you are mixing the row and column values with the x and y locations for the shapes.
    The row is vertically seperated and then moved to a location

    The column is enlarged at that rows location

  16. #41
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Making a method to move blocks in a grid

    Can you now put together the detailed simple steps for step#4?
    If you don't understand my answer, don't ignore it, ask a question.

  17. #42
    Member
    Join Date
    May 2012
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Making a method to move blocks in a grid

    i and j are put on a grid, j depends on i, so..

    for i
    for j
    do i * j? still not sure

    and then put into the list?
    Last edited by geforce; May 21st, 2012 at 07:50 PM.

  18. #43
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Making a method to move blocks in a grid

    I'm asking for the steps in English (pseudo code) that the program needs to do for step#4.
    If you don't understand my answer, don't ignore it, ask a question.

  19. #44
    Member
    Join Date
    May 2012
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Making a method to move blocks in a grid

    for every i equal to 0 to BLOCKROWS
    for every j equal to 0 to NBLOCKS
    perform addbrick
    perform i added to j
    add (i added to j) to location of list

  20. #45
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Making a method to move blocks in a grid

    where do you compute the x and y values for the locations of the shapes?
    Where is the color created?

    What are the last two steps for?
    If you don't understand my answer, don't ignore it, ask a question.

  21. #46
    Member
    Join Date
    May 2012
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Making a method to move blocks in a grid

    for every i equal to 0 to BLOCKROWS
    for every j equal to 0 to NBLOCKS
    perform addbrick
    perform i added to j
    add (i added to j) to location of list
    Last edited by geforce; May 21st, 2012 at 08:22 PM.

  22. #47
    Member
    Join Date
    May 2012
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Making a method to move blocks in a grid

    for every i equal to 0 to BLOCKROWS
    for every j equal to 0 to NBLOCKS
    create x and y to compute location
    create colour
    perform addbrick
    create i
    create j
    perform i * j
    add (i * j) to list
    return the list
    Last edited by geforce; May 21st, 2012 at 08:30 PM.

  23. #48
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Making a method to move blocks in a grid

    You'll need the x & y for addbrick()

    What are the last two steps for?
    If you don't understand my answer, don't ignore it, ask a question.

  24. #49
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Making a method to move blocks in a grid

    Why are you writing code before finishing the design?
    If you don't understand my answer, don't ignore it, ask a question.

  25. #50
    Member
    Join Date
    May 2012
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Making a method to move blocks in a grid

    6) and 7) and computed together and added to the list?
    Last edited by geforce; May 21st, 2012 at 08:24 PM.

Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. BufferedReader.read() blocks,when checking if there's any input for some URLs
    By redateksystem in forum File I/O & Other I/O Streams
    Replies: 8
    Last Post: March 27th, 2012, 09:33 AM
  2. Need help making an image move from one side of screen to the other.
    By Xillius200 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 25th, 2011, 12:46 PM
  3. [SOLVED] Things Won't Move
    By zeraxis in forum What's Wrong With My Code?
    Replies: 4
    Last Post: September 2nd, 2011, 08:46 AM
  4. Grid bag layout inside grid bag layout
    By kiddkoder in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 29th, 2011, 08:07 AM
  5. Nested try blocks
    By Ahmed. in forum Member Introductions
    Replies: 2
    Last Post: April 30th, 2010, 08:12 AM