コード例 #1
0
 private void DrawTetramino(Tetromino t, Color color, int bs = blockSize, int x = 0, int y = 0)
 {
     for (int i = 0; i < t.NumRows; i++)
     {
         for (int j = 0; j < t.NumColumns; j++)
         {
             if (!t.Block(i, j))
             {
                 continue;
             }
             int xx     = x + j * bs;
             int yy     = y + i * bs;
             int width  = bs - 1;
             int height = bs - 1;
             spriteBatch.Draw(whiteRectangle,
                              new Rectangle(xx, yy, width, height), color);
         }
     }
 }
コード例 #2
0
 public bool DoesTetrominoFit(Tetromino t)
 {
     for (int i = 0; i < t.NumRows; i++)
     {
         for (int j = 0; j < t.NumColumns; j++)
         {
             if (!t.Block(i, j))
             {
                 continue;
             }
             int xx = t.PositionX + i - t.NumRows / 2;
             int yy = t.PositionY + j - t.NumColumns / 2;
             if (xx < 0 || xx >= NumRows || yy < 0 || yy >= NumColumns || Block[xx][yy])
             {
                 return(false);
             }
         }
     }
     return(true);
 }
コード例 #3
0
        public void Add(Tetromino t)
        {
            if (!DoesTetrominoFit(t))
            {
                throw new System.InvalidOperationException("Tetromino does not fit.");
            }

            for (int i = 0; i < t.NumRows; i++)
            {
                for (int j = 0; j < t.NumColumns; j++)
                {
                    if (t.Block(i, j))
                    {
                        int xx = t.PositionX + i - t.NumRows / 2;
                        int yy = t.PositionY + j - t.NumColumns / 2;
                        Block[xx][yy] = true;
                        Color[xx][yy] = t.Color;
                        count[xx]++;
                    }
                }
            }
        }