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 9 months, 2 weeks ago.

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

    zuibaf
    Participant

    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’
    [1][0]
    [1][0]
    [1][1]
    The piece ‘T’
    [1][1][1]
    [0][1][0]
    [0][1][0]
    The piece ‘I’
    [1][1][1]
    [0][1][0]
    [1][1][1]
    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.

    #13263

    zuibaf
    Participant

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

    #13286

    Whiteball
    Participant

    I think something like this should work.

    #13295

    Jesse
    Participant

    you can create a multidimensional array like this:

    [/crayon]

    ignore line 1

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

    #13304

    Mark Sibly
    Keymaster

    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!

    #13418

    zuibaf
    Participant

    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.

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

You must be logged in to reply to this topic.