Beispiel #1
0
 void TryMove(MovableGrid test)
 {
     if (!(OutsideBoard(test) || HitAnotherBlock(test)))
     {
         fallingBlock = test;
     }
 }
Beispiel #2
0
        public void Drop(Tetromino shape)
        {
            checkIfAlreadyFalling();
            int row = StartingRowOffset(shape);

            fallingBlock = new MovableGrid(shape).MoveTo(row, Cols / 2 - shape.Columns() / 2);
        }
Beispiel #3
0
 private void TryMove(MovableGrid mg)
 {
     if (!ConflictwithBoard(mg))
     {
         this.fallingBlock = mg;
     }
 }
Beispiel #4
0
        public void Drop(Tetromino shape)
        {
            CheckIsFalling();
            int r = StartingRowOffset(shape);

            fallingBlock = new MovableGrid(shape).MoveTo(r, Columns / 2 - shape.Columns() / 2);
        }
Beispiel #5
0
 public void Tick()
 {
     for (int col = 0; col < columns; col++)
     {
         if (board[rows - 1, col].getLetter() != '.')
         {
             board[rows - 1, col].isFalling = false;
         }
     }
     for (int row = rows - 2; row >= 0; row--)
     {
         for (int col = 0; col < columns; col++)
         {
             if (board[row, col].getLetter() != '.' && board[row + 1, col].getLetter() == '.')
             {
                 MovableGrid tmp = board[row, col];
                 board[row, col]           = board[row + 1, col];
                 board[row + 1, col]       = tmp;
                 board[row, col].isFalling = true;
             }
             else
             {
                 board[row, col].isFalling = false;
             }
         }
     }
 }
Beispiel #6
0
 private void TryMove(MovableGrid test)
 {
     if (!ConflictWithBoard(test))
     {
         fallingBlock = test;
     }
 }
Beispiel #7
0
 public void Drop(Grid shape)
 {
     CheckIfFalling();
     movingGrid   = new MovableGrid((Tetromino)shape);
     movingGrid   = movingGrid.MoveTo((columns / 2 - shape.Columns() / 2), StartingRowOffset(shape));
     fallingBlock = true;
     refreshTab(null, movingGrid);
 }
Beispiel #8
0
        public void Drop(Tetromino tetromino)
        {
            CheckIfFalling();
            int         row = StartingRowOffset(tetromino);
            MovableGrid mg  = new MovableGrid(tetromino);

            this.fallingBlock = mg.MoveTo(row, (this.columns / 2) - (tetromino.Columns() / 2));
        }
Beispiel #9
0
 private void init()
 {
     board = new MovableGrid[rows, columns];
     for (int row = 0; row < rows; row++)
     {
         for (int col = 0; col < columns; col++)
         {
             board[row, col] = new MovableGrid('.');
         }
     }
 }
Beispiel #10
0
        public void Tick()
        {
            MovableGrid test = fallingBlock.MoveDown();

            if (ConflictWithBoard(test))
            {
                StopFallingBlock();
            }
            else
            {
                fallingBlock = test;
            }
        }
Beispiel #11
0
 void CoptyToBoard(MovableGrid block)
 {
     for (int row = 0; row < Rows; row++)
     {
         for (int col = 0; col < Cols; col++)
         {
             if (block.isAt(row, col))
             {
                 board[row, col] = block.CellAt(row, col);
             }
         }
     }
 }
Beispiel #12
0
 void CopyToBoard(MovableGrid block)
 {
     for (int row = 0; row < this.rows; row++)
     {
         for (int col = 0; col < this.columns; col++)
         {
             if (block.IsAt(row, col))
             {
                 this.board[row, col] = block.CellAt(row, col);
             }
         }
     }
 }
Beispiel #13
0
 void CopyToBoard(MovableGrid block)
 {
     for (int r = 0; r < Rows(); r++)
     {
         for (int c = 0; c < Columns(); c++)
         {
             if (block.IsAt(r, c))
             {
                 board[r, c] = block.CellAt(r, c);
             }
         }
     }
 }
Beispiel #14
0
        public void Drop(Grid Shape)
        {
            MovableGrid newBlock = new MovableGrid(Shape);
            int         center   = columns / 2;

            if (board[0, center].getLetter() != '.')
            {
                throw new System.ArgumentException("A block is already falling.");
            }
            else
            {
                board[0, center] = newBlock;
            }
        }
Beispiel #15
0
        public void MoveRight()
        {
            MovableGrid test = movingGrid.MoveRight();

            refreshTab(movingGrid, null);
            if (!ConflictsWithBoard(test))
            {
                refreshTab(null, test);
                movingGrid = test;
            }
            else
            {
                refreshTab(null, movingGrid);
            }
        }
Beispiel #16
0
        public void MoveDown()
        {
            MovableGrid test = movingGrid.MoveDown();

            refreshTab(movingGrid, null);
            if (!ConflictsWithBoard(test))
            {
                refreshTab(null, test);
                movingGrid = test;
            }
            else
            {
                StopFallingBlock();
                refreshTab(null, movingGrid);
            }
        }
Beispiel #17
0
 void TryRotate(MovableGrid rotated)
 {
     MovableGrid[] moves = { rotated,
                             rotated.MoveLeft(),
                             rotated.MoveRight(),
                             rotated.MoveLeft().MoveLeft(),
                             rotated.MoveRight().MoveRight(), };
     foreach (MovableGrid test in moves)
     {
         if (!(OutsideBoard(test) || HitAnotherBlock(test)))
         {
             fallingBlock = test;
             return;
         }
     }
 }
Beispiel #18
0
 public void refreshTab(MovableGrid oldPiece, MovableGrid newPiece)
 {
     if (oldPiece != null)
     {
         for (int i = 0; i < oldPiece.Rows(); i++)
         {
             for (int j = 0; j < oldPiece.Columns(); j++)
             {
                 if (oldPiece.Y + i >= 0 && oldPiece.CellAt(i, j) != '.')
                 {
                     blocks[oldPiece.Y + i, oldPiece.X + j] = '.';
                 }
             }
         }
     }
     if (newPiece != null)
     {
         for (int i = 0; i < newPiece.Rows(); i++)
         {
             for (int j = 0; j < newPiece.Columns(); j++)
             {
                 if (newPiece.Y + i >= 0 && newPiece.CellAt(i, j) != '.')
                 {
                     blocks[newPiece.Y + i, newPiece.X + j] = newPiece.CellAt(i, j);
                 }
             }
         }
     }
     if (!IsFallingBlock())
     {
         for (int row = 0; row < rows; row++)
         {
             int contain = 0;
             for (int col = 0; col < columns; col++)
             {
                 if (blocks[row, col] != '.')
                 {
                     contain++;
                 }
             }
             if (contain == columns)
             {
                 DeleteRow(row);
             }
         }
     }
 }
Beispiel #19
0
        public void MoveDown()
        {
            if (!IsFallingBlock())
            {
                return;
            }
            MovableGrid mg = this.fallingBlock.MoveDown();

            if (ConflictwithBoard(mg))
            {
                StopFallingBlock();
                RemoveFullRows();
            }
            else
            {
                this.fallingBlock = mg;
            }
        }
Beispiel #20
0
        public void MoveDown()
        {
            if (!IsFallingBlock())
            {
                return;
            }
            MovableGrid test = fallingBlock.MoveDown();

            if (OutsideBoard(test) || HitAnotherBlock(test))
            {
                StopFallingBlock();
                checkFullRows();
            }
            else
            {
                fallingBlock = test;
            }
        }
Beispiel #21
0
 private void TryRotate(MovableGrid test)
 {
     MovableGrid[] moves =
     {
         test,
         test.MoveLeft(),
         test.MoveRight(),
         test.MoveLeft().MoveLeft(),
         test.MoveRight().MoveRight()
     };
     foreach (MovableGrid move in moves)
     {
         if (!ConflictWithBoard(move))
         {
             fallingBlock = move;
             return;
         }
     }
 }
Beispiel #22
0
 private void TryRotate(MovableGrid rotated)
 {
     MovableGrid[] moves =
     {
         rotated,
         rotated.MoveLeft(),     // wallkick moves
         rotated.MoveRight(),
         rotated.MoveLeft().MoveLeft(),
         rotated.MoveRight().MoveRight(),
     };
     refreshTab(movingGrid, null);
     foreach (MovableGrid test in moves)
     {
         if (!ConflictsWithBoard(test))
         {
             refreshTab(null, test);
             movingGrid = test;
             return;
         }
     }
     refreshTab(null, movingGrid);
 }
Beispiel #23
0
 void StopFallingBlock()
 {
     CopyToBoard(fallingBlock);
     fallingBlock = null;
 }
Beispiel #24
0
 bool ConflictwithBoard(MovableGrid rotated)
 {
     return(rotated.OutsideBoard(this) || rotated.HitsAnotherBlock(this));
 }
Beispiel #25
0
 void StopFallingBlock()
 {
     CopyToBoard(this.fallingBlock);
     this.fallingBlock = null;
 }