Exemplo n.º 1
0
        public bool CanMoveLeft()
        {
            //get the min col of the tetromino
            int minCol = CoveredCells.Min(_ => _.Column);

            //If any of the covered spaces are currently in the left border, the piece cannot move left.
            if (minCol == 0)
            {
                return(false);
            }
            //get all the leftest tetromino's cells
            var leftestCells = CoveredCells.Where(_ => _.Column == minCol);

            //For each of the covered spaces, get the space immediately below
            foreach (var leftestCell in leftestCells)
            {
                if (_GameBoard.GetRow(leftestCell.Row).HasCellTaken(leftestCell.Column - 1))
                {
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 2
0
        public bool CanMoveRight()
        {
            //get the max col of the tetromino
            int maxCol = CoveredCells.Max(_ => _.Column);

            Console.WriteLine("CanMoveRight - maxCol=" + maxCol);
            //If any of the covered spaces are currently in the right border, the piece cannot move right.
            if (maxCol == _GameBoard.Cols - 1)
            {
                return(false);
            }
            //get all the righest tetromino's cells
            var righestCells = CoveredCells.Where(_ => _.Column == maxCol);

            //For each of the covered spaces, get the space immediately below
            foreach (var rightestCell in righestCells)
            {
                if (_GameBoard.GetRow(rightestCell.Row).HasCellTaken(rightestCell.Column + 1))
                {
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Check whether the tetromino can move down by 1 cell or not
        /// </summary>
        /// <returns>true if it can move, false otherwise</returns>
        public bool CanMoveDown()
        {
            //get the min row of the tetromino
            int minRow = CoveredCells.Min(_ => _.Row);

            //If any of the covered spaces are currently in the lowest row, the piece cannot move down.
            Console.WriteLine("CanMoveDown - minRow=" + minRow);
            if (minRow == 0)
            {
                return(false);
            }
            //get all the lowest tetromino's cells
            var lowestCells = CoveredCells.Where(_ => _.Row == minRow);

            //For each of the covered spaces, get the space immediately below
            foreach (var lowestCell in lowestCells)
            {
                if (_GameBoard.GetRow(lowestCell.Row - 1).HasCellTaken(lowestCell.Column))
                {
                    return(false);
                }
            }
            return(true);
        }