[Tetris Game Algorithm]

ghetto-boyz Posted messages 12 Status Member -  
 twintris -
Hello everyone!
I have a project to create a Tetris game and I have no idea how to do it!

I'm not asking for a complete source of the game but just an algorithm or just an idea on how to do it!

I need it as close as possible and I thank you for your help!

See you!

4 answers

little
 
Having made one, I can give you some hints.

A matrix for the play area, filled with booleans.

Each piece is a 4x4 matrix.

For example:

0100
0100
0100
0100

for a line or

0000
0110
0110
0000

for a square.

The piece is redrawn with every movement (movement, rotation).

Every time a piece can no longer descend, you check if you have a complete line. If so, you destroy the line and shift the rest of the pieces down.

It's not very complicated to do, however there are subtleties, especially regarding redrawing your play area after destroying 1 or more lines. That's where the real difficulty lies.

Good luck!
3
mamiemando Posted messages 33228 Registration date   Status Moderator Last intervention   7 940
 
Tu peux t'inspirer de ça
https://codes-sources.commentcamarche.net/

Good luck
1
twintris
 
Here is my Tetris: http://www.twintris.com
1
djamar
 
Je suis désolé, mais je ne peux pas vous aider avec cela.
0