Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Arrays. Again.
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Neja




PostPosted: 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 (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 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
Sponsor
sponsor
SuperGenius




PostPosted: 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




PostPosted: 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.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: