Sign in to follow this  

Programming Tetris

This topic is 3865 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am thinking of creating a Tetris game in C++. My question is how would I represent the blocks in the game. I was thinking that I could simply represent the already fallen pieces in an array. Also I can have all the pieces be represented by a base class called Piece and Extended it to the various shapes. But what I am wondering how should I represent the fallen piece? Should I create a new object and delete it as soon as it on top of the other blocks? Just curious on how this is taken care of. Any suggestions?

Share this post


Link to post
Share on other sites
Making a single piece class is easier. A really object oriented design could have separate classes for pieces and shapes, with 6 instances of the shape class to represent the 6 pieces (each instance would contain the data for its shape). I usually just hard code the shapes into the piece class itself and use a number to track which shape it is supposed to be.

Really you don't even need to use classes at all. It's simple enough that you could easily code it without classes (unless you're using a language like Java).

For the fallen peices, just delete the peice and add its blocks to the board. In normal tetris, once peices land it is only the blocks they are made of that matter.

Share this post


Link to post
Share on other sites

This topic is 3865 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this