Beispiel #1
0
        /// <summary>
        /// Moves the tetromino down.
        /// </summary>
        /// <remarks>
        /// This method is used by a thread. It needs its own copy of the reference to the
        /// tetromino, because the only time this thread stops is when the
        /// tetromino cant move any further. If the tetromino is dropped all
        /// the way at once (space bar), it will generate a new active tetromino.
        /// This will get its own thread, and now two threads are working on the
        /// same tetromino.
        /// </remarks>
        private void MoveTetrominoDown()
        {
            Tetromino tet = ActiveTetromino;

            Thread.Sleep((int)(500 * Math.Pow(0.75, Level - 1)));
            MovingTetrominoMutex.WaitOne();
            while (tet != null && !Fieldgrid.IsCollisionBelow(tet))
            {
                tet.MoveDownIfPossible(Fieldgrid);
                MovingTetrominoMutex.ReleaseMutex();
                GameController.RefreshUserInterface();
                Thread.Sleep((int)(500 * Math.Pow(0.75, Level - 1)));
                MovingTetrominoMutex.WaitOne();
            }
            if (tet != null && !tet.IsLockedInPlace)
            {
                Fieldgrid.PlaceOnGrid(tet);
            }
            MovingTetrominoMutex.ReleaseMutex();
            GameController.RefreshUserInterface();
        }