Exemplo n.º 1
0
        public bool IsValidMove(Move move)
        {
            var tempMove = ActiveBlock.Clone();

            tempMove.Move(move);

            return(!CheckBlock(tempMove));
        }
Exemplo n.º 2
0
        public bool Move(Move move)
        {
            // move must be set
            if (move == Engine.Move.None)
            {
                return(true);
            }

            // must have active block
            if (ActiveBlock == null)
            {
                return(false);
            }

            // implement fall
            if (move == Engine.Move.Fall)
            {
                var collisionHeight = int.MaxValue;
                foreach (var coord in ActiveBlock.GetCoords())
                {
                    var steps = 0;
                    for (var y = coord.Row - 1; y >= 0; y--)
                    {
                        if (GameBoard[y][coord.Column] == false)
                        {
                            steps++;
                        }
                        else
                        {
                            break;
                        }
                    }

                    collisionHeight = Math.Min(steps, collisionHeight);
                }
                ActiveBlock.Position.Row -= collisionHeight;

                EventHandler?.OnMove(ActiveBlock, move);

                LockBlock();
                CheckBoard();
                IsSoftDrop = false;
                return(true);
            }

            var tempMove  = ActiveBlock.Clone().Move(move);
            var validMove = CheckBlock(tempMove);

            // try to solve rotation offset
            if (validMove == false && (move == Engine.Move.RotateLeft || move == Engine.Move.RotateRight))
            {
                var solved = _TrySolveRotation(ref tempMove);
                if (solved != null)
                {
                    tempMove  = solved;
                    validMove = true;
                }
            }

            // if un valid move down lock block
            if (validMove == false && move == Engine.Move.Down)
            {
                LockBlock();
                CheckBoard();
                IsSoftDrop = false;
                return(true);
            }

            // move is un valid
            if (validMove == false)
            {
                EventHandler?.OnUnvalidMove(move);
                return(false);
            }

            // apply move
            ActiveBlock = tempMove;
            IsSoftDrop  = _IsSoftDrop(ActiveBlock);

            EventHandler?.OnMove(ActiveBlock, move);
            return(true);
        }