Sora
Sora

Reputation: 87

Tetris piece construction using C# array

I've looked for a question like the one I'm about to ask, but haven't found what I'm looking for. Question: How can I implement tetris pieces with C# arrays?

I have only a basic understanding of arrays, I have the concept of initialization, but past that I'm a little lost on how to actually construct it. For example:

public static (type)[,] Matrix = new (type)[x,y];

I would guess that the thing I'm missing is how to assign the values of the pieces. Past the initialization, I know I can change the x and y values(in this case) but how do I put the individual blocks into those pseudo coordinates? Any help would be appreciated.

Upvotes: 0

Views: 524

Answers (1)

Mathias R. Jessen
Mathias R. Jessen

Reputation: 174690

Multi-dimensional arrays support initializers just fine:

int[,] Matrix = new int[3,3]{ { 0, 0, 1 },
                              { 0, 0, 1 },
                              { 0, 1, 1 } };

Upvotes: 1

Related Questions