private void ReDrawTetris(TetrisBlock[,] blocks, ushort matrix, int m, int n, int offsetX, int offsetY, Brush fill) { int b = TETRIS_MAX_M * TETRIS_MAX_N - 1; for (int i = 0; i < m; ++i) { for (int j = 0; j < n; ++j) { int offset = b - (i * TETRIS_MAX_N + j); int row = i + offsetX; int col = j + offsetY; if (row < 0 || row >= TETRIS_MAX_ROWS || col < 0 || col >= TETRIS_MAX_COLUMNS) { continue; } blocks[row, col].Fill = (((matrix >> offset) & 1) == 1) ? fill : null; } } }
private TetrisBlock CreateBlock() { TetrisBlock block = new TetrisBlock(); block.Width = TETRIS_BLOCK_WIDTH; block.Height = TETRIS_BLOCK_HEIGHT; return block; }
private void Initialize(Panel tetrisPanel, Panel nextTetrisPanel) { TetrisBlock[,] blocks = new TetrisBlock[TETRIS_MAX_ROWS, TETRIS_MAX_COLUMNS]; for (int i = 0; i < TETRIS_MAX_ROWS; ++i) { for (int j = 0; j < TETRIS_MAX_COLUMNS; ++j) { TetrisBlock block = blocks[i, j] = CreateBlock(); block.Top = i * TETRIS_BLOCK_HEIGHT; block.Left = j * TETRIS_BLOCK_WIDTH; tetrisPanel.Children.Add(block); block.Fill = null; } } TetrisBlock[,] nextBlocks = new TetrisBlock[TETRIS_MAX_M, TETRIS_MAX_N]; for (int i = 0; i < TETRIS_MAX_M; ++i) { for (int j = 0; j < TETRIS_MAX_N; ++j) { TetrisBlock nextBlock = nextBlocks[i, j] = CreateBlock(); nextBlock.Top = i * TETRIS_BLOCK_HEIGHT; nextBlock.Left = j * TETRIS_BLOCK_WIDTH; nextTetrisPanel.Children.Add(nextBlock); } } m_blocks = blocks; m_nextBlocks = nextBlocks; }
private void ClearBlocks(TetrisBlock[,] blocks, int m, int n) { for (int i = 0; i < m; ++i) { for (int j = 0; j < n; ++j) { blocks[i, j].Fill = null; } } }