Пример #1
0
        public void TestRightDiagonalLine()
        {
            Field field = new Field(10, 10);
            int   length;

            Cell[] lineElements;

            field.Cells[5, 1].Contain = BubbleSize.Big;
            field.Cells[5, 1].Color   = BubbleColor.Red;
            field.Cells[4, 2].Contain = BubbleSize.Big;
            field.Cells[4, 2].Color   = BubbleColor.Red;
            field.Cells[3, 3].Contain = BubbleSize.Big;
            field.Cells[3, 3].Color   = BubbleColor.Red;
            field.Cells[2, 4].Contain = BubbleSize.Big;
            field.Cells[2, 4].Color   = BubbleColor.Red;
            field.Cells[1, 5].Contain = BubbleSize.Big;
            field.Cells[1, 5].Color   = BubbleColor.Red;

            CheckLines _checkLines = new CheckLines(field, field.Cells[2, 4]);

            Assert.IsTrue(_checkLines.CheckLine_RightDiagonal(out length, out lineElements));
            Assert.AreEqual(length, 5);
            Assert.AreSame(lineElements[1], field.Cells[1, 5]);
            Assert.AreSame(lineElements[4], field.Cells[5, 1]);
        }
Пример #2
0
        public void TryMoveBubble(Cell currentCell)
        {
            _checkLine = new CheckLines(Field, currentCell);
            _checkLine.ScoreChangedEventHandler += OnScoreChange;
            _checkLine.DestroyLinesEventHandler += OnDestroyLines;

            if (currentCell.Contain == null)
            {
                if (MoveBubble(SelectedCell, currentCell))
                {
                    SelectedCell = null;

                    if (!_checkLine.Check())
                    {
                        NextTurn(true);
                    }
                    else
                    {
                        Field.EmptyCells += _checkLine.LineLength;
                        NextTurn(false);
                    }
                }
            }
            else
            {
                if (currentCell.Contain == BubbleSize.Small)
                {
                    Cell CurrentCellDuplicate = new Cell(currentCell);

                    if (MoveBubble(SelectedCell, currentCell))
                    {
                        SelectedCell = null;

                        if (!_checkLine.Check())
                        {
                            Cell newBubble = _bubbleGenerationStrategy.GenerateBubble(Field, BubbleSize.Small, CurrentCellDuplicate.Color);
                            Field.Cells[newBubble.Row, newBubble.Column].Contain = newBubble.Contain;
                            Field.Cells[newBubble.Row, newBubble.Column].Color   = newBubble.Color;
                            NextTurn(true);
                        }
                        else
                        {
                            Field.EmptyCells += _checkLine.LineLength;
                            Field.Cells[currentCell.Row, currentCell.Column] = CurrentCellDuplicate;
                            NextTurn(false);
                        }
                    }
                }
                else
                {
                    SelectBubble(currentCell);
                }
            }
        }
Пример #3
0
 private void BubbleRaizing()
 {
     for (int i = 0; i < Field.Height; i++)
     {
         for (int j = 0; j < Field.Width; j++)
         {
             if (Field.Cells[i, j].Contain == BubbleSize.Small)
             {
                 Field.EmptyCells--;
                 Field.Cells[i, j].Contain = BubbleSize.Big;
                 //check if this bubble creates line
                 _checkLine = new CheckLines(Field, Field.Cells[i, j]);
                 _checkLine.ScoreChangedEventHandler += OnScoreChange;
                 _checkLine.DestroyLinesEventHandler += OnDestroyLines;
                 _checkLine.Check();
             }
         }
     }
 }
Пример #4
0
        public void TestCheckMethod_RightDiagonalLine()
        {
            Field field = new Field(10, 10);

            field.Cells[5, 1].Contain = BubbleSize.Big;
            field.Cells[5, 1].Color   = BubbleColor.Red;
            field.Cells[4, 2].Contain = BubbleSize.Big;
            field.Cells[4, 2].Color   = BubbleColor.Red;
            field.Cells[3, 3].Contain = BubbleSize.Big;
            field.Cells[3, 3].Color   = BubbleColor.Red;
            field.Cells[2, 4].Contain = BubbleSize.Big;
            field.Cells[2, 4].Color   = BubbleColor.Red;
            field.Cells[1, 5].Contain = BubbleSize.Big;
            field.Cells[1, 5].Color   = BubbleColor.Red;

            CheckLines _checkLines = new CheckLines(field, field.Cells[2, 4]);

            Assert.IsTrue(_checkLines.Check());
        }
Пример #5
0
        public void TestDoubleLine()
        {
            Field field = new Field(10, 10);
            int   line1Length;

            Cell[] line1Elements;
            int    line2Length;

            Cell[] line2Elements;

            //left diagonal line
            field.Cells[1, 1].Contain = BubbleSize.Big;
            field.Cells[1, 1].Color   = BubbleColor.Red;
            field.Cells[2, 2].Contain = BubbleSize.Big;
            field.Cells[2, 2].Color   = BubbleColor.Red;
            field.Cells[3, 3].Contain = BubbleSize.Big;
            field.Cells[3, 3].Color   = BubbleColor.Red;
            field.Cells[4, 4].Contain = BubbleSize.Big;
            field.Cells[4, 4].Color   = BubbleColor.Red;
            field.Cells[5, 5].Contain = BubbleSize.Big;
            field.Cells[5, 5].Color   = BubbleColor.Red;
            //+ vertical line
            field.Cells[2, 1].Contain = BubbleSize.Big;
            field.Cells[2, 1].Color   = BubbleColor.Red;
            field.Cells[3, 1].Contain = BubbleSize.Big;
            field.Cells[3, 1].Color   = BubbleColor.Red;
            field.Cells[4, 1].Contain = BubbleSize.Big;
            field.Cells[4, 1].Color   = BubbleColor.Red;
            field.Cells[5, 1].Contain = BubbleSize.Big;
            field.Cells[5, 1].Color   = BubbleColor.Red;

            CheckLines _checkLines = new CheckLines(field, field.Cells[1, 1]);

            Assert.IsTrue(_checkLines.CheckLine_LeftDiagonal(out line1Length, out line1Elements));
            Assert.AreEqual(line1Length, 5);
            Assert.AreSame(line1Elements[0], field.Cells[1, 1]);
            Assert.AreSame(line1Elements[4], field.Cells[5, 5]);

            Assert.IsTrue(_checkLines.CheckLine_Vertical(out line2Length, out line2Elements));
            Assert.AreEqual(line2Length, 5);
            Assert.AreSame(line2Elements[0], field.Cells[1, 1]);
            Assert.AreSame(line2Elements[4], field.Cells[5, 1]);
        }