Exemplo n.º 1
0
        public void Update(IInput input)
        {
            bool   autoBottomShift = false;
            double timeFromDown    = (DateTime.Now - time).TotalMilliseconds;

            if (timeFromDown >= AUTO_BOTTOM_SHIFT_MILLISECONDS)
            {
                autoBottomShift = true;
                time            = DateTime.Now;
            }

            if (input.leftRotation)
            {
                Tetrimino copy = TetriminoGenerator.Copy(currentTetrimino);
                copy.RotateLeft();
                if (cells.IsReflection(copy))
                {
                    currentTetrimino = copy;
                }
            }
            if (input.rightRotation)
            {
                Tetrimino copy = TetriminoGenerator.Copy(currentTetrimino);
                copy.RotateRight();
                if (cells.IsReflection(copy))
                {
                    currentTetrimino = copy;
                }
            }
            if (input.left)
            {
                Tetrimino copy = TetriminoGenerator.Copy(currentTetrimino);
                copy.MoveLeft();
                if (cells.IsReflection(copy))
                {
                    currentTetrimino = copy;
                }
            }
            if (input.right)
            {
                Tetrimino copy = TetriminoGenerator.Copy(currentTetrimino);
                copy.MoveRight();
                if (cells.IsReflection(copy))
                {
                    currentTetrimino = copy;
                }
            }
            if (input.down || autoBottomShift)
            {
                Tetrimino copy = TetriminoGenerator.Copy(currentTetrimino);
                copy.MoveDown();
                if (cells.IsReflection(copy))
                {
                    currentTetrimino = copy;
                }
                else
                {
                    //固定.
                    cells.Reflect(currentTetrimino);
                    currentTetrimino = TetriminoGenerator.CreateRandomTetrimino();
                    if (!cells.IsReflection(currentTetrimino))
                    {
                        isGameOver = true;
                    }
                    time = DateTime.Now;
                }
            }

            cells.DeleteLine();
        }
Exemplo n.º 2
0
 public GameController()
 {
     cells            = new Cells();
     currentTetrimino = TetriminoGenerator.CreateRandomTetrimino();
     time             = DateTime.Now;
 }