Making a method to move blocks in a grid

Printable View

Show 40 post(s) from this thread on one page
Page 2 of 3 First 123 Last
• May 21st, 2012, 05:40 PM
Norm
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
• May 21st, 2012, 06:09 PM
geforce
Re: Making a method to move blocks in a grid
Code java:

```  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
• May 21st, 2012, 06:30 PM
Norm
Re: Making a method to move blocks in a grid
Quote:

now is that the i and j are just there, they aren't doing anything
Do they keep track of the row and column?
• May 21st, 2012, 06:31 PM
geforce
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
• May 21st, 2012, 06:36 PM
Norm
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.
• May 21st, 2012, 06:40 PM
geforce
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.
• May 21st, 2012, 06:51 PM
Norm
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.
• May 21st, 2012, 06:54 PM
geforce
Re: Making a method to move blocks in a grid
for i
do i = i * ROWSEPARATION + ROWZERO

for j
do j = j * BLOCKWIDTH
• May 21st, 2012, 07:00 PM
Norm
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.
• May 21st, 2012, 07:04 PM
geforce
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.
• May 21st, 2012, 07:06 PM
geforce
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.
• May 21st, 2012, 07:07 PM
Norm
Re: Making a method to move blocks in a grid
Quote:

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.
• May 21st, 2012, 07:25 PM
geforce
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.
• May 21st, 2012, 07:28 PM
Norm
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.
• May 21st, 2012, 07:37 PM
geforce
Re: Making a method to move blocks in a grid
Quote:

Originally Posted by Norm
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
• May 21st, 2012, 07:40 PM
Norm
Re: Making a method to move blocks in a grid
Can you now put together the detailed simple steps for step#4?
• May 21st, 2012, 07:46 PM
geforce
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?
• May 21st, 2012, 07:53 PM
Norm
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.
• May 21st, 2012, 08:04 PM
geforce
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
• May 21st, 2012, 08:14 PM
Norm
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?
• May 21st, 2012, 08:16 PM
geforce
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
• May 21st, 2012, 08:18 PM
geforce
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
• May 21st, 2012, 08:18 PM
Norm
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?
• May 21st, 2012, 08:20 PM
Norm
Re: Making a method to move blocks in a grid
Why are you writing code before finishing the design?
• May 21st, 2012, 08:20 PM
geforce
Re: Making a method to move blocks in a grid
6) and 7) and computed together and added to the list?
Show 40 post(s) from this thread on one page
Page 2 of 3 First 123 Last