Beispiel #1
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;
                }
            });
        }
Beispiel #2
0
        public ITetriMino GetTetriMino(TetriMinoType tetriMinoType, ITetriMinoRotation tetriMinoRotation)
        {
            var minos = MinoData[tetriMinoType];

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