Arrays. Again.
Author 
Message 
Neja

Posted: Tue Jun 08, 2004 1:12 pm Post subject: Arrays. Again. 


Allright, Tetris was annoying me and I'm running out of time, so I've sort of simplified it. Instead of hapes being dropped, I have two boxes of random colours (each can be different) dropping. The object is to make three in a row (horixontal, vertical, even in "L" shapes). The problem I'm having is this; I havae the boxes dropping (using arrays), and I can speed them up if you press the down button as well as move to the left, but for some reason, the same logic does not apply to moving them to the right.
[/code]
var grid : array 1 .. 20, 1 .. 20 of int
for i : 1 .. 20
for j : 1 .. 20
grid (i, j) := 0
end for
end for
loop
for i : 1 .. 20 % For down.
for j : 1 .. 20
if grid (i, j) not= 0 and j > 1 then
if grid (i, j  1) = 0 then
grid (i, j  1) := grid (i, j)
grid (i, j) := 0
end if
end if
end for
end for
/*for i : 1 .. 20 % For down. % For moving left.
for j : 1 .. 20
if grid (i, j) not= 0 and i > 1 then
if grid (i1, j ) = 0 then
grid (i1, j := grid (i, j)
grid (i, j) := 0
end if
end if
end for
end for
for i : 1 .. 20 % For down. % For moving right, but it doesn't work.
for j : 1 .. 20
if grid (i, j) not= 0 and i > 1 then
if grid (i+1, j ) = 0 then
grid (i+1, j := grid (i, j)
grid (i, j) := 0
end if
end if
end for
end for
*/
for i : 1 .. 20
for j : 1 .. 20
Draw.FillBox (i * width, j * width, i * width + width, j * width + width, grid (i, j))
end for
end for
for i : 1 .. 20
for j : 1 .. 20
Draw.Box (i * width, j * width, i * width + width, j * width + width, gray)
end for
end for
View.Update
delay (200)
end loop
code: 
It's a little out of order, beccuase I cut and pasted, but that's basically it. 






Sponsor Sponsor



SuperGenius

Posted: Tue Jun 08, 2004 4:03 pm Post subject: (No subject) 


you code has a lot of errors. it is difficult for me to understand what you are doing; also if you document your program it is easier to help.






Neja

Posted: Tue Jun 08, 2004 10:30 pm Post subject: (No subject) 


Thank you anyways. I got it. The problem was that for the right, I should be using a for decreasing loop.







