How to Rotate a 2D Array of Integers

前端 未结 7 1965
栀梦
栀梦 2020-12-15 06:36

I am programming a Tetris clone and in my game I store my tetromino blocks as 4x4 arrays of blocks. I now need to be able to rotate the integer positions in the arrays so th

7条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-15 06:59

    int[,] source = { { 1,2,3 }, {4,5,6 }, { 7,8,9} };
    int[,] result = new int[3,3];
    var rows = source.GetLength(0);
    var cols = source.GetLength(1);
    
    for (var r=0; r

提交回复
热议问题