saving tetris blocks
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: saving tetris blocks

  1. #1
    Join Date
    Mar 2010
    Posts
    1

    saving tetris blocks

    Hello,

    I'm currently developing a tetris clone and I have a problem saving the blocks.

    I want to save the blocks in a two-dimensional array that represent the game grid (10x20). I simply want to change the values of the array (to the specefic shape type eg, 1,2,3,4... 0 if there is no block) if there is a block in that specific coordinate.

    I'm currently creating blocks like this:
    Code:
       
    /*
    * 00000
    * 01200
    * 00110
    * 00000
    */
    
    g.FillRectangle(System.Drawing.Brushes.Red, startx - width, starty, height, width);
    g.DrawRectangle(System.Drawing.Pens.Black, startx - width, starty, height, width);
    
    g.FillRectangle(System.Drawing.Brushes.Red, startx, starty, height, width);
    g.DrawRectangle(System.Drawing.Pens.Black, startx, starty, height, width);
    
    g.FillRectangle(System.Drawing.Brushes.Red, startx, starty + height, height, width);
    g.DrawRectangle(System.Drawing.Pens.Black, startx, starty + height, height, width);
    
    g.FillRectangle(System.Drawing.Brushes.Red, startx + width, starty + height, height, width);
    g.DrawRectangle(System.Drawing.Pens.Black, startx + width, starty + height, height, width);
    this is for the z block. the 2 is the center of the brick (the starting point / startx,starty). I'm think that I should save the block in an array as shown in the comment above. 2 is for the center brick which is the coordinates i need to build it from. 1 is another block and 0 is no blocks. But I don't know how to save this array in my current game grid array.

    Anyone know how to do this?

    Thanks

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,074

    Re: saving tetris blocks

    Welcome to the forums!

    You are overcomplicating things!

    You would save a lot of code, time and effort if you separate the blocks into their on class.

    I have developed a VB.NET version, if you are interested.

    With my version, I have separated the grid ( which is the black box where all shapes will appear in ), the shapes, the movements etc. of the shapes, and the graphic oriented stuff into separate classes. Much more manageable.

    My 2 cents.

  3. #3
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: saving tetris blocks

    What you shown us is drawing a block. It has nothing to do with how the information about the block (position, shape, color, etc.) is store.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center