How declare an multidimensional array

About Monkey 2 Forums Monkey 2 Programming Help How declare an multidimensional array

This topic contains 5 replies, has 4 voices, and was last updated by  zuibaf 1 year ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
  • #13261


    I am creating an game Tetris,
    there will be an multidimensional array for each piece,
    each an multidimensional array is store inside of an unidimensional
    For example, I want to store three pieces ‘L’, ‘T’ e ‘I’ this way:
    The piece ‘L’
    The piece ‘T’
    The piece ‘I’
    In C#, this is easy:

    In monkey2, on the documentation, there is nothing similar, I try this way:

    I know what for unidimensional arrays, this is possible:
    Local objPiece: Int[] = New Int[6](1, 2, 3, 4, 5, 6)

    In the documentation, there is nothing described, perhaps not yet supported. If really, it is not supported will be that in a next version we will have something similar to C#.

    In my case, my intention is to avoid the other way described below, as it is not so readable to someone reading the code, that the multidimensional array demonstrates a piece of a tetris game.



    I enter the values ​​in an string variable, this way it becomes more visibile what pieces were set in the game.



    I think something like this should work.



    you can create a multidimensional array like this:


    ignore line 1

    actually not exactly a two dimensional array but an array of should serve your purpose as it’s what you ask for.


    Mark Sibly

    Multi-dimensional arrays aren’t too well supported yet, in particular there’s no way to intiailize them with values at creation time yet.

    Creating them is easy enough, eg: Local myArray:=New Int[10,20], but you’ll have to get a bit tricky to initialize them, maybe something like:

    (totally untested). Of course, string are also a cool way to do this…

    Peronsally, I’d recommend creating a ‘Piece’ class or similar just to make all the arrays easier to deal with (although you seem to be quite comfortable with arrays!) as you’re also gonna wanna ‘Rotate’ them etc. Then you can just have a 1d array of pieces for the game, and give each piece a rotate method, maybe a clone method too for creating new pieces from template pieces etc. Just off the top of my head – I’ve never actually written a tetris game!



    I am creating the game, it is working, but I still have not finished
    This is my game first.
    All that remains is display of the next piece, punctuation, and phase.
    The hard part has already been made.
    The comment is an portuguese.
    Sorry for English, but my native language is Portuguese from Brazil.

    1. Tetris.monkey2
Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.