Пример #1
0
        private void Rotate(Func <ITetriMinoRotation, ITetriMinoRotation> rotateFunc)
        {
            var nextPosition = _position;
            var nextRotation = rotateFunc(_rotation);

            var prevTetriMino = _tetriMinoRepository.GetTetriMino(_minoType, _rotation);
            var prevBottom    = prevTetriMino.Blocks.GetLength(0);

            var nextTetriMino = _tetriMinoRepository.GetTetriMino(_minoType, nextRotation);
            var nextBottom    = nextTetriMino.Blocks.GetLength(0);

            nextPosition.Y += Mathf.Max(0, prevBottom - nextBottom);

            if (IsValid(nextPosition, nextRotation))
            {
                _position = nextPosition;
                _rotation = rotateFunc(_rotation);
            }
            else if (CanKick(nextPosition, nextRotation))
            {
                if (IsValid(nextPosition + new Point(1, 0), nextRotation))
                {
                    nextPosition.X += 1;
                    _position       = nextPosition;
                    _rotation       = rotateFunc(_rotation);
                }
                else if (IsValid(nextPosition + new Point(-1, 0), nextRotation))
                {
                    nextPosition.X -= 1;
                    _position       = nextPosition;
                    _rotation       = rotateFunc(_rotation);
                }
            }
        }
Пример #2
0
 public NextPresenter(ITetriMinoRepository tetriMinoRepository, IBlockRenderer blockRenderer, ITetriMinoRotation tetriMinoRotation, ITetriMinoSupplier tetriMinoSupplier)
 {
     _tetriMinoRepository = tetriMinoRepository;
     _blockRenderer       = blockRenderer;
     _tetriMinoRotation   = tetriMinoRotation;
     _tetriMinoSupplier   = tetriMinoSupplier;
 }
Пример #3
0
        public ActiveMino(IBlockRenderer blockRenderer, IField field, ITetriMinoRepository tetriMinoRepository,
                          IInputManager inputManager, ITetriMinoRotation rotation, ITetriMinoSupplier tetriMinoSupplier)
        {
            _blockRenderer       = blockRenderer;
            _tetriMinoRepository = tetriMinoRepository;
            _rotation            = rotation;
            _field = field;

            _minoType = tetriMinoSupplier.Current;

            inputManager.OnRotate1ButtonDown.Subscribe(_ => Rotate(rot => rot.RotateRight()));
            inputManager.OnRotate2ButtonDown.Subscribe(_ => Rotate(rot => rot.RotateLeft()));

            inputManager.OnRightButtonDown.Subscribe(_ =>
            {
                if (IsValid(_position + new Point(1, 0), _rotation))
                {
                    _position.X += 1;
                }
            });
            inputManager.OnLeftButtonDown.Subscribe(_ =>
            {
                if (IsValid(_position + new Point(-1, 0), _rotation))
                {
                    _position.X -= 1;
                }
            });

            inputManager.OnDownButtonDown.Subscribe(_ =>
            {
                if (IsValid(_position + new Point(0, 1), _rotation))
                {
                    _position.Y += 1;
                }
                else
                {
                    var tetriMino = _tetriMinoRepository.GetTetriMino(_minoType, _rotation);
                    field.SetTetriMino(tetriMino, _position);
                    field.RemoveLines();

                    tetriMinoSupplier.Update();

                    _position = new Point(3, 0);
                    _minoType = tetriMinoSupplier.Current;
                    _rotation = new TetriMinoRotation();
                    if (inputManager.IsRotate1Down)
                    {
                        Debug.Log("Test");
                        _rotation = _rotation.RotateRight();
                    }
                    else
                    if (inputManager.IsRotate2Down)
                    {
                        _rotation = _rotation.RotateLeft();
                    }
                }
            });

            inputManager.OnUpButtonDown.Subscribe(_ =>
            {
                while (IsValid(_position + new Point(0, 1), _rotation))
                {
                    _position.Y += 1;
                }
            });

            _onUpdateSubject.SelectMany(Observable.Range(0, 20)).Subscribe(_ =>
            {
                if (IsValid(_position + new Point(0, 1), _rotation))
                {
                    _position.Y += 1;
                }
            });
        }
Пример #4
0
        private bool CanKick(Point position, ITetriMinoRotation rotation)
        {
            var tetriMino = _tetriMinoRepository.GetTetriMino(_minoType, rotation);

            return(tetriMino.Points.Where(p => p.X == tetriMino.Center.X).Count(point => _field.IsFull(point + position)) == 0);
        }
Пример #5
0
        private bool IsValid(Point position, ITetriMinoRotation rotation)
        {
            var tetriMino = _tetriMinoRepository.GetTetriMino(_minoType, rotation);

            return(tetriMino.Points.Count(point => _field.IsFull(point + position)) == 0);
        }
Пример #6
0
        public ITetriMino GetTetriMino(TetriMinoType tetriMinoType, ITetriMinoRotation tetriMinoRotation)
        {
            var minos = MinoData[tetriMinoType];

            return(minos[Mod(tetriMinoRotation.Id, minos.Length)]);
        }