Answer the question
In order to leave comments, you need to log in
How to use multiple variables in one code?
The thing is, I’m sitting like this writing Tetris, and everything works simply, cubes are called in turn)
But there are 10 such cubes (a certain structure should be obtained) and each code is the same
if (D4.gameObject.name == "D-4 l")
{
if (xD4 < xD4s - 1 || xD4 > xD4s + 1)
{
Console.text = "D4";
GameOver();
}
if (xD4 > xD4s - 1 && xD4 < xD4s + 1 || xD4 == xD4s)
{
StartD5();
}
}
Answer the question
In order to leave comments, you need to log in
I would do so.
1. I would create a class in which I would describe the general game piece. Its coordinates and movement. Would store coordinates in the form of X0, Y0; X1, Y1; X2, Y2; X3, Y3; and pass the type of the figure to the constructor, and use the switch to build the figure.
2. The call to the figure would be done by generating a random number and then compared through enum. enum Figure { green, red, yellow... }
But I didn't quite understand what you mean by cube. That is, one square with the help of which a tetromino is built? If so, then this can obviously be simplified to writing a single class in which to generate a figure. Also, if you are making regular Tetris, with 7 pieces, then instead of a random number, use a bag of pieces , recommendations for it are written on the Tetris Wikipedia.
3. What do you use to store pieces on the playing field? I would make a separate class that uses a normal two-dimensional array to store all the shapes on the field, with methods to remove the filled lines.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question