Пример #1
0
        // Make a copy of the block rotated 90 degrees clockwise.
        public Block RotatedCopy()
        {
            Block result = new Block();
              result.width = height;
              result.height = width;

              for (int y = 0; y < height; y++)
              {
            for (int x = 0; x < width; x++)
            {
              result.shape[result.width - 1 - y, x] = shape[x, y];
            }
              }

              return result;
        }
Пример #2
0
        public static Block[] MakeSet(int type, params string[] shape)
        {
            Block[] result = new Block[4];
              result[0] = new Block(type, shape);

              for (int i = 1; i < 4; i++)
              {
            result[i] = result[i - 1].RotatedCopy();
              }

              return result;
        }
Пример #3
0
 // Draw blocks that haven't dropped yet.
 private void DrawBlock(Block block, int x, int y)
 {
     for (int blockY = 0; blockY < block.Height; blockY++)
       {
     for (int blockX = 0; blockX < block.Width; blockX++)
     {
       if (block[blockX, blockY] != 0)
       {
     DrawCell(block[blockX, blockY], x + blockX, y + blockY);
       }
     }
       }
 }
Пример #4
0
 private void PasteBlock(Block block, int x, int y)
 {
     for (int blockY = 0; blockY < block.Height; blockY++)
       {
     for (int blockX = 0; blockX < block.Width; blockX++)
     {
       if (block[blockX, blockY] != 0)
       {
     field[x + blockX, y + blockY] = block[blockX, blockY];
       }
     }
       }
 }
Пример #5
0
 private bool BlockFits(Block block, int x, int y)
 {
     for (int blockY = 0; blockY < block.Height; blockY++)
       {
     for (int blockX = 0; blockX < block.Width; blockX++)
     {
       if (block[blockX, blockY] != 0 && field[x + blockX, y + blockY] != 0)
       {
     return false;
       }
     }
       }
       return true;
 }