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

Username:   Password: 
 RegisterRegister   
 Tetris (again)- giving a value to a 2d array
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Neja




PostPosted: Mon May 24, 2004 8:19 pm   Post subject: Tetris (again)- giving a value to a 2d array

I have my grid for tetris which looks something like this:

code:

var block : array 0 .. 9, 0 .. 17 of int
var gridy, gridx : int := 30

for count : 0 .. 17 & Array grid.
    for count2 : 0 .. 9
        block (count2, count) := 0
    end for
end for

for counter : 1 .. 18 & Actual grid.
    gridy := gridy + 20
    Draw.Line (30, gridy, 230, gridy, 3)
end for
for counter : 1 .. 10
    gridx := gridx + 20
    Draw.Line (gridx, 30, gridx, 390, 3)
end for
Draw.Box (30, 30, 230, 390, 3)


I've also given all my shapes (the T,Ls,square,Zs and line) values (i.e. block (1,1):=1)

I've been able to have them drawn on my grid using coordinates as follows:

code:

var x,y:int
*y := -1
 x := -1
 for dropy : 1 .. 17
 for count : 31 .. 371 by 20
 y := y + 1
 x := -1
 for count2 : 31 .. 211 by 20
 x := x + 1
 if block (x, y) = 1 then
 Draw.Fill (count2, count, 2, 3)
 end if
 end for
 end for

 end for


- but I find this method inconveniant because I have a more difficult time manipulating the shapes as they fall or get rotated. I've tried using my block array to manipulate the shapes, but it isn't working and I can't figure out why:

code:

var x,y:int
x := 32
y := 32
for count : 0 .. 17
    y := y + (count * 20)
    x := 32
    for count2 : 0 .. 9
        x := x + (count2 * 20)
        if block (count2, count) = 1 then
            Draw.Fill (x, y, 2, 3)
        end if
    end for
end for


So, I suppose the general question is how do I manipulate my shapes?
Sponsor
Sponsor
Sponsor
sponsor
Andy




PostPosted: Tue May 25, 2004 9:38 am   Post subject: (No subject)

i just did hundreds of if statements since i did it the stupid way and used procs to draw the shapes... a really good way to to it is to simply draw them on seperate 2d arrays and just copy them over... better yet use a 3d array of records containing the previous and next block's allocation.
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  [ 2 Posts ]
Jump to:   


Style:  
Search: