GetMatrix() public method

public GetMatrix ( ) : ushort
return ushort
Ejemplo n.º 1
0
        private void HideCurrentTetris()
        {
            TetrisBlock[,] blocks = m_blocks;
            Tetris tetris = m_tetris;
            ushort matrix = tetris.GetMatrix();
            int    b      = TETRIS_MAX_M * TETRIS_MAX_N - 1;

            for (int i = 0; i < TETRIS_MAX_M; ++i)
            {
                for (int j = 0; j < TETRIS_MAX_N; ++j)
                {
                    int offset = b - (i * TETRIS_MAX_N + j);
                    int row    = i + m_row;
                    int col    = j + m_col;
                    if (row < 0 || row >= TETRIS_MAX_ROWS || col < 0 || col >= TETRIS_MAX_COLUMNS)
                    {
                        continue;
                    }

                    if (((matrix >> offset) & 1) == 1)
                    {
                        blocks[row, col].Fill = null;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void RenderCurrentTetris(int offsetX, int offsetY, Brush fill)
        {
            HideCurrentTetris();
            m_row += offsetX;
            m_col += offsetY;
            TetrisBlock[,] blocks = m_blocks;
            Tetris tetris = m_tetris;
            int    b      = TETRIS_MAX_M * TETRIS_MAX_N - 1;
            ushort matrix = tetris.GetMatrix();

            for (int i = 0; i < TETRIS_MAX_M; ++i)
            {
                for (int j = 0; j < TETRIS_MAX_N; ++j)
                {
                    int row = i + m_row;
                    int col = j + m_col;
                    if (row < 0 || col < 0 || row >= TETRIS_MAX_ROWS || col >= TETRIS_MAX_COLUMNS)
                    {
                        continue;
                    }

                    int offset = b - (i * TETRIS_MAX_N + j);
                    if (((matrix >> offset) & 1) == 1)
                    {
                        blocks[row, col].Fill = (fill != null ? fill : tetris.Fill);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private void DrawNextTetris()
        {
            TetrisBlock[,] nextBlocks = m_nextBlocks;
            Tetris nextTetris = m_nextTetris;

            ReDrawTetris(nextBlocks, nextTetris.GetMatrix(), TETRIS_MAX_M, TETRIS_MAX_N, 0, 0, nextTetris.Fill);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Moves down.
        /// </summary>
        public void MoveDown()
        {
            if (IsRunning)
            {
                Tetris tetris = m_tetris;
                ushort matrix = tetris.GetMatrix();
                if (HitTest(matrix, 1, 0))
                {
                    RenderCurrentTetris(0, 0, Brushes.Teal);
                    TryClearLines();

                    if (DetectGameOver())
                    {
                        OnGameOver();
                    }
                    else
                    {
                        CreateNextTetris();
                    }
                }
                else
                {
                    RenderCurrentTetris(1, 0);
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Rotates
        /// </summary>
        public void Rotate()
        {
            if (IsRunning)
            {
                Tetris tetris = m_tetris;
                ushort matrix = tetris.GetMatrix();
                if (!HitTest(matrix, 0, 0))
                {
                    tetris.MatrixTransform();
                }

                RenderCurrentTetris(0, 0);
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Moves right.
 /// </summary>
 public void MoveRight()
 {
     if (IsRunning)
     {
         Tetris tetris = m_tetris;
         ushort matrix = tetris.GetMatrix();
         if (HitTest(matrix, 0, 1))
         {
             RenderCurrentTetris(0, 0);
         }
         else
         {
             RenderCurrentTetris(0, 1);
         }
     }
 }