Esempio n. 1
0
        private Logic.DropPiece CreateCheckeredDropPiece(double holdTimeSecs = 0.0)
        {
            var dp = new Logic.DropPiece();

            dp.HoldTime      = holdTimeSecs;
            dp.DownDropRate  = 1.0;
            dp.DropRateWhole = 0.5;
            dp.DropRateSplit = 0.25;
            dp.Reset(new PlayfieldPoint(0, 0), false, (c, r, aj) => c % 2 == 0 ? Cell.States.Black : Cell.States.White);
            return(dp);
        }
Esempio n. 2
0
        public void TestReset()
        {
            var dp  = new Logic.DropPiece();
            var dps = new Logic.DropPieceSimple();

            dp.Reset(new PlayfieldPoint(0, 0), false);
            Assert.AreEqual(DropPiece.State.Whole, dp.CurrentState);
            foreach (var row in dp.Cells)
            {
                foreach (var s in row)
                {
                    Assert.AreNotEqual(Cell.States.Disabled, s);
                    Assert.AreNotEqual(Cell.States.Empty, s);
                }
            }
        }
Esempio n. 3
0
    void Update()
    {
        _newColumnOrRow = false;

        var playfield = playfieldManager.Playfield;

        if (_fastMoveDirection != Logic.DropPiece.MoveDirection.None)
        {
            _moveDirection = _fastMoveDirection;
        }
        bool moved = _logic.Update(TimeSpan.FromSeconds(Time.deltaTime), _moveDirection,
                                   (c, r, i) => c >= 0 && c < playfield.NumCellColumns - 1,
                                   (d) => playfieldManager.PlayMoveSnd(),
                                   (p) => p.Row >= playfield.NumCellRows || playfield.GetCell(p).IsOccupied,
                                   playfieldManager.PopulateCell
                                   );

        if (!moved)
        {
            _fastMoveDirection = DropPiece.MoveDirection.None;
        }

        const int numColumns = Logic.DropPiece.NumColumns;
        const int numRows    = Logic.DropPiece.NumRows;

        // show drop piece:
        if (_instantiatePieces)
        {
            var dps = playfieldManager.PopPreview();
            _instantiatePieces  = false;
            _logic.DownDropRate = downDropRate;
            _logic.Reset(new PlayfieldPoint(0, 0), dps);
            if (_pieces == null)
            {
                _pieces = new Tile[numColumns, numRows];
                for (var c = 0; c < numColumns; c++)
                {
                    for (var r = 0; r < numRows; r++)
                    {
                        _pieces[c, r] = new Tile();
                    }
                }
            }
            UpdateVisuals = true;
        }

        // instantiate pieces:
        if (UpdateVisuals)
        {
            DestroyVisuals();
            var level = playfieldManager.Level;

            for (var c = 0; c < numColumns; c++)
            {
                for (var r = 0; r < numRows; r++)
                {
                    var        cell = _logic.Cells[c][r];
                    GameObject tile = null, adornment = null;
                    Transform  pfTransform = null;
                    playfieldManager.GetTileVisuals(cell, out tile, out adornment, out pfTransform);
                    _pieces[c, r].Instantiate(tile, adornment, Vector3.zero, pfTransform, new TileAnimParams(jewelEaseType, jewelHighlightAnimTime));
                }
            }
            UpdateVisuals = false;
        }

        ComputeDropPiecePosition();

        if (_logic.CurrentState == DropPiece.State.Complete)
        {
            /*Vector2 prevPos = playfieldManager.ComputePos(
             *             _logic.Positions[0].Column,
             *             _logic.Positions[0].Row + 2
             *             );
             * GetComponentInChildren<ParticleSystem>().transform.position = new Vector3(prevPos.x, prevPos.y, 0.0f);
             *
             * var ps = GetComponentInChildren<ParticleSystem>();
             * var em = ps.emission;
             * em.enabled = true;
             * ps.Play();
             */

            //StartCoroutine(StopSparks());
            DestroyVisuals();
            _instantiatePieces = true;
        }

        _moveDirection = DropPiece.MoveDirection.None;
    }