Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Tetris (again)- giving a value to a 2d array
Author Message
Neja

Posted: 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?

Andy

Posted: 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: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 2 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: