protected void DrawPiece( DrawingContext drawingContext, int x, int y, TetrisPieceColor tetrisPieceColor )
        {
            if ( m_nPieceSize <= 0 )
            return;

             int nX = x * m_nPieceSize;
             int nY = ((m_Board.GetHeight()-1) * m_nPieceSize) - y * m_nPieceSize;
             Brush b;
             switch(tetrisPieceColor)
             {
            default:
            case TetrisPieceColor.Red:
               b = Brushes.Red;
               break;
            case TetrisPieceColor.Yellow:
               b = Brushes.Yellow;
               break;
            case TetrisPieceColor.Purple:
               b = Brushes.Purple;
               break;
            case TetrisPieceColor.LtGray:
               b = Brushes.LightGray;
               break;
            case TetrisPieceColor.LtBlue:
               b = Brushes.LightBlue;
               break;
            case TetrisPieceColor.Green:
               b = Brushes.Green;
               break;
            case TetrisPieceColor.Blue:
               b = Brushes.Blue;
               break;
             }
             drawingContext.DrawRectangle( b, new Pen( Brushes.Black, 1d ), new Rect( nX, nY, m_nPieceSize, m_nPieceSize ) );
        }
示例#2
0
        public void SetPieceAt(int nX, int nY, TetrisPieceColor eColor)
        {
            if (nX < 0 || nX >= m_nWidth || nY < 0 || nY >= m_nHeight)
            {
                return;
            }

            m_Board[nX, nY] = eColor;
        }
示例#3
0
        public TetrisPieceColor GetBoardPieceAt(int nX, int nY)
        {
            if (nX < 0 || nX >= m_nWidth || nY < 0 || nY >= m_nHeight)
            {
                return(TetrisPieceColor.NoPiece);
            }

            TetrisPieceColor eColor = m_Board[nX, nY];

            return(eColor);
        }
示例#4
0
        public TetrisPieceColor GetPieceAt(int nX, int nY)
        {
            TetrisPieceColor eColor = GetBoardPieceAt(nX, nY);

            if (eColor == TetrisPieceColor.NoPiece && m_Piece != null)
            {
                if (m_Piece.HasPieceAt(nX, nY))
                {
                    eColor = m_Piece.GetPieceColor();
                }
            }
            return(eColor);
        }
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);

            drawingContext.DrawRectangle(Brushes.Black, new Pen(), new Rect(0d, 0d, m_Board.GetWidth() * m_nPieceSize, m_Board.GetHeight() * m_nPieceSize));
            for (int x = 0; x < m_Board.GetWidth(); x++)
            {
                for (int y = 0; y < m_Board.GetHeight(); y++)
                {
                    TetrisPieceColor eColor = m_Board.GetPieceAt(x, y);
                    if (eColor != TetrisPieceColor.NoPiece)
                    {
                        DrawPiece(drawingContext, x, y, eColor);
                    }
                }
            }
        }
        protected void DrawPiece(DrawingContext drawingContext, int x, int y, TetrisPieceColor tetrisPieceColor)
        {
            if (m_nPieceSize <= 0)
            {
                return;
            }

            int   nX = x * m_nPieceSize;
            int   nY = ((m_Board.GetHeight() - 1) * m_nPieceSize) - y * m_nPieceSize;
            Brush b;

            switch (tetrisPieceColor)
            {
            default:
            case TetrisPieceColor.Red:
                b = Brushes.Red;
                break;

            case TetrisPieceColor.Yellow:
                b = Brushes.Yellow;
                break;

            case TetrisPieceColor.Purple:
                b = Brushes.Purple;
                break;

            case TetrisPieceColor.LtGray:
                b = Brushes.LightGray;
                break;

            case TetrisPieceColor.LtBlue:
                b = Brushes.LightBlue;
                break;

            case TetrisPieceColor.Green:
                b = Brushes.Green;
                break;

            case TetrisPieceColor.Blue:
                b = Brushes.Blue;
                break;
            }
            drawingContext.DrawRectangle(b, new Pen(Brushes.Black, 1d), new Rect(nX, nY, m_nPieceSize, m_nPieceSize));
        }
示例#7
0
        public void Step()
        {
            if (m_Piece == null)
            {
                Random           r      = new Random();
                TetrisPieceColor eColor = ( TetrisPieceColor)r.Next((int)TetrisPieceColor.Red, (int)TetrisPieceColor.Blue);
                m_Piece = new TetrisPiece(this, eColor);
            }
            else
            {
                if (!m_Piece.Step())
                {
                    //Add to board
                    m_Piece.ApplyYourSelfToBoard();
                    m_Piece = null;

                    //Check Rows to see if can clear anything
                    DoClearRowCheck();
                }
            }
        }
