Пример #1
0
        public void TestConstructor(
            [Values(2, 4)] int columns,
            [Values(2, 6)] int rows)
        {
            var pf = new Playfield(columns, rows);

            Assert.AreEqual(columns, pf.NumCellColumns);
            Assert.AreEqual(rows, pf.NumCellRows);
            Assert.IsTrue(pf.GetEnumeratorCells().All(c => c.State == Cell.States.Empty));

            Assert.AreEqual(columns - 1, pf.NumSquareColumns);
            Assert.AreEqual(rows - 1, pf.NumSquareRows);

            for (int c = 0; c < pf.NumSquareColumns; c++)
            {
                for (int r = 0; r < pf.NumSquareRows; r++)
                {
                    Assert.AreEqual(c, pf.Squares[c][r].Column);
                    Assert.AreEqual(r, pf.Squares[c][r].Row);
                }
            }
        }
Пример #2
0
    void SetLevel()
    {
        if (lgo != null)
        {
            GameObject.Destroy(lgo);
            lgo = null;
        }

        var level  = _levelNames[_currentLevel];
        var subDir = $"Levels/{level}";
        var goPath = $"{subDir}/Level{level}";

        Debug.Log($"Instantiating {goPath}");
        {
            var go = Resources.Load <GameObject>(goPath);
            if (go == null)
            {
                throw new Exception($"failed to load resource '{goPath}'");
            }
            lgo = Instantiate(go);
        }
        Level = (AbstractLevel)lgo?.GetComponent <MonoBehaviour>();
        if (Level == null)
        {
            throw new Exception($"failed to find component for level '{level}'");
        }

        if (audioSource != null)
        {
            audioSource.Stop();
        }
        audioSource = lgo.GetComponent <AudioSource>();
        if (audioSource != null)
        {
            audioSource.Play();
        }

        var bgcam = GameObject.Find("Background Camera").GetComponent <Camera>();

        bgcam.backgroundColor = Level.clearColor;

        var bggo = GameObject.Find("BackgroundPlane");

        bggo.GetComponent <MeshRenderer>().material = Level.backgroundMaterial;
        _currentLevel = ++_currentLevel % _levelNames.Length;

        // update current visuals:
        foreach (var c in Playfield.GetEnumeratorCells())
        {
            InstantiateVisual(c);
        }

        foreach (var s in Playfield.GetEnumeratorSquares())
        {
            //    InstantiateVisual(s);
        }

        var dpv = GameObject.Find("DropPiece").GetComponent <DropPieceView>();

        dpv.UpdateVisuals = true;
    }
Пример #3
0
        //TODO: fix test [Test()]
        public void TestSetJewelRemoveState()
        {
            // -------------
            // | B | W | B |
            // +---+---+---+
            // | W | J | W |
            // +---+---+---+
            // | W | W | B |
            // +---+---+---+
            const int numColumns = 3;
            var       pf         = new Playfield(numColumns, 3);

            pf.Cells[0][0].State = pf.Cells[2][0].State = Cell.States.Black;
            pf.Cells[2][2].State = Cell.States.Black;

            pf.Cells[1][1].State = Cell.States.WhiteJeweledBoth;
            pf.JeweledCells.Add(pf.Cells[1][1]);

            pf.Cells[0][1].State = pf.Cells[0][2].State = Cell.States.White;
            pf.Cells[1][0].State = pf.Cells[1][2].State = Cell.States.White;
            pf.Cells[2][1].State = Cell.States.White;

            pf.Timeline.IncrementPosition(0.0001f);
            Assert.AreEqual(0, pf.Timeline.Column);

            Assert.AreEqual(Cell.RemoveStates.NotRemoved, pf.Cells[0][0].RemoveState);
            Assert.AreEqual(Cell.RemoveStates.NotRemoved, pf.Cells[2][0].RemoveState);
            Assert.AreEqual(Cell.RemoveStates.NotRemoved, pf.Cells[2][2].RemoveState);

            Assert.AreEqual(Cell.RemoveStates.Removing, pf.Cells[0][1].RemoveState);
            Assert.AreEqual(Cell.RemoveStates.Removing, pf.Cells[0][2].RemoveState);
            Assert.AreEqual(Cell.RemoveStates.JewelWillBeRemoved, pf.Cells[1][0].RemoveState);
            Assert.AreEqual(Cell.RemoveStates.WillBeRemoved, pf.Cells[1][1].RemoveState);
            Assert.AreEqual(Cell.RemoveStates.WillBeRemoved, pf.Cells[1][2].RemoveState);
            Assert.AreEqual(Cell.RemoveStates.JewelWillBeRemoved, pf.Cells[2][1].RemoveState);

            pf.Timeline.IncrementPosition(1.0 / numColumns);
            Assert.AreEqual(1, pf.Timeline.Column);

            Assert.AreEqual(Cell.RemoveStates.NotRemoved, pf.Cells[0][0].RemoveState);
            Assert.AreEqual(Cell.RemoveStates.NotRemoved, pf.Cells[2][0].RemoveState);
            Assert.AreEqual(Cell.RemoveStates.NotRemoved, pf.Cells[2][2].RemoveState);

            Assert.AreEqual(Cell.RemoveStates.Removing, pf.Cells[0][1].RemoveState);
            Assert.AreEqual(Cell.RemoveStates.Removing, pf.Cells[0][2].RemoveState);
            Assert.AreEqual(Cell.RemoveStates.JewelRemoving, pf.Cells[1][0].RemoveState);
            Assert.AreEqual(Cell.RemoveStates.Removing, pf.Cells[1][1].RemoveState);
            Assert.AreEqual(Cell.RemoveStates.Removing, pf.Cells[1][2].RemoveState);
            Assert.AreEqual(Cell.RemoveStates.JewelWillBeRemoved, pf.Cells[2][1].RemoveState);

            pf.Timeline.IncrementPosition(1.0 / numColumns);
            Assert.AreEqual(2, pf.Timeline.Column);

            Assert.AreEqual(Cell.RemoveStates.NotRemoved, pf.Cells[0][0].RemoveState);
            Assert.AreEqual(Cell.RemoveStates.NotRemoved, pf.Cells[2][0].RemoveState);
            Assert.AreEqual(Cell.RemoveStates.NotRemoved, pf.Cells[2][2].RemoveState);

            Assert.AreEqual(Cell.RemoveStates.JewelRemoving, pf.Cells[0][1].RemoveState);
            Assert.AreEqual(Cell.RemoveStates.JewelRemoving, pf.Cells[0][2].RemoveState);
            Assert.AreEqual(Cell.RemoveStates.JewelRemoving, pf.Cells[1][0].RemoveState);
            Assert.AreEqual(Cell.RemoveStates.JewelRemoving, pf.Cells[1][1].RemoveState);
            Assert.AreEqual(Cell.RemoveStates.JewelRemoving, pf.Cells[1][2].RemoveState);
            Assert.AreEqual(Cell.RemoveStates.JewelRemoving, pf.Cells[2][1].RemoveState);


            pf.Timeline.IncrementPosition(1.0 / numColumns);
            Assert.AreEqual(0, pf.Timeline.Column);

            // -------------
            // | E | E | E |
            // +---+---+---+
            // | E | E | B |
            // +---+---+---+
            // | B | E | B |
            // +---+---+---+
            Assert.IsTrue(pf.GetEnumeratorCells().All(c => c.RemoveState == Cell.RemoveStates.NotRemoved));

            // black cells:
            Assert.AreEqual(Cell.States.Black, pf.Cells[0][2].State);
            Assert.AreEqual(Cell.States.Black, pf.Cells[2][1].State);
            Assert.AreEqual(Cell.States.Black, pf.Cells[2][2].State);

            // expect cells to be empty:
            Assert.AreEqual(Cell.States.Empty, pf.Cells[0][0].State);
            Assert.AreEqual(Cell.States.Empty, pf.Cells[0][1].State);
            Assert.AreEqual(Cell.States.Empty, pf.Cells[1][0].State);
            Assert.AreEqual(Cell.States.Empty, pf.Cells[1][1].State);
            Assert.AreEqual(Cell.States.Empty, pf.Cells[1][2].State);
            Assert.AreEqual(Cell.States.Empty, pf.Cells[2][0].State);
        }