Esempio n. 1
0
        public TetrisShapeDataOnly projectMove(TetrisShape.TetrisMoves tm)
        {
            List <TetrisData> returnval = this.CloneData();

            TetrisShape.movePiece(returnval, tm);
            TetrisShapeDataOnly tsdo = new TetrisShapeDataOnly();

            tsdo.points = returnval;
            return(tsdo);
        }
Esempio n. 2
0
 public void moveActivePiece(TetrisShape.TetrisMoves tm)
 {
     moveActivePiece(tm, true);
 }
Esempio n. 3
0
        public void moveActivePiece(TetrisShape.TetrisMoves tm, bool resetTimer)
        {
            if (_activeShape == null || _activeShape.Activated == false || _gameTimer.Enabled == false)
            {
                return;
            }

            // Up is a special command, we want to drop down to the bottom.
            int  howFarToDrop = 1;
            bool dropToBottom = (tm == TetrisShape.TetrisMoves.UP);

            if (dropToBottom)
            {
                tm = TetrisShape.TetrisMoves.DOWN;
            }

            if (resetTimer && tm == TetrisShape.TetrisMoves.DOWN)
            {
                _gameTimer.Enabled = false;
            }

            bool canMove           = true;
            TetrisShapeDataOnly ts = _activeShape.projectMove(tm);;

            canMove = isInValidPosition(ts);

            // Two special cases to check for.
            if (canMove == false && (tm == TetrisShape.TetrisMoves.ROTATELEFT || tm == TetrisShape.TetrisMoves.ROTATERIGHT))
            {
                // lets see if sliding the piece left or right would let us move.. If it does, then lets do it.
                // this will allow us to rotate when we are up against the wall, or trying to rotate into a tight spot.
                TetrisShapeDataOnly tsLeft = ts.projectMove(TetrisShape.TetrisMoves.LEFT);//.projectMove(TetrisShape.TetrisMoves.LEFT);
                if (isInValidPosition(tsLeft))
                {
                    // lets apply this left move right here.
                    _activeShape.movePiece(TetrisShape.TetrisMoves.LEFT);
                    canMove = true;
                }
                else
                {
                    TetrisShapeDataOnly tsRight = ts.projectMove(TetrisShape.TetrisMoves.RIGHT);
                    if (isInValidPosition(tsRight))
                    {
                        // lets apply this right move right here.
                        _activeShape.movePiece(TetrisShape.TetrisMoves.RIGHT);
                        canMove = true;
                    }
                }
            }


            if (canMove == false)
            {
                // find out if it collided while moving down
                if (tm == TetrisShape.TetrisMoves.DOWN)
                {
                    // if it i then move it into the local piece collection
                    this.Add(_activeShape);
                    // find any full rows and destory them.
                    int rowsCleared = this.ClearFullRows();

                    if (rowsCleared > 0)
                    {
                        // Update our score and Level
                        this._linesClearedThisLevel += rowsCleared;
                        this._linesCleared          += rowsCleared;
                        this._score += Convert.ToInt32((rowsCleared * rowsCleared) * (10 - (_gameTimer.Interval / 100)));

                        if (this._linesClearedThisLevel >= 10 + this._level)
                        {
                            LevelChange();
                        }
                        this.RaiseScoreChangedEvent();
                    }
                    // and start a new active piece.
                    loadActiveShapeFromQueue();
                    updateShape(_activeShape, TimeSpan.FromMilliseconds(this._gameTimer.Interval));
                }
            }

            if (canMove && dropToBottom == false)
            {
                _activeShape.movePiece(tm);
                updateShape(_activeShape, TimeSpan.FromMilliseconds(100));
            }
            else if (canMove && dropToBottom == true)// if we are droping to bottom, find out how far we have to go to do that.
            {
                // we wanna go until we cant move.

                while (canMove == true)
                {
                    ts = ts.projectMove(tm); // keep projecting down.

                    canMove = isInValidPosition(ts);

                    howFarToDrop++;
                }
                _activeShape.movePiece(TetrisShape.TetrisMoves.DOWN, --howFarToDrop);
                updateShape(_activeShape, TimeSpan.FromMilliseconds(100));
            }
            if (resetTimer && tm == TetrisShape.TetrisMoves.DOWN && this.GameOver == false)
            {
                _gameTimer.Enabled = !_gameTimer.Enabled;
            }
        }