示例#8
0
 public TetrisPiece(TetrisBoard board, TetrisPieceColor eColor)
 {
     m_Board  = board;
     m_eColor = eColor;
     m_nX     = board.GetWidth() / 2;
     m_nY     = board.GetHeight();
     //m_eFlip = TetrisPieceFlip.Normal;
     m_PieceBoard = new bool[4, 4];
     for (int x = 0; x < 4; x++)
     {
         for (int y = 0; y < 4; y++)
         {
             m_PieceBoard[x, y] = false;
         }
     }
     if (m_eColor == TetrisPieceColor.Red)
     {
         m_PieceBoard[0, 0] = true;
         m_PieceBoard[1, 0] = true;
         m_PieceBoard[2, 0] = true;
         m_PieceBoard[3, 0] = true;
     }
     else if (m_eColor == TetrisPieceColor.Yellow)
     {
         m_PieceBoard[0, 0] = true;
         m_PieceBoard[1, 0] = true;
         m_PieceBoard[2, 0] = true;
         m_PieceBoard[2, 1] = true;
     }
     else if (m_eColor == TetrisPieceColor.Purple)
     {
         m_PieceBoard[1, 1] = true;
         m_PieceBoard[1, 0] = true;
         m_PieceBoard[2, 0] = true;
         m_PieceBoard[3, 0] = true;
     }
     else if (m_eColor == TetrisPieceColor.LtGray)
     {
         m_PieceBoard[1, 0] = true;
         m_PieceBoard[1, 1] = true;
         m_PieceBoard[2, 0] = true;
         m_PieceBoard[3, 0] = true;
     }
     else if (m_eColor == TetrisPieceColor.LtBlue)
     {
         m_PieceBoard[0, 0] = true;
         m_PieceBoard[0, 1] = true;
         m_PieceBoard[1, 0] = true;
         m_PieceBoard[1, 1] = true;
     }
     else if (m_eColor == TetrisPieceColor.Green)
     {
         m_PieceBoard[3, 0] = true;
         m_PieceBoard[2, 0] = true;
         m_PieceBoard[2, 1] = true;
         m_PieceBoard[1, 1] = true;
     }
     else
     {
         m_PieceBoard[0, 0] = true;
         m_PieceBoard[1, 0] = true;
         m_PieceBoard[1, 1] = true;
         m_PieceBoard[2, 1] = true;
     }
 }
        public void SetPieceAt( int nX, int nY, TetrisPieceColor eColor )
        {
            if ( nX < 0 || nX >= m_nWidth || nY < 0 || nY >= m_nHeight )
            return;

             m_Board[nX, nY] = eColor;
        }
 public TetrisPiece( TetrisBoard board, TetrisPieceColor eColor )
 {
     m_Board = board;
      m_eColor = eColor;
      m_nX = board.GetWidth() / 2;
      m_nY = board.GetHeight();
      //m_eFlip = TetrisPieceFlip.Normal;
      m_PieceBoard = new bool[4, 4];
      for(int x=0; x<4; x++ )
      {
     for(int y=0; y<4; y++ )
     {
        m_PieceBoard[x, y] = false;
     }
      }
      if ( m_eColor == TetrisPieceColor.Red )
      {
     m_PieceBoard[0, 0] = true;
     m_PieceBoard[1, 0] = true;
     m_PieceBoard[2, 0] = true;
     m_PieceBoard[3, 0] = true;
      }
      else if( m_eColor == TetrisPieceColor.Yellow )
      {
     m_PieceBoard[0, 0] = true;
     m_PieceBoard[1, 0] = true;
     m_PieceBoard[2, 0] = true;
     m_PieceBoard[2, 1] = true;
      }
      else if ( m_eColor == TetrisPieceColor.Purple )
      {
     m_PieceBoard[1, 1] = true;
     m_PieceBoard[1, 0] = true;
     m_PieceBoard[2, 0] = true;
     m_PieceBoard[3, 0] = true;
      }
      else if ( m_eColor == TetrisPieceColor.LtGray )
      {
     m_PieceBoard[1, 0] = true;
     m_PieceBoard[1, 1] = true;
     m_PieceBoard[2, 0] = true;
     m_PieceBoard[3, 0] = true;
      }
      else if ( m_eColor == TetrisPieceColor.LtBlue )
      {
     m_PieceBoard[0, 0] = true;
     m_PieceBoard[0, 1] = true;
     m_PieceBoard[1, 0] = true;
     m_PieceBoard[1, 1] = true;
      }
      else if( m_eColor == TetrisPieceColor.Green )
      {
     m_PieceBoard[3, 0] = true;
     m_PieceBoard[2, 0] = true;
     m_PieceBoard[2, 1] = true;
     m_PieceBoard[1, 1] = true;
      }
      else
      {
     m_PieceBoard[0, 0] = true;
     m_PieceBoard[1, 0] = true;
     m_PieceBoard[1, 1] = true;
     m_PieceBoard[2, 1] = true;
      }
 }